Refactor CI workflow to build all platforms and create releases #8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main, master] | |
| pull_request: | |
| branches: [main, master] | |
| jobs: | |
| analyze-test: | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.9' | |
| cache: true | |
| - name: Install dependencies | |
| run: flutter pub get | |
| - name: Run code generation | |
| run: dart run build_runner build --delete-conflicting-outputs | |
| - name: Analyze code | |
| run: flutter analyze --no-fatal-infos | |
| - name: Run tests | |
| run: flutter test | |
| build-linux: | |
| runs-on: ubuntu-latest | |
| needs: analyze-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.9' | |
| cache: true | |
| - name: Install dependencies | |
| run: flutter pub get | |
| - name: Run code generation | |
| run: dart run build_runner build --delete-conflicting-outputs | |
| - name: Build Linux | |
| run: flutter build linux --debug | |
| - name: Upload Linux build | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: build/linux/x64/debug/bundle/ | |
| compression-level: 0 | |
| build-windows: | |
| runs-on: windows-latest | |
| needs: analyze-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.9' | |
| cache: true | |
| - name: Install dependencies | |
| run: flutter pub get | |
| - name: Run code generation | |
| run: dart run build_runner build --delete-conflicting-outputs | |
| - name: Build Windows | |
| run: flutter build windows --debug | |
| - name: Upload Windows build | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-build | |
| path: build/windows/x64/debug/runner/ | |
| compression-level: 0 | |
| build-macos: | |
| runs-on: macos-latest | |
| needs: analyze-test | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.38.9' | |
| cache: true | |
| - name: Install dependencies | |
| run: flutter pub get | |
| - name: Run code generation | |
| run: dart run build_runner build --delete-conflicting-outputs | |
| - name: Build macOS | |
| run: flutter build macos --debug --no-tree-shake-icons | |
| - name: Upload macOS build | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-build | |
| path: build/macos/_debug/ | |
| compression-level: 0 | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [build-linux, build-windows, build-macos] | |
| if: startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get version | |
| id: version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Download Linux build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-build | |
| path: releases/ | |
| - name: Download Windows build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-build | |
| path: releases/ | |
| - name: Download macOS build | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: macos-build | |
| path: releases/ | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.VERSION }} | |
| name: Release ${{ steps.version.outputs.VERSION }} | |
| draft: false | |
| prerelease: false | |
| files: | | |
| releases/**/* | |
| body: | | |
| ## Changes | |
| See [CHANGELOG.md](./CHANGELOG.md) for details. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| release-draft: | |
| runs-on: ubuntu-latest | |
| needs: [build-linux, build-windows, build-macos] | |
| if: github.event_name == 'pull_request' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/')) | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get version | |
| id: version | |
| run: | | |
| VERSION=$(git describe --tags --always --dirty 2>/dev/null || echo "dev") | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| echo "RUN_NUMBER=${{ github.run_number }}" >> $GITHUB_OUTPUT | |
| - name: Download builds | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: releases/ | |
| merge-multiple: true | |
| - name: Create Pre-release Draft | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.version.outputs.VERSION }}-${{ steps.version.outputs.RUN_NUMBER }} | |
| name: Pre-release ${{ steps.version.outputs.VERSION }} (Build ${{ steps.version.outputs.RUN_NUMBER }}) | |
| draft: true | |
| prerelease: true | |
| files: | | |
| releases/**/* | |
| body: | | |
| ## Pre-release | |
| This is a pre-release build for testing purposes. | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |