|
| 1 | +name: Build Flatpak |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + pull_request: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + workflow_dispatch: |
| 13 | + |
| 14 | +env: |
| 15 | + FLATPAK_ID: com.onclebob.Bob |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + name: Build Flatpak (${{ matrix.arch }}) |
| 20 | + runs-on: ${{ matrix.arch == 'aarch64' && 'ubuntu-24.04-arm' || 'ubuntu-latest' }} |
| 21 | + strategy: |
| 22 | + matrix: |
| 23 | + arch: [x86_64, aarch64] |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v4 |
| 28 | + |
| 29 | + - name: Install flatpak-builder |
| 30 | + run: | |
| 31 | + sudo apt-get update |
| 32 | + sudo apt-get install -y flatpak flatpak-builder |
| 33 | +
|
| 34 | + - name: Add Flathub repository |
| 35 | + run: | |
| 36 | + sudo flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo |
| 37 | +
|
| 38 | + - name: Install Flatpak SDK and runtime |
| 39 | + run: | |
| 40 | + sudo flatpak install -y flathub org.freedesktop.Platform//25.08 org.freedesktop.Sdk//25.08 |
| 41 | + sudo flatpak install -y flathub org.freedesktop.Sdk.Extension.llvm21//25.08 |
| 42 | +
|
| 43 | + - name: Build Flatpak |
| 44 | + run: | |
| 45 | + flatpak-builder --arch=${{ matrix.arch }} \ |
| 46 | + --repo=repo \ |
| 47 | + --force-clean \ |
| 48 | + --ccache \ |
| 49 | + --install-deps-from=flathub \ |
| 50 | + build-dir \ |
| 51 | + ${{ env.FLATPAK_ID }}.yml |
| 52 | +
|
| 53 | + - name: Create Flatpak bundle |
| 54 | + run: | |
| 55 | + flatpak build-bundle repo \ |
| 56 | + ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak \ |
| 57 | + ${{ env.FLATPAK_ID }} \ |
| 58 | + --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo |
| 59 | +
|
| 60 | + - name: Import GPG key |
| 61 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) |
| 62 | + env: |
| 63 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 64 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 65 | + run: | |
| 66 | + echo "$GPG_PRIVATE_KEY" | gpg --batch --import |
| 67 | + echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf |
| 68 | + echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf |
| 69 | + gpg-connect-agent reloadagent /bye |
| 70 | +
|
| 71 | + - name: Sign Flatpak bundle |
| 72 | + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) |
| 73 | + env: |
| 74 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 75 | + run: | |
| 76 | + GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2 | head -n1) |
| 77 | + echo "$GPG_PASSPHRASE" | gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 \ |
| 78 | + --detach-sign --armor \ |
| 79 | + --output ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak.sig \ |
| 80 | + ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak |
| 81 | +
|
| 82 | + - name: Generate checksums |
| 83 | + run: | |
| 84 | + sha256sum ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak > ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak.sha256 |
| 85 | +
|
| 86 | + - name: Upload build artifacts |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: flatpak-${{ matrix.arch }} |
| 90 | + path: | |
| 91 | + ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak |
| 92 | + ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak.sig |
| 93 | + ${{ env.FLATPAK_ID }}-${{ matrix.arch }}.flatpak.sha256 |
| 94 | + retention-days: 30 |
| 95 | + |
| 96 | + - name: Upload OSTree repository |
| 97 | + uses: actions/upload-artifact@v4 |
| 98 | + with: |
| 99 | + name: ostree-repo-${{ matrix.arch }} |
| 100 | + path: repo/ |
| 101 | + retention-days: 7 |
| 102 | + |
| 103 | + release: |
| 104 | + name: Create Release |
| 105 | + needs: build |
| 106 | + runs-on: ubuntu-latest |
| 107 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') |
| 108 | + |
| 109 | + steps: |
| 110 | + - name: Download all artifacts |
| 111 | + uses: actions/download-artifact@v4 |
| 112 | + with: |
| 113 | + path: artifacts |
| 114 | + |
| 115 | + - name: Prepare release assets |
| 116 | + run: | |
| 117 | + mkdir -p release |
| 118 | + find artifacts -name "*.flatpak" -exec cp {} release/ \; |
| 119 | + find artifacts -name "*.flatpak.sig" -exec cp {} release/ \; |
| 120 | + find artifacts -name "*.flatpak.sha256" -exec cp {} release/ \; |
| 121 | + ls -lah release/ |
| 122 | +
|
| 123 | + - name: Create GitHub Release |
| 124 | + uses: softprops/action-gh-release@v1 |
| 125 | + with: |
| 126 | + files: release/* |
| 127 | + draft: false |
| 128 | + prerelease: false |
| 129 | + generate_release_notes: true |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + |
| 133 | + publish-repo: |
| 134 | + name: Publish OSTree Repository |
| 135 | + needs: build |
| 136 | + runs-on: ubuntu-latest |
| 137 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 138 | + |
| 139 | + steps: |
| 140 | + - name: Download OSTree repositories |
| 141 | + uses: actions/download-artifact@v4 |
| 142 | + with: |
| 143 | + pattern: ostree-repo-* |
| 144 | + path: repos |
| 145 | + |
| 146 | + - name: Install OSTree |
| 147 | + run: | |
| 148 | + sudo apt-get update |
| 149 | + sudo apt-get install -y ostree |
| 150 | +
|
| 151 | + - name: Merge OSTree repositories |
| 152 | + run: | |
| 153 | + ostree init --repo=dist --mode=archive-z2 |
| 154 | +
|
| 155 | + # Find all downloaded repo directories |
| 156 | + for repo_dir in repos/ostree-repo-*/; do |
| 157 | + if [ -d "$repo_dir" ] && [ -f "$repo_dir/config" ]; then |
| 158 | + echo "Processing repository: $repo_dir" |
| 159 | +
|
| 160 | + # Create refs/remotes directory if it doesn't exist to prevent errors |
| 161 | + mkdir -p "$repo_dir/refs/remotes" |
| 162 | +
|
| 163 | + # List available refs in source repo |
| 164 | + echo "Available refs in source repo:" |
| 165 | + ostree refs --repo="$repo_dir" || echo "No refs found" |
| 166 | +
|
| 167 | + # Pull all refs from the source repo |
| 168 | + for ref in $(ostree refs --repo="$repo_dir" 2>/dev/null || true); do |
| 169 | + echo "Pulling ref: $ref" |
| 170 | + ostree pull-local --repo=dist "$repo_dir" "$ref" || echo "Warning: Failed to pull $ref" |
| 171 | + done |
| 172 | + fi |
| 173 | + done |
| 174 | +
|
| 175 | + # List what we have in the merged repo |
| 176 | + echo "Merged repository contents:" |
| 177 | + ostree refs --repo=dist || echo "No refs found in merged repo" |
| 178 | +
|
| 179 | + - name: Import GPG key for repo signing |
| 180 | + env: |
| 181 | + GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} |
| 182 | + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} |
| 183 | + run: | |
| 184 | + echo "$GPG_PRIVATE_KEY" | gpg --batch --import |
| 185 | + echo "allow-preset-passphrase" >> ~/.gnupg/gpg-agent.conf |
| 186 | + echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf |
| 187 | + gpg-connect-agent reloadagent /bye |
| 188 | + GPG_KEY_ID=$(gpg --list-secret-keys --keyid-format LONG | grep sec | awk '{print $2}' | cut -d'/' -f2 | head -n1) |
| 189 | + echo "GPG_KEY_ID=$GPG_KEY_ID" >> $GITHUB_ENV |
| 190 | +
|
| 191 | + # Get the keygrip for the signing key |
| 192 | + KEYGRIP=$(gpg --with-keygrip --list-secret-keys "$GPG_KEY_ID" | grep "Keygrip" | head -n1 | awk '{print $3}') |
| 193 | +
|
| 194 | + # Preset the passphrase in the gpg-agent cache |
| 195 | + echo "$GPG_PASSPHRASE" | /usr/lib/gnupg/gpg-preset-passphrase --preset "$KEYGRIP" |
| 196 | +
|
| 197 | + - name: Sign OSTree repository |
| 198 | + run: | |
| 199 | + ostree summary --repo=dist --update --gpg-sign=${{ env.GPG_KEY_ID }} --gpg-homedir=$HOME/.gnupg |
| 200 | +
|
| 201 | + - name: Install xmit |
| 202 | + run: | |
| 203 | + XMIT_VERSION=$(curl -s https://api.github.com/repos/xmit-co/xmit/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') |
| 204 | + curl -sL "https://github.com/xmit-co/xmit/releases/download/${XMIT_VERSION}/xmit_${XMIT_VERSION#v}_linux_amd64.tgz" -o xmit.tgz |
| 205 | + tar -xzf xmit.tgz |
| 206 | + chmod +x xmit_${XMIT_VERSION#v}_linux_amd64/xmit |
| 207 | + sudo mv xmit_${XMIT_VERSION#v}_linux_amd64/xmit /usr/local/bin/ |
| 208 | +
|
| 209 | + - name: Upload to xmit |
| 210 | + env: |
| 211 | + XMIT_KEY: ${{ secrets.XMIT_KEY }} |
| 212 | + run: | |
| 213 | + /usr/local/bin/xmit flatpak.onclebob.com |
0 commit comments