Skip to content

chore(scripts): auto create autoversion PR from release script #13074

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
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
49 changes: 48 additions & 1 deletion scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ script_check=1
mainline=1
channel=mainline

# These values will be used for any PRs created.
pr_review_assignee=${CODER_RELEASE_PR_REVIEW_ASSIGNEE:-@me}
pr_review_reviewer=${CODER_RELEASE_PR_REVIEW_REVIEWER:-bpmct,stirby}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe add yourself as reviewer too in case of emergency

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t want to involve myself too much in the process, since this is just docs changes I don’t think I’m needed. I will cooperate with @stirby during the next release(s) to ensure the process is smooth.


args="$(getopt -o h -l dry-run,help,ref:,mainline,stable,major,minor,patch,force,ignore-script-out-of-date -- "$@")"
eval set -- "$args"
while true; do
Expand Down Expand Up @@ -294,7 +298,7 @@ log "Release tags for ${new_version} created successfully and pushed to ${remote

log
# Write to a tmp file for ease of debugging.
release_json_file=$(mktemp -t coder-release.json)
release_json_file=$(mktemp -t coder-release.json.XXXXXX)
log "Writing release JSON to ${release_json_file}"
jq -n \
--argjson dry_run "${dry_run}" \
Expand All @@ -310,6 +314,49 @@ maybedryrun "${dry_run}" cat "${release_json_file}" |
log
log "Release workflow started successfully!"

log
log "Would you like for me to create a pull request for you to automatically bump the version numbers in the docs?"
while [[ ! ${create_pr:-} =~ ^[YyNn]$ ]]; do
read -p "Create PR? (y/n) " -n 1 -r create_pr
log
done
if [[ ${create_pr} =~ ^[Yy]$ ]]; then
pr_branch=autoversion/${new_version}
title="docs: bump ${channel} version to ${new_version}"
body="This PR was automatically created by the [release script](https://github.com/coder/coder/blob/main/scripts/release.sh).

Please review the changes and merge if they look good and the release is complete.

You can follow the release progress [here](https://github.com/coder/coder/actions/workflows/release.yaml) and view the published release [here](https://github.com/coder/coder/releases/tag/${new_version}) (once complete)."

log
log "Creating branch \"${pr_branch}\" and updating versions..."

create_pr_stash=0
if ! git diff --quiet --exit-code -- docs; then
maybedryrun "${dry_run}" git stash push --message "scripts/release.sh: autostash (autoversion)" -- docs
create_pr_stash=1
fi
maybedryrun "${dry_run}" git checkout -b "${pr_branch}" "${remote}/${branch}"
execrelative go run ./release autoversion --channel "${channel}" "${new_version}" --dry-run
maybedryrun "${dry_run}" git add docs
maybedryrun "${dry_run}" git commit -m "${title}"
# Return to previous branch.
maybedryrun "${dry_run}" git checkout -
if ((create_pr_stash)); then
maybedryrun "${dry_run}" git stash pop
fi

log "Creating pull request..."
maybedryrun "${dry_run}" gh pr create \
--assignee "${pr_review_assignee}" \
--reviewer "${pr_review_reviewer}" \
--base "${branch}" \
--head "${pr_branch}" \
--title "${title}" \
--body "${body}"
fi

if ((dry_run)); then
# We can't watch the release.yaml workflow if we're in dry-run mode.
exit 0
Expand Down
16 changes: 11 additions & 5 deletions scripts/release/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,18 @@ func (r *releaseCommand) autoversionFile(ctx context.Context, file, channel, ver
}
}
if matchRe != nil {
// Apply matchRe and find the group named "version", then replace it with the new version.
// Utilize the index where the match was found to replace the correct part. The only
// match group is the version.
// Apply matchRe and find the group named "version", then replace it
// with the new version.
if match := matchRe.FindStringSubmatchIndex(line); match != nil {
logger.Info(ctx, "updating version number", "line_number", i+1, "match", match)
lines[i] = line[:match[2]] + version + line[match[3]:]
vg := matchRe.SubexpIndex("version")
if vg == -1 {
logger.Error(ctx, "version group not found in match", "num_subexp", matchRe.NumSubexp(), "subexp_names", matchRe.SubexpNames(), "match", match)
return xerrors.Errorf("bug: version group not found in match")
}
start := match[vg*2]
end := match[vg*2+1]
logger.Info(ctx, "updating version number", "line_number", i+1, "match_start", start, "match_end", end, "old_version", line[start:end])
lines[i] = line[:start] + version + line[end:]
matchRe = nil
break
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/release/tag_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fi

# Ensure the ref is in the release branch.
branch_contains_ref=$(git branch --contains "${ref}" --list "${release_branch}" --format='%(refname)')
if [[ -z $branch_contains_ref ]]; then
if ((!dry_run)) && [[ -z $branch_contains_ref ]]; then
error "Provided ref (${ref_name}) is not in the required release branch (${release_branch})."
fi

Expand Down
14 changes: 14 additions & 0 deletions scripts/release/testdata/autoversion/docs/random.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Some documentation
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to commit this test case in a previous PR.


1. Run the following command to install the chart in your cluster.

For the **mainline** Coder release:

<!-- autoversion(mainline): "--version [version] # trailing comment!" -->

```shell
helm install coder coder-v2/coder \
--namespace coder \
--values values.yaml \
--version 2.10.0 # trailing comment!
```
14 changes: 14 additions & 0 deletions scripts/release/testdata/autoversion/docs/random.md.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Some documentation

1. Run the following command to install the chart in your cluster.

For the **mainline** Coder release:

<!-- autoversion(mainline): "--version [version] # trailing comment!" -->

```shell
helm install coder coder-v2/coder \
--namespace coder \
--values values.yaml \
--version 2.11.1 # trailing comment!
```
Loading