-
Notifications
You must be signed in to change notification settings - Fork 171
ci: add package.json bumper workflow #1627
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
Open
jescalada
wants to merge
11
commits into
main
Choose a base branch
from
1533-autobump-on-milestone-clean
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+266
−6
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e2bf33b
ci: add package.json bumper workflow
jescalada 74edf28
ci: add release branch bumper workflow
jescalada bf007ef
docs: improve releases.md, add TLDR and link to workflows
jescalada 9be0981
docs: update NPM publish section and remove autobump disclaimer
jescalada d7f8b19
Merge branch 'main' into 1533-autobump-on-milestone-clean
jescalada 348758b
Merge branch '1533-autobump-on-milestone-clean' of https://github.com…
jescalada 57204d1
Merge branch 'main' into 1533-autobump-on-milestone-clean
jescalada c9fdf6b
Merge branch 'main' into 1533-autobump-on-milestone-clean
jescalada d98d9fa
ci: remove invalid job name interpolation
jescalada fe4355b
Merge branch '1533-autobump-on-milestone-clean' of https://github.com…
jescalada 7f52f5c
Merge branch 'main' into 1533-autobump-on-milestone-clean
jescalada 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
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,131 @@ | ||
| name: Bump Patch Version on Release Branch | ||
|
|
||
| # Manually bumps package.json + package-lock.json (root and | ||
| # packages/git-proxy-cli) to the next patch version on existing release | ||
| # branch, and opens a PR against that branch | ||
|
|
||
| # This is needed since patch releases don't have an easy way to trigger the bump | ||
| # and people may forget to bump the versions manually in the patch PR | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| line: | ||
| description: 'Release branch to patch in X.Y format, e.g. 2.0 (targets release/2.0)' | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: patch-bump-${{ inputs.line }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| bump-patch: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Validate release line | ||
| id: line | ||
| env: | ||
| LINE: ${{ inputs.line }} | ||
| run: | | ||
| if [[ ! "$LINE" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
| echo "::error::'$LINE' isn't a release line in X.Y form (expected e.g. '2.0')." | ||
| exit 1 | ||
| fi | ||
| echo "line=$LINE" >> "$GITHUB_OUTPUT" | ||
| echo "branch=release/$LINE" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Checkout release branch | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| ref: ${{ steps.line.outputs.branch }} | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 | ||
| with: | ||
| node-version: '24' | ||
|
|
||
| - name: Confirm both packages exist on this branch | ||
| run: | | ||
| if [ ! -f packages/git-proxy-cli/package.json ]; then | ||
| echo "::error::packages/git-proxy-cli/package.json doesn't exist on this branch. It probably predates the CLI package split, bump this one by hand." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Compute next patch version | ||
| id: version | ||
| env: | ||
| LINE: ${{ steps.line.outputs.line }} | ||
| run: | | ||
| CURRENT=$(node -p "require('./package.json').version") | ||
|
|
||
| if [[ ! "$CURRENT" =~ ^([0-9]+\.[0-9]+)\.([0-9]+)$ ]]; then | ||
| echo "::error::root package.json version '$CURRENT' isn't a plain X.Y.Z, can't compute a patch bump automatically." | ||
| exit 1 | ||
| fi | ||
|
|
||
| CURRENT_LINE="${BASH_REMATCH[1]}" | ||
| PATCH="${BASH_REMATCH[2]}" | ||
|
|
||
| if [ "$CURRENT_LINE" != "$LINE" ]; then | ||
| echo "::error::release/$LINE's package.json is on $CURRENT, which isn't on the $LINE line. Refusing to guess, sort this out by hand first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| VERSION="$CURRENT_LINE.$((PATCH + 1))" | ||
| echo "current=$CURRENT" >> "$GITHUB_OUTPUT" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "Current: $CURRENT -> Next patch: $VERSION" | ||
|
|
||
| - name: Check packages are in sync | ||
| env: | ||
| ROOT_VERSION: ${{ steps.version.outputs.current }} | ||
| run: | | ||
| CLI_VERSION=$(node -p "require('./packages/git-proxy-cli/package.json').version") | ||
| if [ "$CLI_VERSION" != "$ROOT_VERSION" ]; then | ||
| echo "::error::packages/git-proxy-cli is on $CLI_VERSION but root is on $ROOT_VERSION. Versions have already drifted, resolve by hand before bumping." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Bump root package | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: npm version "$VERSION" --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Bump git-proxy-cli package | ||
| working-directory: packages/git-proxy-cli | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: npm version "$VERSION" --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Open patch bump PR | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| CURRENT: ${{ steps.version.outputs.current }} | ||
| BASE_BRANCH: ${{ steps.line.outputs.branch }} | ||
| run: | | ||
| BRANCH="chore/patch-bump-$VERSION" | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout -b "$BRANCH" | ||
| git add package.json package-lock.json packages/git-proxy-cli/package.json packages/git-proxy-cli/package-lock.json | ||
| git commit -m "chore: bump version to $VERSION" | ||
| git push -u origin "$BRANCH" --force | ||
|
|
||
| BODY=$(printf 'Automated patch bump on `%s`: `%s` -> `%s`.\n\nBumps:\n- `package.json` / `package-lock.json`\n- `packages/git-proxy-cli/package.json`\n\nOnce merged, this drafts a release on `%s`. Please publish it immedietaly, otherwise the draft release will get overwritten. Then, cascade-merge it forward into the next supported release branch (bumping that line too) if one exists.\nFor more details see our guide on [How to Publish a Patch Release](https://git-proxy.finos.org/docs/development/releases/#publishing-a-patch-release).\n' "$BASE_BRANCH" "$CURRENT" "$VERSION" "$BASE_BRANCH") | ||
|
|
||
| if gh pr view "$BRANCH" >/dev/null 2>&1; then | ||
| echo "PR for $BRANCH already exists. Branch updated, no new PR opened." | ||
| else | ||
| gh pr create --base "$BASE_BRANCH" --head "$BRANCH" --title "chore: bump version to $VERSION" --body "$BODY" | ||
| fi |
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,110 @@ | ||
| name: Bump Package Version | ||
|
|
||
| # Can be triggered by closing a milestone or manually | ||
| on: | ||
| milestone: | ||
| types: [closed] | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: 'Version to bump to, e.g. 2.2.0' | ||
| required: true | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| concurrency: | ||
| group: version-bump-${{ github.event.milestone.number || github.run_id }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| bump-version-${{ inputs.branch }}: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Harden Runner | ||
| uses: step-security/harden-runner@9af89fc71515a100421586dfdb3dc9c984fbf411 # v2.19.4 | ||
| with: | ||
| egress-policy: audit | ||
|
|
||
| - name: Checkout main | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| ref: main | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6 | ||
| with: | ||
| node-version: '24' | ||
|
|
||
| - name: Resolve version | ||
| id: version | ||
| env: | ||
| MILESTONE_TITLE: ${{ github.event.milestone.title }} | ||
| MANUAL_VERSION: ${{ inputs.version }} | ||
| run: | | ||
| RAW="${MANUAL_VERSION:-$MILESTONE_TITLE}" | ||
| RAW="$(printf '%s' "$RAW" | tr -d '[:space:]')" | ||
|
|
||
| if [[ ! "$RAW" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then | ||
| echo "::error::'$RAW' isn't a plain semver version (for example '2.2.0'). Not bumping." | ||
| exit 1 | ||
| fi | ||
|
|
||
| VERSION="${RAW#v}" | ||
| echo "version=$VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "Resolved version: $VERSION" | ||
|
|
||
| - name: Sanity check against current version | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: | | ||
| CURRENT=$(node -p "require('./package.json').version") | ||
| NEWEST=$(printf '%s\n%s\n' "$CURRENT" "$VERSION" | sort -V | tail -n1) | ||
| if [ "$VERSION" = "$CURRENT" ] || [ "$NEWEST" != "$VERSION" ]; then | ||
| echo "::error::$VERSION is not newer than the current package.json version ($CURRENT)." | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Bump root package | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: npm version "$VERSION" --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Bump git-proxy-cli package | ||
| working-directory: packages/git-proxy-cli | ||
| env: | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| run: npm version "$VERSION" --no-git-tag-version --allow-same-version | ||
|
|
||
| - name: Open version bump PR | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| VERSION: ${{ steps.version.outputs.version }} | ||
| MILESTONE_TITLE: ${{ github.event.milestone.title }} | ||
| MILESTONE_URL: ${{ github.event.milestone.html_url }} | ||
| run: | | ||
| BRANCH="chore/bump-version-$VERSION" | ||
| RELEASE_BRANCH="release/${VERSION%.*}" | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| git checkout -b "$BRANCH" | ||
| git add package.json package-lock.json packages/git-proxy-cli/package.json | ||
| git commit -m "chore: bump git-proxy and git-proxy-cli to $VERSION" | ||
| git push -u origin "$BRANCH" --force | ||
|
|
||
| if [ -n "$MILESTONE_URL" ]; then | ||
| SOURCE_LINE="Triggered by closing milestone **$MILESTONE_TITLE** ($MILESTONE_URL)." | ||
| else | ||
| SOURCE_LINE="Triggered manually for version $VERSION." | ||
| fi | ||
|
|
||
| BODY=$(printf '%s\n\nBumps:\n- `package.json`, `package-lock.json`\n- `packages/git-proxy-cli/package.json`\n\nOnce merged, cut `%s` from `main` per our [release process](https://git-proxy.finos.org/docs/development/releases) in order to generate a GitHub draft release.\n' "$SOURCE_LINE" "$RELEASE_BRANCH") | ||
|
|
||
| if gh pr view "$BRANCH" >/dev/null 2>&1; then | ||
| echo "PR for $BRANCH already exists. Branch updated, no new PR opened." | ||
| else | ||
| gh pr create --base main --head "$BRANCH" --title "chore: bump version to $VERSION" --body "$BODY" | ||
| fi | ||
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
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.