Repository navigation
feat(ENG-14534): pin the CLI version and release on each CLI bump #49
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cloudsmith-iduffy
wants to merge
2
commits into
master
Choose a base branch
from
eng-14534-auto-release-cloudsmith-cli-action-on-every-cloudsmith-cli
base: master
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.
Open
Changes from all commits
Commits
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
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
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,62 @@ | ||
| #!/usr/bin/env bash | ||
|
cloudsmith-iduffy marked this conversation as resolved.
|
||
| # Pins the default cli-version in action.yml to a new Cloudsmith CLI release | ||
| # and records the change as a release of the action in CHANGELOG.md. The | ||
| # release is a patch release, or a minor release that also includes the | ||
| # entries under [Unreleased] when there are any. | ||
| # Prints the new action version. Prints nothing when action.yml already pins | ||
| # that version or a newer one. | ||
| # Usage: scripts/bump-cli-version.sh CLI_VERSION | ||
| set -euo pipefail | ||
|
|
||
| cli_version="${1:-}" | ||
| [[ "$cli_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] \ | ||
| || { echo "usage: $0 MAJOR.MINOR.PATCH" >&2; exit 1; } | ||
|
|
||
| pinned_version="$(awk ' | ||
| /^ cli-version:/ { in_cli_version = 1 } | ||
| in_cli_version && /^ default:/ { gsub(/"/, "", $2); print $2; exit } | ||
| ' action.yml)" | ||
| [[ -n "$pinned_version" ]] || { echo "no cli-version default in action.yml" >&2; exit 1; } | ||
| newest_version="$(printf '%s\n' "$pinned_version" "$cli_version" | sort -V | tail -n 1)" | ||
| if [[ "$pinned_version" == "$newest_version" ]]; then | ||
| echo "action.yml already pins Cloudsmith CLI $pinned_version" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| released_version="$(sed -n 's/^## \[\([0-9]*\.[0-9]*\.[0-9]*\)\].*/\1/p' CHANGELOG.md | head -n 1)" | ||
| [[ -n "$released_version" ]] || { echo "no released version in CHANGELOG.md" >&2; exit 1; } | ||
| unreleased_changes="$(awk ' | ||
| /^## \[/ { in_unreleased = ($0 == "## [Unreleased]"); next } | ||
| in_unreleased && $0 != "" && $0 != "---" | ||
| ' CHANGELOG.md)" | ||
| IFS=. read -r major minor patch <<< "$released_version" | ||
| if [[ -n "$unreleased_changes" ]]; then | ||
| action_version="$major.$(( minor + 1 )).0" | ||
| else | ||
| action_version="$major.$minor.$(( patch + 1 ))" | ||
| fi | ||
|
|
||
| awk -v cli_version="$cli_version" ' | ||
| /^ cli-version:/ { in_cli_version = 1 } | ||
| in_cli_version && /^ default:/ { sub(/".*"/, "\"" cli_version "\""); in_cli_version = 0 } | ||
| { print } | ||
| ' action.yml > action.yml.new | ||
| mv action.yml.new action.yml | ||
|
|
||
| awk -v action_version="$action_version" -v cli_version="$cli_version" -v today="$(date -u +%Y-%m-%d)" ' | ||
| inserted && $0 != "" { print "" } | ||
| { inserted = 0; print } | ||
| previous == "## [Unreleased]" && $0 == "---" { | ||
| inserted = 1 | ||
| print "" | ||
| print "## [" action_version "] - " today | ||
| print "---" | ||
| print "### Changed" | ||
| print "" | ||
| print "- Pin the default `cli-version` to Cloudsmith CLI " cli_version "." | ||
| } | ||
| { previous = $0 } | ||
| ' CHANGELOG.md > CHANGELOG.md.new | ||
| mv CHANGELOG.md.new CHANGELOG.md | ||
|
|
||
| echo "$action_version" | ||
Oops, something went wrong.
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.