Merge pull request #51 from FreddyFunk/feature/better-flatpak-comments #8
Workflow file for this run
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: Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| env: | |
| CARGO_TERM_COLOR: always | |
| FLATHUB_REPO: flathub/io.github.freddyfunk.cosmic-camera | |
| jobs: | |
| # Build Linux binaries for multiple architectures | |
| build-binaries: | |
| name: Build Binary (${{ matrix.arch }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| arch: x86_64 | |
| use_cross: false | |
| - target: aarch64-unknown-linux-gnu | |
| arch: aarch64 | |
| use_cross: true | |
| - target: riscv64gc-unknown-linux-gnu | |
| arch: riscv64 | |
| use_cross: true | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: stable | |
| targets: ${{ matrix.target }} | |
| - name: Install system dependencies (native build) | |
| if: ${{ !matrix.use_cross }} | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| libgstreamer1.0-dev \ | |
| libgstreamer-plugins-base1.0-dev \ | |
| libgstreamer-plugins-bad1.0-dev \ | |
| libwayland-dev \ | |
| libxkbcommon-dev \ | |
| libinput-dev \ | |
| libudev-dev \ | |
| libseat-dev | |
| - name: Install cross | |
| if: ${{ matrix.use_cross }} | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Install just | |
| uses: extractions/setup-just@v2 | |
| - name: Build release binary | |
| run: | | |
| if [ "${{ matrix.use_cross }}" = "true" ]; then | |
| cross build --release --target ${{ matrix.target }} | |
| else | |
| just build-release --target ${{ matrix.target }} | |
| fi | |
| - name: Package binary | |
| run: | | |
| mkdir -p dist | |
| cp target/${{ matrix.target }}/release/cosmic-camera dist/ | |
| cd dist | |
| tar -czvf cosmic-camera-${{ matrix.arch }}-linux.tar.gz cosmic-camera | |
| rm cosmic-camera | |
| - name: Upload binary artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: binary-${{ matrix.arch }} | |
| path: dist/cosmic-camera-${{ matrix.arch }}-linux.tar.gz | |
| retention-days: 1 | |
| # Build Flatpak for x86_64 (native, fast) | |
| build-flatpak-x86_64: | |
| name: Build Flatpak (x86_64) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Install Flatpak and flatpak-builder | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y flatpak flatpak-builder | |
| - name: Add Flathub remote | |
| run: sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo | |
| - name: Install just | |
| uses: extractions/setup-just@v2 | |
| - name: Install Flatpak dependencies | |
| run: just flatpak-deps x86_64 | |
| - name: Install Python dependencies | |
| run: pip install aiohttp toml tomlkit | |
| - name: Build Flatpak bundle | |
| run: just flatpak-bundle x86_64 | |
| - name: Upload Flatpak artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: flatpak-x86_64 | |
| path: cosmic-camera-x86_64.flatpak | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # Build Flatpak for aarch64 (QEMU emulation, slow but necessary for releases) | |
| build-flatpak-aarch64: | |
| name: Build Flatpak (aarch64) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Install Flatpak and flatpak-builder | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y flatpak flatpak-builder | |
| - name: Set up QEMU for multi-arch builds | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: arm64 | |
| - name: Add Flathub remote | |
| run: sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo | |
| - name: Install just | |
| uses: extractions/setup-just@v2 | |
| - name: Install Flatpak dependencies | |
| run: just flatpak-deps aarch64 | |
| - name: Install Python dependencies | |
| run: pip install aiohttp toml tomlkit | |
| - name: Build Flatpak bundle | |
| run: just flatpak-bundle aarch64 | |
| - name: Upload Flatpak artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: flatpak-aarch64 | |
| path: cosmic-camera-aarch64.flatpak | |
| if-no-files-found: error | |
| retention-days: 1 | |
| # Create the GitHub release with all artifacts | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: [build-binaries, build-flatpak-x86_64, build-flatpak-aarch64] | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Prepare release assets | |
| run: | | |
| mkdir -p release-assets | |
| mv artifacts/binary-x86_64/cosmic-camera-x86_64-linux.tar.gz release-assets/ | |
| mv artifacts/binary-aarch64/cosmic-camera-aarch64-linux.tar.gz release-assets/ | |
| mv artifacts/binary-riscv64/cosmic-camera-riscv64-linux.tar.gz release-assets/ | |
| mv artifacts/flatpak-x86_64/cosmic-camera-x86_64.flatpak release-assets/ | |
| mv artifacts/flatpak-aarch64/cosmic-camera-aarch64.flatpak release-assets/ | |
| git archive --format=zip --prefix=cosmic-camera-${{ github.ref_name }}/ -o release-assets/cosmic-camera-${{ github.ref_name }}-source.zip HEAD | |
| - name: Generate release notes | |
| run: | | |
| cat << 'EOF' > release_notes_footer.md | |
| ## Installation | |
| ### Flatpak (Recommended) | |
| ```bash | |
| flatpak install cosmic-camera-x86_64.flatpak | |
| ``` | |
| ### Binary | |
| ```bash | |
| tar -xzf cosmic-camera-x86_64-linux.tar.gz | |
| ./cosmic-camera | |
| ``` | |
| ## Assets | |
| | File | Description | | |
| |------|-------------| | |
| | `cosmic-camera-x86_64.flatpak` | Flatpak bundle for x86_64 | | |
| | `cosmic-camera-aarch64.flatpak` | Flatpak bundle for ARM64 | | |
| | `cosmic-camera-x86_64-linux.tar.gz` | Linux binary for x86_64 | | |
| | `cosmic-camera-aarch64-linux.tar.gz` | Linux binary for ARM64 | | |
| | `cosmic-camera-riscv64-linux.tar.gz` | Linux binary for RISC-V 64 | | |
| | `cosmic-camera-${{ github.ref_name }}-source.zip` | Source code | | |
| EOF | |
| - name: Create GitHub Release | |
| run: | | |
| gh api repos/${{ github.repository }}/releases/generate-notes \ | |
| -f tag_name="${{ github.ref_name }}" \ | |
| --jq '.body' > release_notes.md | |
| cat release_notes_footer.md >> release_notes.md | |
| gh release create ${{ github.ref_name }} \ | |
| --title "COSMIC Camera ${{ github.ref_name }}" \ | |
| --notes-file release_notes.md \ | |
| release-assets/* | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| # Publish to Flathub by updating the Flathub repository | |
| publish-flathub: | |
| name: Publish to Flathub | |
| runs-on: ubuntu-latest | |
| needs: create-release | |
| steps: | |
| - name: Check for Flathub token | |
| id: check_token | |
| run: | | |
| if [ -z "${{ secrets.FLATHUB_TOKEN }}" ]; then | |
| echo "FLATHUB_TOKEN secret is not set. Skipping Flathub publish." | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Checkout source repository | |
| if: steps.check_token.outputs.skip != 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| path: source | |
| - name: Checkout Flathub repository | |
| if: steps.check_token.outputs.skip != 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: ${{ env.FLATHUB_REPO }} | |
| token: ${{ secrets.FLATHUB_TOKEN }} | |
| path: flathub | |
| - name: Install Python dependencies | |
| if: steps.check_token.outputs.skip != 'true' | |
| run: pip install aiohttp toml tomlkit pyyaml | |
| - name: Get release commit SHA | |
| if: steps.check_token.outputs.skip != 'true' | |
| id: get_sha | |
| run: | | |
| cd source | |
| COMMIT_SHA=$(git rev-parse ${{ github.ref_name }}) | |
| echo "sha=$COMMIT_SHA" >> $GITHUB_OUTPUT | |
| - name: Download flatpak-cargo-generator | |
| if: steps.check_token.outputs.skip != 'true' | |
| run: | | |
| curl -sLo flatpak-cargo-generator.py https://raw.githubusercontent.com/flatpak/flatpak-builder-tools/master/cargo/flatpak-cargo-generator.py | |
| - name: Generate cargo-sources.json for Flathub | |
| if: steps.check_token.outputs.skip != 'true' | |
| run: python3 flatpak-cargo-generator.py source/Cargo.lock -o flathub/cargo-sources.json | |
| - name: Update Flathub manifest | |
| if: steps.check_token.outputs.skip != 'true' | |
| run: | | |
| cd flathub | |
| python3 << 'EOF' | |
| import yaml | |
| tag = "${{ github.ref_name }}" | |
| commit = "${{ steps.get_sha.outputs.sha }}" | |
| repo_url = "https://github.com/${{ github.repository }}.git" | |
| with open("io.github.freddyfunk.cosmic-camera.yml", "r") as f: | |
| manifest = yaml.safe_load(f) | |
| for module in manifest.get("modules", []): | |
| if module.get("name") == "cosmic-camera": | |
| module["sources"] = [ | |
| {"type": "git", "url": repo_url, "tag": tag, "commit": commit}, | |
| "cargo-sources.json" | |
| ] | |
| break | |
| with open("io.github.freddyfunk.cosmic-camera.yml", "w") as f: | |
| yaml.dump(manifest, f, default_flow_style=False, sort_keys=False, allow_unicode=True) | |
| print(f"Updated manifest to use tag {tag} (commit {commit})") | |
| EOF | |
| - name: Commit and push to Flathub | |
| if: steps.check_token.outputs.skip != 'true' | |
| run: | | |
| cd flathub | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add io.github.freddyfunk.cosmic-camera.yml cargo-sources.json | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "Update to ${{ github.ref_name }}" | |
| git push origin main | |
| echo "Successfully pushed update to Flathub!" |