From 32d36f957bcee1699be38056fa661d6d47919f98 Mon Sep 17 00:00:00 2001 From: Victor Ramperez Date: Thu, 29 Oct 2026 11:06:16 +0100 Subject: [PATCH] Read the semver label of a pull request when the job runs chart-pr.yml and semver-version.yml took the labels from the event that started the run. A pull request opened with a label, as the appVersion bot of helm-charts does with gh pr create --label, gets it two seconds after the opened event, and the labeled event of the workflow token starts no run: the check failed with 'found: none' although the label was there, and re-running it read the same event again (FIWARE/helm-charts#645, #647, #649). The labels are now read from the API, so the label counts and a re-run picks up a label added later. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/chart-pr.yml | 8 +++++++- .github/workflows/semver-version.yml | 7 ++++--- README.md | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/workflows/chart-pr.yml b/.github/workflows/chart-pr.yml index 1f786d8..fb979cf 100644 --- a/.github/workflows/chart-pr.yml +++ b/.github/workflows/chart-pr.yml @@ -28,11 +28,17 @@ jobs: outputs: bump: ${{ steps.label.outputs.bump }} steps: + # The labels the pull request has now, not the ones of the event that started the run: a pull + # request opened with a label (gh pr create --label) gets it right after the `opened` event, and + # the `labeled` event of the workflow token starts no run. Reading them now also lets a re-run + # pick up a label added later. - name: Read the semver label id: label env: - LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} + GH_TOKEN: ${{ github.token }} + PR: ${{ github.event.pull_request.number }} run: | + LABELS=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '[.labels[].name]') bumps=$(jq -r '[.[] | select(. == "major" or . == "minor" or . == "patch")] | join(" ")' <<< "$LABELS") if [ "$(wc -w <<< "$bumps")" -ne 1 ]; then echo "::error::The pull request needs exactly one of the labels major, minor or patch (found: ${bumps:-none})" diff --git a/.github/workflows/semver-version.yml b/.github/workflows/semver-version.yml index 4e92499..d3db628 100644 --- a/.github/workflows/semver-version.yml +++ b/.github/workflows/semver-version.yml @@ -58,17 +58,18 @@ jobs: path: semver-workflows persist-credentials: false - # on a push, the labels of the pull request the pushed commit was merged from + # On a pull request, the labels it has now, not the ones of the event that started the run (see + # chart-pr.yml). On a push, the labels of the pull request the pushed commit was merged from. - name: Read the semver label id: label env: GH_TOKEN: ${{ github.token }} EVENT: ${{ github.event_name }} - PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }} + PR: ${{ github.event.pull_request.number }} SHA: ${{ github.sha }} run: | if [ "$EVENT" = pull_request ]; then - labels="$PR_LABELS" + labels=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '[.labels[].name]') else pr=$(gh api "repos/$GITHUB_REPOSITORY/commits/$SHA/pulls" \ --jq '[.[] | select(.merged_at != null)][0] // empty | {number, labels: [.labels[].name]}') diff --git a/README.md b/README.md index 73555b7..4f4223d 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ jobs: For repositories that release Helm charts from a `charts/` directory, with the version of each chart driven by the semver label of the pull request that changes it. On every pull request it: -1. requires exactly one of the labels `major`, `minor` or `patch`, and comments on the pull request when it is missing; +1. requires exactly one of the labels `major`, `minor` or `patch`, and comments on the pull request when it is missing. The labels are read when the job runs, not from the event that started it, so a label added right after the pull request was opened counts, and re-running the job picks up a label added later; 2. bumps the `version` of every chart the pull request changes: its version on the base branch, bumped by the label. A chart that is not on the base branch yet keeps its version; 3. commits the new versions ("Update helm chart versions") to the pull request branch. A pull request from a fork, which the workflow token cannot push to, fails instead, listing the versions its author has to set. @@ -141,7 +141,7 @@ The chart version is bumped in the pull request itself because pull requests ope For repositories that release an application, not charts, with the version driven by the semver label of the pull request. It works out the version and leaves the build and the release to the caller: -- on a pull request, it requires exactly one of the labels `major`, `minor` or `patch`, commenting on the pull request when it is missing, and returns `X.Y.Z-PRE-`; +- on a pull request, it requires exactly one of the labels `major`, `minor` or `patch` (read when the job runs, as in `chart-pr.yml`), commenting on the pull request when it is missing, and returns `X.Y.Z-PRE-`; - on a push to the main branch, it reads the label of the pull request the pushed commit was merged from, and returns `X.Y.Z`. A commit that no merged pull request contains, or one merged without a label, fails. `X.Y.Z` is the highest release tag bumped by the label. Release tags are `X.Y.Z`; other tags, such as pre-releases (`1.2.3-PRE-4`), are ignored.