Repository navigation
ci(release): Release only green builds, release stranded commits, and drop failed releases #137
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
sentry-junior
wants to merge
7
commits into
main
Choose a base branch
from
ci/self-healing-release
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.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f6caac5
ci(release): Release only green builds and clear stale release branches
sentry-junior[bot] e8f6c8a
ci(release): Release commits that landed while a release was pending
sentry-junior[bot] 9a08083
Merge remote-tracking branch 'origin/main' into ci/self-healing-release
sentry-junior[bot] c24715f
ci(release): Drop a release as soon as its Build fails
sentry-junior[bot] 3c8e84d
ci: Close the pipeline issue only when Release prepares a release
sentry-junior[bot] 4f930a2
ci(release): Trim preflight and the failed-release drop
sentry-junior[bot] f62189b
ci: Treat a gone or moved release branch as nothing to drop
sentry-junior[bot] 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,44 @@ | ||
| #!/bin/sh | ||
| # Drops a release whose Build failed: deletes its release branch, so the next | ||
| # push to main cuts a fresh release instead of failing on "release branch | ||
| # already exists", then tries to close its publish request. | ||
| # | ||
| # Environment: | ||
| # BRANCH Release branch whose Build failed, such as release/1.2.3. | ||
| # SHA Commit that Build ran on. The branch is deleted only while it | ||
| # still points there. | ||
| # RUN_URL The failed Build run. | ||
| # GH_TOKEN Token that can delete branches here, and ideally close issues in | ||
| # the publish repository. | ||
| # GITHUB_REPOSITORY and GITHUB_REPOSITORY_OWNER come from GitHub Actions. | ||
| set -eu | ||
|
|
||
| ref="refs/heads/$BRANCH" | ||
| if ! git push --force-with-lease="$ref:$SHA" origin ":$ref"; then | ||
| # The lease fails when the branch is already gone (a rerun) or has moved on. | ||
| # Either way there is nothing to drop. Any other failure is a real one. | ||
| current=$(git ls-remote origin "$ref") | ||
| case "$current" in | ||
| "$SHA"*) exit 1 ;; | ||
| esac | ||
| printf '::notice::%s no longer points at %s. Nothing to drop.\n' "$BRANCH" "$SHA" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Craft files publish requests in <owner>/publish by default. Closing one is | ||
| # tidying up: an open request whose branch is gone cannot publish anything. | ||
| publish_repo="$GITHUB_REPOSITORY_OWNER/publish" | ||
| title="publish: $GITHUB_REPOSITORY@${BRANCH#release/}" | ||
| comment="Superseded: [Build failed]($RUN_URL) on \`$BRANCH\`, so its branch was deleted. The next push to \`main\` prepares a new release." | ||
| # List open requests instead of searching: search lags behind new issues. | ||
| if ! open_requests=$(gh issue list -R "$publish_repo" --state open --limit 1000 --json number,title); then | ||
| printf '::warning::Could not list publish requests. Close the one for %s by hand.\n' "$BRANCH" | ||
| exit 0 | ||
| fi | ||
| number=$(jq -r --arg t "$title" 'map(select(.title == $t)) | first | .number // empty' <<EOF | ||
| $open_requests | ||
| EOF | ||
| ) | ||
| if [ -n "$number" ] && ! gh issue close "$number" -R "$publish_repo" --comment "$comment"; then | ||
| printf '::warning::Could not close %s#%s. Close it by hand.\n' "$publish_repo" "$number" | ||
| 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
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,36 @@ | ||
| #!/bin/sh | ||
| # Decides whether an automatic Release run cuts a release from HEAD, a commit | ||
| # whose Build passed on main. Writes proceed=true or proceed=false to | ||
| # $GITHUB_OUTPUT. Each skip is a case where `craft prepare` would fail. | ||
| set -eu | ||
|
|
||
| skip() { | ||
| printf '::notice::%s\n' "$1" | ||
| printf 'proceed=false\n' >>"$GITHUB_OUTPUT" | ||
| exit 0 | ||
| } | ||
|
|
||
| # "Release branch already exists". Once that release merges into main, the | ||
| # Release run for the merge commit releases whatever landed meanwhile. | ||
| pending=$(git ls-remote --heads origin 'refs/heads/release/*') | ||
| if [ -n "$pending" ]; then | ||
| skip 'A release is still pending.' | ||
| fi | ||
|
|
||
| # Craft takes the next version from the latest tag in HEAD's history. A newer | ||
| # tag outside it means HEAD predates a release, and craft would cut that | ||
| # version again. | ||
| base=$(git describe --tags --abbrev=0) | ||
| tags=$(git tag --sort=-version:refname) | ||
| newest=${tags%%[[:space:]]*} | ||
| if [ "$newest" != "$base" ]; then | ||
| skip "HEAD predates release $newest." | ||
| fi | ||
|
|
||
| # "No commits found since the last release". Release merges count as released. | ||
| unreleased=$(git rev-list --no-merges "$base..HEAD") | ||
| if [ -z "$unreleased" ]; then | ||
| skip "Nothing to release since $base." | ||
| fi | ||
|
|
||
| printf 'proceed=true\n' >>"$GITHUB_OUTPUT" |
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
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.