From e8952ee548da01ff8b12d7fae68ae7922e0f205a Mon Sep 17 00:00:00 2001 From: poli0981 Date: Mon, 23 Nov 2026 16:26:37 +0700 Subject: [PATCH] fix(notify): read the workflow_run fields Gitea sends Gitea's workflow_run payload is not GitHub's: workflow_run has no `name` and no `head_commit`, and head_branch is empty for tag runs. So the name filters in the notify workflows never matched: notify-deploy and notify-release-pipeline never ran, and notify-ci-failure posted for every failed run on main, the ones with a dedicated notifier included. - notify-*: workflow name from github.event.workflow.name, commit title from workflow_run.display_title; the release pipeline finds tag runs, and the tag, in workflow_run.path ("@") - notify-*, announce-release: new input ops_ref (default main), so a caller loads discord_notify.py at the SHA it pins in `uses:` - weekly digest: OPS_GITEA_TOKEN also needs read:user, since GET /users/{owner}/repos checks both user and repository scopes; a 401/403 there now ends with that hint instead of a traceback - publish-r2: the release guard of the reusables, a v* tag ref from a push or workflow_dispatch (was: dispatch from any ref) - announce-release: github.token instead of secrets.GITEA_TOKEN (the same token, and one actionlint knows) - reusable-chrome-extension: `./` resolves in this repo at the same commit, so the nested publish-r2 call needs no change - .gitignore: ignore the whole .idea/ Read from the Gitea source (main, 2026-11-23); confirm on 28.4.0 with the pilot repo. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MnPQKxkPgL2sb8BqwHKv5k --- .gitea/workflows/announce-release.yml | 15 +++-- .gitea/workflows/notify-ci-failure.yml | 41 ++++++++------ .gitea/workflows/notify-deploy.yml | 32 +++++++---- .gitea/workflows/notify-release-pipeline.yml | 55 ++++++++++++++----- .gitea/workflows/publish-r2.yml | 5 +- .../workflows/reusable-chrome-extension.yml | 8 +-- .gitea/workflows/weekly-digest.yml | 7 ++- .github/scripts/discord_notify.py | 10 +++- .gitignore | 1 + 9 files changed, 116 insertions(+), 58 deletions(-) diff --git a/.gitea/workflows/announce-release.yml b/.gitea/workflows/announce-release.yml index 39cfa81..5c78ce4 100644 --- a/.gitea/workflows/announce-release.yml +++ b/.gitea/workflows/announce-release.yml @@ -14,7 +14,8 @@ name: Reusable — Announce Release to Discord # uses: poli0981/.github/.gitea/workflows/announce-release.yml@ # ops vYYYY.MM.N # with: # tag_override: ${{ inputs.tag }} -# secrets: # explicit; `secrets: inherit` is VERIFY on Gitea +# ops_ref: # the same SHA as `uses:` +# secrets: # explicit, as the runbook asks (Gitea also has `inherit`) # DISCORD_RELEASES_WEBHOOK: ${{ secrets.DISCORD_RELEASES_WEBHOOK }} # DISCORD_REPO_WEBHOOK: ${{ secrets.DISCORD_REPO_WEBHOOK }} # DISCORD_PING_ROLE_ID: ${{ secrets.DISCORD_PING_ROLE_ID }} @@ -23,7 +24,9 @@ name: Reusable — Announce Release to Discord # (GET {api_url}/repos/{owner}/{repo}/releases/tags/{tag}, same field names as GitHub) # instead of `gh api`. Gitea releases carry notes + links only (no binaries), so the # "Downloads" field is normally empty — the links are in the release body. -# VERIFY: the job token can read poli0981/.github from a caller repo (sparse checkout below). +# The job token reads poli0981/.github from a caller repo because that repo is public: Gitea +# gives every job token read access to public repos. Making it private needs the owner-level +# cross-repo Actions setting instead. on: workflow_call: @@ -32,6 +35,10 @@ on: description: "Optional tag (when re-running manually)" type: string default: "" + ops_ref: + description: "Ref of poli0981/.github the notifier script is loaded from: pass the SHA pinned in `uses:`" + type: string + default: "main" secrets: DISCORD_RELEASES_WEBHOOK: required: false @@ -54,7 +61,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: poli0981/.github - ref: main + ref: ${{ inputs.ops_ref }} path: ops sparse-checkout: | .github/scripts @@ -63,7 +70,7 @@ jobs: - name: Resolve release data (Gitea API) id: release env: - GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_TOKEN: ${{ github.token }} API_URL: ${{ github.api_url }} INPUT_TAG: ${{ inputs.tag_override }} EVENT_TAG: ${{ github.event.release.tag_name }} diff --git a/.gitea/workflows/notify-ci-failure.yml b/.gitea/workflows/notify-ci-failure.yml index 70bd76e..eb2eb8e 100644 --- a/.gitea/workflows/notify-ci-failure.yml +++ b/.gitea/workflows/notify-ci-failure.yml @@ -16,14 +16,17 @@ name: Reusable — Notify CI Failures to Discord # uses: poli0981/.github/.gitea/workflows/notify-ci-failure.yml@ # ops vYYYY.MM.N # with: # default_branch: main -# secrets: # explicit; `secrets: inherit` is VERIFY on Gitea +# ops_ref: # the same SHA as `uses:` +# secrets: # explicit, as the runbook asks (Gitea also has `inherit`) # DISCORD_CI_WEBHOOK: ${{ secrets.DISCORD_CI_WEBHOOK }} # # Gitea port 2026-11-23: -# - VERIFY: `workflow_run` triggers and the github.event.workflow_run.* payload on Gitea 28. +# - Gitea's workflow_run payload is not GitHub's (read from the Gitea source, VERIFY on +# 28.4.0): `workflow_run` has no `name` and no `head_commit`, and head_branch is empty +# for tag runs. The workflow name is github.event.workflow.name, the commit title +# workflow_run.display_title, and the ref the end of workflow_run.path ("@"). # - github.event.repository.default_branch → explicit input `default_branch` (runbook §4.1). -# - VERIFY: the run link built by discord_notify.py ({server_url}/{repo}/actions/runs/{id}) -# opens the right run on Gitea. +# - Run link {server_url}/{repo}/actions/runs/{id}: Gitea looks run IDs up first. on: workflow_call: @@ -38,6 +41,10 @@ on: description: "Caller repo default branch (Gitea may not populate github.event.repository)" type: string default: "main" + ops_ref: + description: "Ref of poli0981/.github the notifier script is loaded from: pass the SHA pinned in `uses:`" + type: string + default: "main" secrets: DISCORD_CI_WEBHOOK: required: true @@ -50,19 +57,19 @@ jobs: notify: if: > github.event.workflow_run.conclusion == 'failure' && - !startsWith(github.event.workflow_run.name, 'Notify') && - !startsWith(github.event.workflow_run.name, 'Announce') && + !startsWith(github.event.workflow.name, 'Notify') && + !startsWith(github.event.workflow.name, 'Announce') && ( inputs.skip_dedicated_workflows == false || ( - !contains(github.event.workflow_run.name, 'odeQL') && - !contains(github.event.workflow_run.name, 'ependabot') && - !contains(github.event.workflow_run.name, 'enovate') && - !contains(github.event.workflow_run.name, 'ependency') && - !contains(github.event.workflow_run.name, 'eploy') && - !contains(github.event.workflow_run.name, 'ages') && - !contains(github.event.workflow_run.name, 'elease') && - !contains(github.event.workflow_run.name, 'esktop') + !contains(github.event.workflow.name, 'odeQL') && + !contains(github.event.workflow.name, 'ependabot') && + !contains(github.event.workflow.name, 'enovate') && + !contains(github.event.workflow.name, 'ependency') && + !contains(github.event.workflow.name, 'eploy') && + !contains(github.event.workflow.name, 'ages') && + !contains(github.event.workflow.name, 'elease') && + !contains(github.event.workflow.name, 'esktop') ) ) && ( @@ -83,7 +90,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: poli0981/.github - ref: main + ref: ${{ inputs.ops_ref }} path: ops sparse-checkout: | .github/scripts @@ -92,13 +99,13 @@ jobs: - name: Post failure to Discord env: DISCORD_CI_WEBHOOK: ${{ secrets.DISCORD_CI_WEBHOOK }} - WORKFLOW_NAME: ${{ github.event.workflow_run.name }} + WORKFLOW_NAME: ${{ github.event.workflow.name }} RUN_ID: ${{ github.event.workflow_run.id }} RUN_NUMBER: ${{ github.event.workflow_run.run_number }} RUN_ATTEMPT: ${{ github.event.workflow_run.run_attempt }} BRANCH: ${{ github.event.workflow_run.head_branch }} COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} - COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }} + COMMIT_MESSAGE: ${{ github.event.workflow_run.display_title }} ACTOR: ${{ github.event.workflow_run.actor.login }} EVENT_NAME: ${{ github.event.workflow_run.event }} run: python3 ops/.github/scripts/discord_notify.py failure diff --git a/.gitea/workflows/notify-deploy.yml b/.gitea/workflows/notify-deploy.yml index 6fdce35..e8cdd3a 100644 --- a/.gitea/workflows/notify-deploy.yml +++ b/.gitea/workflows/notify-deploy.yml @@ -13,6 +13,7 @@ name: Reusable — Notify Deploy Status to Discord # uses: poli0981/.github/.gitea/workflows/notify-deploy.yml@ # ops vYYYY.MM.N # with: # deploy_url: https://example.poli0981.dev # live site shown on success (optional) +# ops_ref: # the same SHA as `uses:` # secrets: # DISCORD_CI_WEBHOOK: ${{ secrets.DISCORD_CI_WEBHOOK }} # @@ -20,7 +21,10 @@ name: Reusable — Notify Deploy Status to Discord # - The GitHub Pages lookup (`gh api repos/.../pages`) is removed — Pages does not exist on # Gitea and sites deploy to Cloudflare Workers. Pass the live URL with `deploy_url`. # - github.event.repository.default_branch → explicit input `default_branch` (runbook §4.1). -# - VERIFY: `workflow_run` triggers and payload on Gitea 28. +# - Gitea's workflow_run payload is not GitHub's (read from the Gitea source, VERIFY on +# 28.4.0): `workflow_run` has no `name` and no `head_commit`, and head_branch is empty +# for tag runs. The workflow name is github.event.workflow.name, the commit title +# workflow_run.display_title, and the ref the end of workflow_run.path ("@"). on: workflow_call: @@ -33,6 +37,10 @@ on: description: "Caller repo default branch (Gitea may not populate github.event.repository)" type: string default: "main" + ops_ref: + description: "Ref of poli0981/.github the notifier script is loaded from: pass the SHA pinned in `uses:`" + type: string + default: "main" secrets: DISCORD_CI_WEBHOOK: required: true @@ -46,14 +54,14 @@ jobs: if: > (github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure') && ( - contains(github.event.workflow_run.name, 'eploy') || - contains(github.event.workflow_run.name, 'ages') || - contains(github.event.workflow_run.name, 'ublish') + contains(github.event.workflow.name, 'eploy') || + contains(github.event.workflow.name, 'ages') || + contains(github.event.workflow.name, 'ublish') ) && - !startsWith(github.event.workflow_run.name, 'Notify') && - !contains(github.event.workflow_run.name, 'odeQL') && - !contains(github.event.workflow_run.name, 'ependabot') && - !contains(github.event.workflow_run.name, 'enovate') && + !startsWith(github.event.workflow.name, 'Notify') && + !contains(github.event.workflow.name, 'odeQL') && + !contains(github.event.workflow.name, 'ependabot') && + !contains(github.event.workflow.name, 'enovate') && ( github.event.workflow_run.head_branch == inputs.default_branch || github.event.workflow_run.head_branch == 'main' || @@ -69,7 +77,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: poli0981/.github - ref: main + ref: ${{ inputs.ops_ref }} path: ops sparse-checkout: | .github/scripts @@ -78,7 +86,7 @@ jobs: - name: Detect deploy target from workflow name id: target env: - WF_NAME: ${{ github.event.workflow_run.name }} + WF_NAME: ${{ github.event.workflow.name }} run: | TARGET="Deploy" # Later matches win. No GitHub Pages on Gitea; sites deploy to Cloudflare Workers. @@ -95,11 +103,11 @@ jobs: DEPLOY_STATUS: ${{ github.event.workflow_run.conclusion }} DEPLOY_TARGET: ${{ steps.target.outputs.target }} DEPLOY_URL: ${{ github.event.workflow_run.conclusion == 'success' && inputs.deploy_url || '' }} - WORKFLOW_NAME: ${{ github.event.workflow_run.name }} + WORKFLOW_NAME: ${{ github.event.workflow.name }} RUN_ID: ${{ github.event.workflow_run.id }} RUN_NUMBER: ${{ github.event.workflow_run.run_number }} BRANCH: ${{ github.event.workflow_run.head_branch }} COMMIT_SHA: ${{ github.event.workflow_run.head_sha }} - COMMIT_MESSAGE: ${{ github.event.workflow_run.head_commit.message }} + COMMIT_MESSAGE: ${{ github.event.workflow_run.display_title }} ACTOR: ${{ github.event.workflow_run.actor.login }} run: python3 ops/.github/scripts/discord_notify.py deploy diff --git a/.gitea/workflows/notify-release-pipeline.yml b/.gitea/workflows/notify-release-pipeline.yml index e1f752c..d65a848 100644 --- a/.gitea/workflows/notify-release-pipeline.yml +++ b/.gitea/workflows/notify-release-pipeline.yml @@ -11,14 +11,26 @@ name: Reusable — Notify Release Pipeline to Discord # jobs: # notify: # uses: poli0981/.github/.gitea/workflows/notify-release-pipeline.yml@ # ops vYYYY.MM.N +# with: +# ops_ref: # the same SHA as `uses:` # secrets: # DISCORD_RELEASE_PIPELINE_WEBHOOK: ${{ secrets.DISCORD_RELEASE_PIPELINE_WEBHOOK }} # -# Gitea port 2026-11-23: VERIFY `workflow_run` triggers on Gitea 28 and that head_branch -# carries the tag name (v*) for tag-push runs, as on GitHub. +# Gitea port 2026-11-23: +# - Gitea's workflow_run payload is not GitHub's (read from the Gitea source, VERIFY on +# 28.4.0): `workflow_run` has no `name` and no `head_commit`, and head_branch is empty +# for tag runs. The workflow name is github.event.workflow.name, the commit title +# workflow_run.display_title, and the ref the end of workflow_run.path ("@"). +# - So tag runs are recognised by "@refs/tags/v" in workflow_run.path, and the tag is cut +# from it (step "Resolve release tag"). on: workflow_call: + inputs: + ops_ref: + description: "Ref of poli0981/.github the notifier script is loaded from: pass the SHA pinned in `uses:`" + type: string + default: "main" secrets: DISCORD_RELEASE_PIPELINE_WEBHOOK: required: true @@ -31,18 +43,18 @@ jobs: notify: if: > ( - contains(github.event.workflow_run.name, 'elease') || - contains(github.event.workflow_run.name, 'esktop') + contains(github.event.workflow.name, 'elease') || + contains(github.event.workflow.name, 'esktop') ) && - !startsWith(github.event.workflow_run.name, 'Notify') && - !startsWith(github.event.workflow_run.name, 'Announce') && - !contains(github.event.workflow_run.name, 'odeQL') && - !contains(github.event.workflow_run.name, 'ependabot') && + !startsWith(github.event.workflow.name, 'Notify') && + !startsWith(github.event.workflow.name, 'Announce') && + !contains(github.event.workflow.name, 'odeQL') && + !contains(github.event.workflow.name, 'ependabot') && ( github.event.workflow_run.event == 'release' || github.event.workflow_run.event == 'workflow_dispatch' || - startsWith(github.event.workflow_run.head_branch, 'v') || - startsWith(github.event.workflow_run.head_branch, 'desktop-v') + contains(github.event.workflow_run.path, '@refs/tags/v') || + contains(github.event.workflow_run.path, '@refs/tags/desktop-v') ) && ( github.event.workflow_run.conclusion == 'success' || @@ -59,7 +71,7 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: poli0981/.github - ref: main + ref: ${{ inputs.ops_ref }} path: ops sparse-checkout: | .github/scripts @@ -68,7 +80,7 @@ jobs: - name: Detect packager id: detect env: - WF_NAME: ${{ github.event.workflow_run.name }} + WF_NAME: ${{ github.event.workflow.name }} REPO: ${{ github.repository }} run: | PACKAGER="" @@ -82,13 +94,28 @@ jobs: esac echo "packager=$PACKAGER" >> "$GITHUB_OUTPUT" + - name: Resolve release tag + id: tag + env: + WF_PATH: ${{ github.event.workflow_run.path }} # ".yml@" on Gitea + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} + run: | + set -euo pipefail + # Gitea leaves head_branch empty for tag runs; the ref is the end of workflow_run.path. + ref="${WF_PATH#*@}" + case "$ref" in + refs/tags/*) tag="${ref#refs/tags/}" ;; + *) tag="$HEAD_BRANCH" ;; + esac + echo "tag=$tag" >> "$GITHUB_OUTPUT" + - name: Post release pipeline status env: DISCORD_RELEASE_PIPELINE_WEBHOOK: ${{ secrets.DISCORD_RELEASE_PIPELINE_WEBHOOK }} BUILD_STATUS: ${{ github.event.workflow_run.conclusion }} BUILD_PLATFORM: ${{ github.event.workflow_run.event }} BUILD_PACKAGER: ${{ steps.detect.outputs.packager }} - RELEASE_TAG: ${{ github.event.workflow_run.head_branch }} - WORKFLOW_NAME: ${{ github.event.workflow_run.name }} + RELEASE_TAG: ${{ steps.tag.outputs.tag }} + WORKFLOW_NAME: ${{ github.event.workflow.name }} RUN_ID: ${{ github.event.workflow_run.id }} run: python3 ops/.github/scripts/discord_notify.py release-build diff --git a/.gitea/workflows/publish-r2.yml b/.gitea/workflows/publish-r2.yml index 717af24..4f8dafc 100644 --- a/.gitea/workflows/publish-r2.yml +++ b/.gitea/workflows/publish-r2.yml @@ -39,7 +39,8 @@ # stale feed — the job fails before uploading anything # - rclone pinned + SHA-256 verified; configured only through env vars, with an empty # config file so the host-mode Windows runner never picks up a local rclone.conf -# - runs only for tag pushes (refs/tags/v*) or workflow_dispatch (runbook §2 rule 10) +# - runs only on a v* tag: a tag push, or workflow_dispatch started on that tag +# (runbook §2 rule 10), the same guard as the release jobs in the reusables name: Reusable / Publish to R2 @@ -82,7 +83,7 @@ permissions: jobs: publish: # Release credentials: tag pushes or manual runs only (runbook §2 rule 10) - if: ${{ (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) || github.event_name == 'workflow_dispatch' }} + if: ${{ startsWith(github.ref, 'refs/tags/v') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} runs-on: ${{ inputs.runs-on }} timeout-minutes: 30 permissions: diff --git a/.gitea/workflows/reusable-chrome-extension.yml b/.gitea/workflows/reusable-chrome-extension.yml index f3b5f9d..7b01851 100644 --- a/.gitea/workflows/reusable-chrome-extension.yml +++ b/.gitea/workflows/reusable-chrome-extension.yml @@ -28,9 +28,9 @@ # R2_RELEASES_SECRET_ACCESS_KEY: ${{ secrets.R2_RELEASES_SECRET_ACCESS_KEY }} # # Gitea port 2026-11-23: ubuntu-latest = Docker image docker.gitea.com/runner-images. -# VERIFY on pilot: the nested call `uses: ./.gitea/workflows/publish-r2.yml` must resolve to -# this ops repo at the same commit. If Gitea resolves `./` against the CALLER repo, change it -# to `poli0981/.github/.gitea/workflows/publish-r2.yml@`. +# The nested call `uses: ./.gitea/workflows/publish-r2.yml` resolves to THIS ops repo at the +# same commit: Gitea reads `./` against the repo and commit of the file that holds the +# `uses:`, not against the caller repo (read from the Gitea source; VERIFY on 28.4.0). # Actions pinned to commit SHAs (Renovate keeps them current). name: Reusable / Chrome Extension @@ -211,7 +211,7 @@ jobs: if: ${{ inputs.release && startsWith(github.ref, 'refs/tags/v') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') }} permissions: contents: read - uses: ./.gitea/workflows/publish-r2.yml # VERIFY: resolves to this ops repo (see header) + uses: ./.gitea/workflows/publish-r2.yml # this ops repo, same commit (see header) with: app: ${{ needs.package.outputs.app }} artifact: r2-release diff --git a/.gitea/workflows/weekly-digest.yml b/.gitea/workflows/weekly-digest.yml index 44cac54..f4b5e53 100644 --- a/.gitea/workflows/weekly-digest.yml +++ b/.gitea/workflows/weekly-digest.yml @@ -10,9 +10,10 @@ name: Weekly Digest # Required repo secrets (set on poli0981/.github): # DISCORD_DIGEST_WEBHOOK — webhook for #announcements # OPS_GITEA_TOKEN — Gitea PAT (Settings → Applications), scopes: -# read:repository + read:issue. The job token -# (GITEA_TOKEN) only sees this repo, so it cannot -# aggregate the others. +# read:repository + read:issue + read:user +# (GET /users/{owner}/repos needs user AND repository). +# The job token (GITEA_TOKEN) does not see private +# repos, so it cannot aggregate them. # # Run on demand: Actions → Weekly Digest → Run workflow diff --git a/.github/scripts/discord_notify.py b/.github/scripts/discord_notify.py index 02215c4..abe639d 100644 --- a/.github/scripts/discord_notify.py +++ b/.github/scripts/discord_notify.py @@ -441,7 +441,7 @@ def post_weekly_digest() -> int: Env: DISCORD_DIGEST_WEBHOOK — webhook for #announcements - OPS_GITEA_TOKEN — Gitea PAT, scopes read:repository + read:issue + OPS_GITEA_TOKEN — Gitea PAT, scopes read:repository + read:issue + read:user (the job token only sees its own repo) GH_OWNER — owner username (default: owner part of GITHUB_REPOSITORY) GITEA_API_URL — API root, e.g. https://git.poli0981.dev/api/v1 @@ -473,7 +473,13 @@ def post_weekly_digest() -> int: ] # Releases: no cross-repo endpoint, so list them per repo and filter by published_at. - repos = _gitea_paged(base, f"/users/{quote(owner, safe='')}/repos", token) + try: + repos = _gitea_paged(base, f"/users/{quote(owner, safe='')}/repos", token) + except HTTPError as e: + if e.code in (401, 403): + print("[ERROR] OPS_GITEA_TOKEN cannot list the repos: GET /users/{owner}/repos needs " + "the scopes read:user + read:repository.") + return 1 releases_by_repo: dict[str, list[dict]] = defaultdict(list) for repo in repos: repo_full = repo.get("full_name", "") diff --git a/.gitignore b/.gitignore index 60f7576..5f74abd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/ .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml -- 2.54.1