Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/chart-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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})"
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/semver-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]}')
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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-<pull request number>`;
- 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-<pull request number>`;
- 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 `<tag-prefix>X.Y.Z`; other tags, such as pre-releases (`1.2.3-PRE-4`), are ignored.
Expand Down
Loading