Check FOG version #27
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: Check FOG version | |
| # Daily sweep across all watched fogproject branches, at 10:10 UTC - just | |
| # over an hour before stable-releases.yml's monthly run (11:11 UTC on the | |
| # 11th), so a release never reads a stale version on the day it's cut. | |
| # Runs entirely out of this repo - GitHub Actions has no native cross-repo | |
| # push trigger, and yesterday's push-triggered design (a stub living in | |
| # fogproject, calling a reusable workflow here) had real maintenance cost: | |
| # the stub had to be propagated onto every watched branch by hand, and | |
| # worse, a bot-authored fixup push back into fogproject re-triggered the | |
| # stub, which re-triggered this workflow, which pushed another fixup - an | |
| # infinite self-correcting commit loop that put 30 commits on dev-branch in | |
| # ~20 minutes before it was caught. A schedule trigger sidesteps both | |
| # problems: nothing about this workflow's own commits can cause another | |
| # run, since a cron tick doesn't look at what was last pushed. Daily rather | |
| # than hourly caps any real drift-fixing to at most one commit per branch | |
| # per day, instead of the same fix (however rarely actually needed) running | |
| # up to 24 times over the same 24 hours. | |
| # | |
| # Computes FOG_VERSION/FOG_CHANNEL by running fogproject's own | |
| # .githooks/lib/fog-version.sh against each watched branch - the same script | |
| # .githooks/pre-commit calls locally - rather than keeping a second, | |
| # separately-maintained copy of the math here. That script only computes | |
| # and prints the values (no file writes, so it's safe to run without side | |
| # effects); .githooks/lib/apply-fog-version.sh does the actual write. If | |
| # the result disagrees with what's committed, pushes a fixup commit | |
| # directly to that branch - no PR, since this mirrors the same kind of | |
| # mechanical correction the local hook already makes. | |
| # | |
| # Never invoked for `stable` - that branch's version is owned entirely by | |
| # stable-releases.yml's release flow. | |
| # | |
| # Each matrix instance writes its own outcome (fixed / already correct) to | |
| # $GITHUB_STEP_SUMMARY, and GitHub renders every job's summary together on | |
| # the run's Summary page - so the state of every watched branch is visible | |
| # at a glance from one run, with no need to open individual job logs. | |
| # | |
| # dev-branch and working-1.6 also get a small JSON badge file committed | |
| # into this repo (badges/<branch>.json), read by a shields.io endpoint | |
| # badge in fogproject's README - see that README for the rendered badges. | |
| # stable's badge is written by stable-releases.yml instead, since that's | |
| # the only workflow that ever changes stable's version. | |
| on: | |
| schedule: | |
| - cron: "10 10 * * *" | |
| workflow_call: | |
| inputs: | |
| branch: | |
| description: "Single fogproject branch to check (omit to sweep all watched branches)" | |
| required: false | |
| type: string | |
| workflow_dispatch: | |
| inputs: | |
| branch: | |
| description: "Single fogproject branch to check (omit to sweep all watched branches)" | |
| required: false | |
| type: string | |
| concurrency: | |
| group: fog-version-check | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| jobs: | |
| discover-branches: | |
| runs-on: ubuntu-24.04 | |
| outputs: | |
| branches: ${{ steps.list.outputs.branches }} | |
| steps: | |
| - uses: actions/create-github-app-token@v3 | |
| id: app-token | |
| with: | |
| client-id: ${{ vars.FOG_WORKFLOWS_APPID }} | |
| private-key: ${{ secrets.FOG_WORKFLOWS_PRIVATE_KEY }} | |
| owner: FOGProject | |
| repositories: "fogproject" | |
| - name: List watched branches | |
| id: list | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| SINGLE_BRANCH: ${{ inputs.branch }} | |
| run: | | |
| set -e | |
| if [ -n "$SINGLE_BRANCH" ]; then | |
| branches=$(jq -n --arg branch "$SINGLE_BRANCH" -c '[$branch]') | |
| else | |
| all=$(gh api repos/FOGProject/fogproject/branches --paginate --jq '.[].name') | |
| matched=$(printf '%s\n' "$all" | grep -E '^(working-1\.6|dev-branch)$|^(rc-|feature-)' || true) | |
| branches=$(printf '%s\n' "$matched" | jq -R -s -c 'split("\n") | map(select(length > 0))') | |
| fi | |
| echo "branches=$branches" >> "$GITHUB_OUTPUT" | |
| { | |
| echo "## Watched branches" | |
| echo "" | |
| if [ "$branches" = "[]" ]; then | |
| echo "None found." | |
| else | |
| printf '%s\n' "$branches" | jq -r '.[] | "- `\(.)`"' | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" | |
| check-version: | |
| needs: discover-branches | |
| if: needs.discover-branches.outputs.branches != '[]' | |
| runs-on: ubuntu-24.04 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| branch: ${{ fromJson(needs.discover-branches.outputs.branches) }} | |
| steps: | |
| - uses: actions/create-github-app-token@v3 | |
| id: app-token | |
| with: | |
| client-id: ${{ vars.FOG_WORKFLOWS_APPID }} | |
| private-key: ${{ secrets.FOG_WORKFLOWS_PRIVATE_KEY }} | |
| owner: FOGProject | |
| repositories: "fogproject" | |
| - uses: actions/checkout@v7 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| repository: FOGProject/fogproject | |
| ref: ${{ matrix.branch }} | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Compute FOG_VERSION / FOG_CHANNEL | |
| id: compute | |
| run: | | |
| set -e | |
| computed=$(sh .githooks/lib/fog-version.sh "${{ matrix.branch }}" 0) | |
| echo "version=$(printf '%s\n' "$computed" | sed -n '1p')" >> "$GITHUB_OUTPUT" | |
| echo "channel=$(printf '%s\n' "$computed" | sed -n '2p')" >> "$GITHUB_OUTPUT" | |
| echo "drifted=$(printf '%s\n' "$computed" | sed -n '3p')" >> "$GITHUB_OUTPUT" | |
| - name: Apply, commit, and push if stale | |
| id: commit | |
| if: steps.compute.outputs.drifted == 'true' | |
| env: | |
| BOT_SLUG: ${{ steps.app-token.outputs.app-slug }} | |
| run: | | |
| set -e | |
| system_file="packages/web/lib/fog/system.class.php" | |
| old_version=$(grep "define('FOG_VERSION'" "$system_file" | sed "s/.*FOG_VERSION', '\([^']*\)');/\1/") | |
| echo "old_version=$old_version" >> "$GITHUB_OUTPUT" | |
| sh .githooks/lib/apply-fog-version.sh \ | |
| "${{ steps.compute.outputs.version }}" \ | |
| "${{ steps.compute.outputs.channel }}" | |
| echo "Version drift detected on ${{ matrix.branch }}:" | |
| git diff -- "$system_file" | |
| git config user.name "${BOT_SLUG}[bot]" | |
| git config user.email "${BOT_SLUG}[bot]@users.noreply.github.com" | |
| git add "$system_file" | |
| git commit -m "Version Sync: Increment version from ${old_version} to ${{ steps.compute.outputs.version }} for ${{ steps.compute.outputs.channel }} channel on ${{ matrix.branch }} to match commit count since master" | |
| git push origin "HEAD:${{ matrix.branch }}" | |
| - name: Update version badge | |
| if: contains(fromJson('["dev-branch", "working-1.6"]'), matrix.branch) | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| set -e | |
| path="badges/${{ matrix.branch }}.json" | |
| body=$(jq -n \ | |
| --arg label "${{ matrix.branch }}" \ | |
| --arg message "${{ steps.compute.outputs.version }}" \ | |
| '{schemaVersion: 1, label: $label, message: $message, color: "blue", cacheSeconds: 3600}') | |
| content=$(printf '%s' "$body" | base64 -w0) | |
| sha=$(gh api "repos/FOGProject/fog-workflows/contents/$path" --jq .sha 2>/dev/null || true) | |
| if [ -n "$sha" ]; then | |
| gh api "repos/FOGProject/fog-workflows/contents/$path" -X PUT \ | |
| -f message="chore: update ${{ matrix.branch }} version badge" \ | |
| -f content="$content" -f sha="$sha" >/dev/null | |
| else | |
| gh api "repos/FOGProject/fog-workflows/contents/$path" -X PUT \ | |
| -f message="chore: add ${{ matrix.branch }} version badge" \ | |
| -f content="$content" >/dev/null | |
| fi | |
| - name: Summarize | |
| if: always() | |
| run: | | |
| { | |
| echo "## \`${{ matrix.branch }}\`" | |
| echo "" | |
| if [ "${{ steps.compute.outputs.drifted }}" != "true" ]; then | |
| echo "✅ Already correct - \`${{ steps.compute.outputs.version }}\` (channel: ${{ steps.compute.outputs.channel }})" | |
| elif [ "${{ steps.commit.outcome }}" = "success" ]; then | |
| echo "🔧 **Fixed** - \`${{ steps.commit.outputs.old_version }}\` → \`${{ steps.compute.outputs.version }}\` (channel: ${{ steps.compute.outputs.channel }})" | |
| else | |
| echo "⚠️ Drift detected but the fix did not complete - check the job log." | |
| fi | |
| } >> "$GITHUB_STEP_SUMMARY" |