fix(flatpak): replace gh CLI with curl in upload step — gh not in con… #12
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: Flatpak | ||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
| workflow_dispatch: | ||
| permissions: | ||
| contents: write | ||
| jobs: | ||
| build-flatpak: | ||
| name: Build Flatpak (Ubuntu 24.04) | ||
| runs-on: ubuntu-24.04 | ||
| container: | ||
| image: bilelmoussaoui/flatpak-github-actions:freedesktop-24.08 | ||
| options: --privileged | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - name: Validate Flatpak manifest | ||
| run: bash tests/packaging/flatpak_validate.sh | ||
| - name: Install Rust SDK extension | ||
| run: | | ||
| flatpak remote-add --if-not-exists flathub \ | ||
| https://flathub.org/repo/flathub.flatpakrepo | ||
| flatpak install --noninteractive flathub \ | ||
| org.freedesktop.Sdk.Extension.rust-stable//24.08 \ | ||
| org.freedesktop.Sdk.Extension.llvm18//24.08 | ||
| - name: Build with flatpak-builder | ||
| run: | | ||
| flatpak-builder \ | ||
| --repo=repo \ | ||
| --install-deps-from=flathub \ | ||
| --force-clean \ | ||
| builddir \ | ||
| packaging/flatpak/io.github.thewrz.HonkHonk.yml | ||
| - name: Bundle | ||
| run: | | ||
| flatpak build-bundle repo honkhonk.flatpak io.github.thewrz.HonkHonk | ||
| - name: Upload Flatpak artifact | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: honkhonk-flatpak-${{ github.ref_name }} | ||
| path: honkhonk.flatpak | ||
| - name: Attach Flatpak to GitHub Release | ||
| if: startsWith(github.ref, 'refs/tags/') | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| TAG_NAME: ${{ github.ref_name }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| for i in $(seq 1 30); do | ||
| HTTP=$(curl -sf -o /dev/null -w "%{http_code}" \ | ||
| -H "Authorization: token $GH_TOKEN" \ | ||
| "https://api.github.com/repos/$REPO/releases/tags/$TAG_NAME") | ||
| [ "$HTTP" = "200" ] && break | ||
| echo "Waiting for release... ($i/30)" | ||
| sleep 10 | ||
| done | ||
| [ "$HTTP" = "200" ] || { echo "Release not found after 5 minutes"; exit 1; } | ||
| RELEASE=$(curl -sf \ | ||
| -H "Authorization: token $GH_TOKEN" \ | ||
| "https://api.github.com/repos/$REPO/releases/tags/$TAG_NAME") | ||
| ASSET_ID=$(echo "$RELEASE" | python3 -c " | ||
| import sys, json | ||
| data = json.load(sys.stdin) | ||
| for a in data.get('assets', []): | ||
| if a['name'] == 'honkhonk.flatpak': | ||
| print(a['id']) | ||
| break | ||
| " 2>/dev/null) | ||
| [ -n "$ASSET_ID" ] && curl -sf -X DELETE \ | ||
| -H "Authorization: token $GH_TOKEN" \ | ||
| "https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID" | ||
| UPLOAD_URL=$(echo "$RELEASE" | python3 -c " | ||
| import sys, json; print(json.load(sys.stdin)['upload_url'].split('{')[0]) | ||
| ") | ||
| curl -sf \ | ||
| -H "Authorization: token $GH_TOKEN" \ | ||
| -H "Content-Type: application/octet-stream" \ | ||
| "$UPLOAD_URL?name=honkhonk.flatpak" \ | ||
| --data-binary @honkhonk.flatpak | ||