diff --git a/.github/workflows/update-flake-hash.yml b/.github/workflows/update-flake-hash.yml index 9e77ced..2f8aa4c 100644 --- a/.github/workflows/update-flake-hash.yml +++ b/.github/workflows/update-flake-hash.yml @@ -1,8 +1,12 @@ name: Update Flake Hash on Release on: - release: - types: [published] + workflow_run: + workflows: ["Build WinBoat"] + types: + - completed + branches: + - main workflow_dispatch: inputs: version: @@ -12,6 +16,10 @@ on: jobs: update-hash: runs-on: ubuntu-latest + # Only run if the workflow succeeded and was triggered by a tag + if: | + github.event.workflow_run.conclusion == 'success' && + startsWith(github.event.workflow_run.head_branch, 'refs/tags/') permissions: contents: write @@ -35,16 +43,33 @@ jobs: script: | set -euo pipefail - if [ "${{ github.event_name }}" = "release" ]; then - VERSION="${{ github.event.release.tag_name }}" + if [ "${{ github.event_name }}" = "workflow_run" ]; then + # Extract version from the tag ref (refs/tags/v0.8.7 -> v0.8.7) + VERSION="${{ github.event.workflow_run.head_branch }}" + VERSION="${VERSION#refs/tags/}" else - VERSION="${{ github.event.inputs.version }}" + # Manual workflow_dispatch trigger + VERSION="${{ inputs.version }}" fi VERSION="${VERSION#v}" URL="https://github.com/TibixDev/winboat/releases/download/v${VERSION}/winboat-${VERSION}-x64.tar.gz" + echo "Checking if release asset is available..." + for i in {1..30}; do + if curl --head --fail "$URL" &>/dev/null; then + echo "✓ Release asset is available" + break + fi + if [ $i -eq 30 ]; then + echo "✗ Release asset not available after 5 minutes" + exit 1 + fi + echo "Waiting for asset... (attempt $i/30)" + sleep 10 + done + echo "Prefetching from: $URL" HASH=$(nix-prefetch-url "$URL") @@ -66,4 +91,12 @@ jobs: git add flake.nix || true git commit -m "chore: update flake.nix for version ${VERSION}" || echo "No changes to commit" - git push origin HEAD:main || echo "Push failed" \ No newline at end of file + git push origin HEAD:main || echo "Push failed" + + # Also update the tag with the corrected flake hash + if [ "${{ github.event_name }}" = "release" ]; then + TAG="${{ github.event.release.tag_name }}" + echo "Updating tag ${TAG} with corrected flake hash" + git tag -f "${TAG}" HEAD + git push -f origin "${TAG}" || echo "Failed to update tag" + fi