-
Notifications
You must be signed in to change notification settings - Fork 73
Create GitHub action for bumping patch versions #1259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0141a00
Add manual patch release workflow for Go KRM functions
mozesl-nokia df4bc1a
Simplify manual patch release script and add list-functions target
mozesl-nokia 7998fa2
Apply suggestions from code review
mozesl-nokia a31ac0d
Apply suggestions from code review
mozesl-nokia 3f7533b
Rely on other workflows to do the bulk of the work
mozesl-nokia d2d9718
Remove dependency on go and notes pregeneration
mozesl-nokia 0e062bc
use app token instead
mozesl-nokia 255cd73
Apply suggestions from code review
mozesl-nokia 3f991d7
align token generation ID and key with new app
mozesl-nokia 6f52e57
final adjustments
mozesl-nokia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # Copyright 2026 The kpt Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Manual patch release for functions/go KRM functions. | ||
| # | ||
| # - Input: comma-separated function names, or "all" (case-insensitive) for every name from | ||
| # `make list-functions`. With "all", functions without a prior functions/go/<name>/v* semver tag | ||
| # are skipped with a notice. | ||
| # - Resolves the latest functions/go/<name>/vMAJOR.MINOR.PATCH tag, bumps patch only. | ||
| # - Creates a GitHub Release (and tag at github.sha) via `gh` using a GitHub App installation | ||
| # access token (not GITHUB_TOKEN), so tag push events start other workflows. | ||
| # - Image build/push, short tag, and appending the container image line to release notes are handled | ||
| # by workflows triggered on the new tag (e.g. after-tag-with-version.yaml, release.yaml). | ||
| # | ||
| # GitHub App setup (org or user app, installed on this repository): | ||
| # 1. Create a GitHub App with Repository permissions: Contents (Read and write), Metadata (Read). | ||
| # 2. Install the app on this repository (Only select repositories). | ||
| # 3. Repository secret: CI_BOT_APP_ID = App ID (numeric, from app settings). | ||
| # 4. Repository secret: CI_BOT_PRIVATE_KEY = App private key (.pem contents). | ||
|
|
||
| name: Manual patch release (functions/go) | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| functions: | ||
| description: >- | ||
| Comma-separated function names (e.g. kubeconform,apply-setters), or "all" to patch-release | ||
| every function from `make list-functions`. Functions with no prior v* semver tag | ||
| are skipped with a notice when using "all". | ||
| required: true | ||
| type: string | ||
| dry_run: | ||
| description: "If true, only print planned versions (no releases)" | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| concurrency: | ||
| group: manual-patch-release-catalog | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| release: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
| fetch-tags: true | ||
|
|
||
| - name: Generate GitHub App token | ||
| if: ${{ !inputs.dry_run }} | ||
| id: app-token | ||
| uses: actions/create-github-app-token@v3 | ||
| with: | ||
| app-id: ${{ secrets.CI_BOT_APP_ID }} | ||
| private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }} | ||
| permission-contents: write | ||
|
|
||
| - name: Patch release (GitHub release only) | ||
| env: | ||
| MANUAL_PATCH_FUNCTIONS: ${{ inputs.functions }} | ||
| MANUAL_PATCH_DRY_RUN: ${{ inputs.dry_run }} | ||
| GITHUB_REPOSITORY: ${{ github.repository }} | ||
| GITHUB_SHA: ${{ github.sha }} | ||
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
| run: bash scripts/manual-patch-release.sh |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Copyright 2026 The kpt Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| # Manual patch release for functions/go KRM functions (used by GitHub Actions and runnable locally). | ||
| # | ||
| # Creates a GitHub Release (and the semver tag on the server at GITHUB_SHA) via `gh`. Image build, | ||
| # short tag creation, and appending the container image to release notes are left to workflows | ||
| # that run on tag push (e.g. after-tag-with-version.yaml, release.yaml). Use a GitHub App | ||
| # installation access token or PAT for GH_TOKEN in CI so those workflows are triggered; | ||
| # GITHUB_TOKEN-created tag/release events do not start them. | ||
| # | ||
| # Environment (required unless noted): | ||
| # MANUAL_PATCH_FUNCTIONS Comma-separated function names (must match output of: make list-functions), | ||
| # or the single word "all" (case-insensitive) to release every name from | ||
| # `make list-functions`. With "all", functions with no prior | ||
| # functions/go/<name>/vMAJOR.MINOR.PATCH tag are skipped with a notice. | ||
| # GITHUB_REPOSITORY owner/repo (e.g. kptdev/krm-functions-catalog). | ||
| # GITHUB_SHA Commit SHA for the new tag and release target. | ||
| # GH_TOKEN GitHub App installation token or PAT for gh release create — required | ||
| # when not in dry-run; must allow creating releases and tags on the repo. | ||
| # | ||
| # Optional: | ||
| # MANUAL_PATCH_DRY_RUN If "true", only print planned versions (no gh calls). | ||
| # | ||
| # Prerequisites: gh, git; remote `origin` must exist for non dry-run. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| scripts_dir="$(cd "$(dirname "$0")" && pwd)" | ||
| repo_root="$(cd "${scripts_dir}/.." && pwd)" | ||
| cd "${repo_root}" | ||
|
|
||
| functions_input="${MANUAL_PATCH_FUNCTIONS:-}" | ||
| repo="${GITHUB_REPOSITORY:-}" | ||
| sha="${GITHUB_SHA:-}" | ||
| dry_run="${MANUAL_PATCH_DRY_RUN:-false}" | ||
|
|
||
| if [[ -z "$functions_input" ]]; then | ||
| echo "::error::MANUAL_PATCH_FUNCTIONS is not set" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ -z "$repo" ]]; then | ||
| echo "::error::GITHUB_REPOSITORY is not set" >&2 | ||
| exit 1 | ||
| fi | ||
| if [[ -z "$sha" ]]; then | ||
| echo "::error::GITHUB_SHA is not set" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ "$dry_run" != "true" ]] && [[ -z "${GH_TOKEN:-}" ]]; then | ||
| echo "::error::GH_TOKEN is required when not in dry-run (GitHub App installation token or PAT with permission to create releases and tags)" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Same names as FUNCTIONS in functions/go/Makefile (see target list-functions). | ||
| mapfile -t allowed < <(make -s list-functions) | ||
|
|
||
| if [[ ${#allowed[@]} -eq 0 ]]; then | ||
| echo "::error::make list-functions produced no output" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| _trim_space() { | ||
| local s="$1" | ||
| s="${s#"${s%%[![:space:]]*}"}" | ||
| s="${s%"${s##*[![:space:]]}"}" | ||
| printf '%s' "$s" | ||
| } | ||
|
|
||
| is_allowed() { | ||
| local n="$1" | ||
| for a in "${allowed[@]}"; do | ||
| [[ "$n" == "$a" ]] && return 0 | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| outer_trim="$(_trim_space "${functions_input}")" | ||
| declare -a functions=() | ||
| expand_all=0 | ||
|
|
||
| # Bulk mode: every function from `make list-functions`. | ||
| if [[ "${outer_trim,,}" == "all" ]]; then | ||
| expand_all=1 | ||
| functions=("${allowed[@]}") | ||
| else | ||
| # Explicit list: comma-separated names (strict if missing tags). | ||
| IFS=',' read -ra raw_parts <<< "${functions_input}" | ||
| for part in "${raw_parts[@]}"; do | ||
| fn="$(_trim_space "$part")" | ||
| [[ -z "$fn" ]] && continue | ||
| if ! is_allowed "$fn"; then | ||
| echo "::error::Function '$fn' is not in output of: make list-functions" >&2 | ||
| exit 1 | ||
| fi | ||
| functions+=("$fn") | ||
| done | ||
| fi | ||
|
|
||
| mapfile -t functions < <(printf '%s\n' "${functions[@]}" | sort -u) | ||
|
|
||
| if [[ ${#functions[@]} -eq 0 ]]; then | ||
| echo "::error::No function names after parsing MANUAL_PATCH_FUNCTIONS" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| for fn in "${functions[@]}"; do | ||
| echo "===== ${fn} =====" | ||
|
|
||
| # Latest strict SemVer long tag for this function (sort -V orders versions correctly). | ||
| prev_long="$( | ||
| git tag -l "functions/go/${fn}/v*" --sort=v:refname | | ||
| grep -E -- '/v[0-9]+\.[0-9]+\.[0-9]+$' | | ||
| tail -n 1 || true | ||
| )" | ||
|
|
||
| if [[ -z "${prev_long}" ]]; then | ||
| if [[ "${expand_all}" -eq 1 ]]; then | ||
| echo "::notice::Skipping ${fn}: no prior semver tag functions/go/${fn}/vMAJOR.MINOR.PATCH" | ||
| continue | ||
| fi | ||
| echo "::error::No prior semver tag functions/go/${fn}/vMAJOR.MINOR.PATCH; cannot infer next patch." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| ver="${prev_long##*/}" | ||
| v="${ver#v}" | ||
| IFS=. read -r major minor patch <<< "${v}" | ||
| next_ver="v${major}.${minor}.$((patch + 1))" | ||
| long_tag="functions/go/${fn}/${next_ver}" | ||
| release_title="${fn} ${next_ver}" | ||
|
|
||
| echo "Previous: ${prev_long} -> Next: ${long_tag}" | ||
|
|
||
| if [[ "$dry_run" == "true" ]]; then | ||
| echo "(dry_run) would run: gh release create \"${long_tag}\" --repo \"${repo}\" --target \"${sha}\" --title \"${release_title}\" --generate-notes --notes-start-tag \"${prev_long}\"" | ||
| continue | ||
| fi | ||
|
|
||
| if [[ -n "$(git ls-remote origin "refs/tags/${long_tag}")" ]]; then | ||
| echo "::error::Tag ${long_tag} already exists on origin" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| gh release create "${long_tag}" \ | ||
| --repo "${repo}" \ | ||
| --target "${sha}" \ | ||
| --title "${release_title}" \ | ||
| --generate-notes \ | ||
| --notes-start-tag "${prev_long}" | ||
| done | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.