andrewinci/Insulator

View on GitHub
.github/workflows/release.yml

Summary

Maintainability
Test Coverage
name: Release

on:
  push:
    tags:
      - '*.*.*'

jobs:
  package-app:
    runs-on: ${{ matrix.os.name }}
    strategy:
      matrix:
        os:
        - name: macos-latest
          artifact: insulator-mac
          path: Insulator*.dmg
        - name: ubuntu-latest
          artifact: insulator-debian
          path: insulator*.deb
        - name: windows-latest
          artifact: insulator-win
          path: Insulator*.exe
    steps:
    - uses: actions/checkout@v2
    - name: Setup Java JDK
      uses: actions/setup-java@v1.4.3
      with:
        java-version: 14
        java-package: jdk
    - name: Cache
      uses: actions/cache@v2
      with:
        path: |
          ~/.gradle/caches
          ~/.gradle/wrapper
        key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
        restore-keys: ${{ runner.os }}-gradle-
    - uses: battila7/get-version-action@v2
      id: get_version
    - name: Gradle package
      run: "./gradlew bootstrap:packageApp"
      env:
        RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
    - name: Update binary
      uses: actions/upload-artifact@v2
      with:
        name: ${{ matrix.os.artifact }}
        path: "./bootstrap/${{ matrix.os.path }}"
        if-no-files-found: error
    - name: Build update4j config and jar
      if: ${{ matrix.os.name == 'ubuntu-latest' }}
      run: |
        ./gradlew getDependencySources
        ./gradlew :app:mergeLocalLibs
        python3 scripts/build.py
        mv ./app/build/distributions/app/lib/insulator.jar .
      env:
        RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
    - name: Update update4j config + jar
      if: ${{ matrix.os.name == 'ubuntu-latest' }}
      uses: actions/upload-artifact@v2
      with:
        name: jar-update
        path: |
          ./insulator.jar
          ./insulator-update.xml
        if-no-files-found: error

  create-release:
    runs-on: ubuntu-latest
    needs: package-app
    outputs:
      release-url: ${{ steps.create_release.outputs.upload_url }}
    steps:
      - uses: battila7/get-version-action@v2
        id: get_version
      - name: Create release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ steps.get_version.outputs.version }}
          release_name: Release Candidate ${{ steps.get_version.outputs.version }}
          draft: false
          prerelease: true

  upload-artifacts:
    runs-on: ubuntu-latest
    needs: create-release
    strategy:
      matrix:
        artifact:
          - name: insulator-mac
            path: Insulator-*.dmg
          - name: insulator-win
            path: Insulator-*.exe
          - name: insulator-debian
            path: insulator*.deb
    steps:
      - uses: battila7/get-version-action@v2
        id: get_version
      - name: Download binary from previous jobs
        uses: actions/download-artifact@v2
        with:
          name: ${{ matrix.artifact.name }}
      - name: Download update4j config + jar from previous jobs
        if: ${{ matrix.artifact.name == 'insulator-debian' }}
        uses: actions/download-artifact@v2
        with:
          name: jar-update

      - name: Zip artifact
        run: |
          zip --junk-paths ${{ matrix.artifact.name }} ${{ matrix.artifact.path }}

      - name: Upload ${{ matrix.artifact.name }} asset
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.release-url }}
          asset_path: ./${{ matrix.artifact.name }}.zip
          asset_name: ${{ matrix.artifact.name }}.zip
          asset_content_type: application/zip

      - name: Upload jar
        if: ${{ matrix.artifact.name == 'insulator-debian' }}
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.release-url }}
          asset_path: ./insulator.jar
          asset_name: insulator.jar
          asset_content_type: application/java-archive

      - name: Upload update4j config
        if: ${{ matrix.artifact.name == 'insulator-debian' }}
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          upload_url: ${{ needs.create-release.outputs.release-url }}
          asset_path: ./insulator-update.xml
          asset_name: insulator-update.xml
          asset_content_type: application/xml

      - name: Bump Homebrew formula
        if: ${{ matrix.artifact.name == 'insulator-mac' }}
        run: |
          git config --global user.name ${{ github.actor }}
          git config --global user.email andrewinci@users.noreply.github.com
          brew tap andrewinci/tap
          brew bump-cask-pr --write-only --commit --no-audit --no-browse --no-fork --version $RELEASE_VERSION --force insulator
          cd /home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/andrewinci/homebrew-tap
          git push https://${{ secrets.GITHUBTOKEN }}@github.com/andrewinci/homebrew-tap.git
        env:
          RELEASE_VERSION: ${{ steps.get_version.outputs.version }}