From c8aa04d44f8b84346bf74048e82c4cf7cc1ecd65 Mon Sep 17 00:00:00 2001 From: supahgreg Date: Thu, 16 Oct 2025 20:47:57 +0000 Subject: [PATCH] Break 'version.json' stuff out to a separate workflow. --- .github/workflows/publish-version-json.yml | 79 ++++++++++++++++++++++ .github/workflows/publish.yml | 65 +----------------- 2 files changed, 80 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/publish-version-json.yml diff --git a/.github/workflows/publish-version-json.yml b/.github/workflows/publish-version-json.yml new file mode 100644 index 000000000..8f5aeaacf --- /dev/null +++ b/.github/workflows/publish-version-json.yml @@ -0,0 +1,79 @@ +name: Publish Version JSON + +on: + # Allow manual triggering + workflow_dispatch: + # Allow other workflows (e.g. Publish) to invoke this one. + workflow_call: + + +permissions: + contents: write + + +jobs: + publish-version: + name: Publish version.json + runs-on: ubuntu-latest + + steps: + - name: Check out code + uses: actions/checkout@v5 + + - name: Generate version.json + run: | + # Get the commit short SHA (8 characters) expected by the backend + COMMIT_SHORT_SHA=$(git rev-parse --short=8 HEAD) + + # Get the commit timestamp in Unix format + COMMIT_TIMESTAMP=$(git show -s --format=%ct HEAD) + + # Create version.json with the expected format for RPC#checkforupdates() + jq -n \ + --arg commit_id "$COMMIT_SHORT_SHA" \ + --argjson commit_timestamp "$COMMIT_TIMESTAMP" \ + '{ + changeset: { + id: $commit_id, + timestamp: $commit_timestamp + } + }' > version.json + + cat version.json + + - name: Deploy version.json to gh-pages + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # Save version.json to a safe location outside the repo + cp version.json /tmp/version.json + + # Fetch gh-pages branch + git fetch origin gh-pages 2>/dev/null || true + + if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then + # gh-pages exists + # Remove the local version.json first to avoid conflicts when switching branches + rm -f version.json + git checkout gh-pages + else + # Create new orphan gh-pages branch + git checkout --orphan gh-pages + git rm -rf . 2>/dev/null || true + fi + + # Restore version.json from safe location + cp /tmp/version.json version.json + git add version.json + + # Check if there are changes to commit + if git diff --staged --quiet; then + echo "No changes to commit" + else + # Set up git authentication for GitHub-signed commits + gh auth setup-git + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -m "Update version info [automated]" + git push origin gh-pages || { echo "Failed to push to gh-pages"; exit 1; } + fi diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5e185a14b..ef00e1818 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -127,71 +127,8 @@ jobs: push: true publish-version: - name: Publish version.json needs: - publish - runs-on: ubuntu-latest + uses: ./.github/workflows/publish-version-json.yml permissions: contents: write - - steps: - - name: Check out code - uses: actions/checkout@v5 - - - name: Generate version.json - run: | - # Get the commit short SHA (8 characters) expected by the backend - COMMIT_SHORT_SHA=$(git rev-parse --short=8 HEAD) - - # Get the commit timestamp in Unix format - COMMIT_TIMESTAMP=$(git show -s --format=%ct HEAD) - - # Create version.json with the expected format for RPC#checkforupdates() - jq -n \ - --arg commit_id "$COMMIT_SHORT_SHA" \ - --argjson commit_timestamp "$COMMIT_TIMESTAMP" \ - '{ - changeset: { - id: $commit_id, - timestamp: $commit_timestamp - } - }' > version.json - - cat version.json - - - name: Deploy version.json to gh-pages - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - # Save version.json to a safe location outside the repo - cp version.json /tmp/version.json - - # Fetch gh-pages branch - git fetch origin gh-pages 2>/dev/null || true - - if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then - # gh-pages exists - # Remove the local version.json first to avoid conflicts when switching branches - rm -f version.json - git checkout gh-pages - else - # Create new orphan gh-pages branch - git checkout --orphan gh-pages - git rm -rf . 2>/dev/null || true - fi - - # Restore version.json from safe location - cp /tmp/version.json version.json - git add version.json - - # Check if there are changes to commit - if git diff --staged --quiet; then - echo "No changes to commit" - else - # Set up git authentication for GitHub-signed commits - gh auth setup-git - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git commit -m "Update version info [automated]" - git push origin gh-pages || { echo "Failed to push to gh-pages"; exit 1; } - fi