Skip to content

Commit e821b98

Browse files
authored
ci: Revert to local tag creation and push for releases (#5714)
1 parent 0cf7138 commit e821b98

File tree

5 files changed

+58
-165
lines changed

5 files changed

+58
-165
lines changed

.github/workflows/release.yaml

+12-73
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
# GitHub release workflow.
22
name: Release
3-
run-name: Release ${{ github.ref_name }}${{ inputs.dry_run && ' (DRYRUN)' || '' }}
43
on:
4+
push:
5+
tags:
6+
- "v*"
57
workflow_dispatch:
68
inputs:
7-
increment:
8-
description: Preferred version increment (release script may promote e.g. patch to minor depending on changes).
9-
type: choice
10-
required: true
11-
default: patch
12-
options:
13-
- patch
14-
- minor
15-
- major
16-
draft:
17-
description: Create a draft release (for manually editing release notes before publishing).
18-
type: boolean
19-
required: true
20-
default: false
219
dry_run:
22-
description: Perform a dry-run release.
10+
description: Perform a dry-run release (devel). Note that ref must be an annotated tag when run without dry-run.
2311
type: boolean
2412
required: true
2513
default: false
26-
ignore_missing_commit_metadata:
27-
description: WARNING! This option disables the requirement that all commits have a PR. Not needed for dry_run.
28-
type: boolean
29-
default: false
3014

3115
permissions:
3216
# Required to publish a release
@@ -43,29 +27,19 @@ env:
4327
# booleans, not strings.
4428
# https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
4529
CODER_RELEASE: ${{ !inputs.dry_run }}
46-
CODER_RELEASE_INCREMENT: ${{ inputs.increment }}
47-
CODER_RELEASE_DRAFT: ${{ inputs.draft }}
4830
CODER_DRY_RUN: ${{ inputs.dry_run }}
4931

5032
jobs:
5133
release:
52-
name: Create and publish
34+
name: Build and publish
5335
runs-on: ${{ github.repository_owner == 'coder' && 'ubuntu-latest-16-cores' || 'ubuntu-latest' }}
5436
env:
5537
# Necessary for Docker manifest
5638
DOCKER_CLI_EXPERIMENTAL: "enabled"
5739
steps:
58-
- name: Check release on main (or dry-run)
59-
if: ${{ github.ref_name != 'main' && !inputs.dry_run }}
60-
run: |
61-
echo "Release not allowed on ${{ github.ref_name }}, use dry-run."
62-
exit 1
63-
6440
- uses: actions/checkout@v3
6541
with:
6642
fetch-depth: 0
67-
# Set token for pushing protected tag (vX.X.X).
68-
token: ${{ secrets.RELEASE_GITHUB_PAT }}
6943

7044
# If the event that triggered the build was an annotated tag (which our
7145
# tags are supposed to be), actions/checkout has a bug where the tag in
@@ -75,55 +49,23 @@ jobs:
7549
- name: Fetch git tags
7650
run: git fetch --tags --force
7751

78-
# Configure git user name/email for creating annotated version tag.
79-
- name: Setup git config
80-
run: |
81-
git config user.name "Coder CI"
82-
git config user.email "dean+cdrci@coder.com"
83-
84-
- name: Create release tag and release notes
52+
- name: Create release notes
53+
env:
54+
# We always have to set this since there might be commits on
55+
# main that didn't have a PR.
56+
CODER_IGNORE_MISSING_COMMIT_METADATA: "1"
8557
run: |
8658
set -euo pipefail
8759
ref=HEAD
8860
old_version="$(git describe --abbrev=0 "$ref^1")"
89-
90-
if [[ "${{ inputs.ignore_missing_commit_metadata }}" == *t* ]]; then
91-
export CODER_IGNORE_MISSING_COMMIT_METADATA=1
92-
fi
93-
94-
# Warn if CODER_IGNORE_MISSING_COMMIT_METADATA is set any other way
95-
# than via dry-run.
96-
if [[ ${CODER_IGNORE_MISSING_COMMIT_METADATA:-0} != 0 ]]; then
97-
echo "WARNING: CODER_IGNORE_MISSING_COMMIT_METADATA is enabled and we will ignore missing commit metadata." 1>&2
98-
fi
99-
100-
version_args=()
101-
if [[ $CODER_DRY_RUN == *t* ]]; then
102-
# Allow dry-run of branches to pass.
103-
export CODER_IGNORE_MISSING_COMMIT_METADATA=1
104-
version_args+=(--dry-run)
105-
fi
106-
107-
# Cache commit metadata.
108-
. ./scripts/release/check_commit_metadata.sh "$old_version" "$ref"
109-
110-
declare -p version_args
111-
112-
# Create new release tag (note that this tag is not pushed before
113-
# release.sh is run).
114-
version="$(
115-
./scripts/release/tag_version.sh \
116-
"${version_args[@]}" \
117-
--ref "$ref" \
118-
--"$CODER_RELEASE_INCREMENT"
119-
)"
61+
version="$(./scripts/version.sh)"
12062
12163
# Generate notes.
12264
release_notes_file="$(mktemp -t release_notes.XXXXXX)"
12365
./scripts/release/generate_release_notes.sh --old-version "$old_version" --new-version "$version" --ref "$ref" >> "$release_notes_file"
12466
echo CODER_RELEASE_NOTES_FILE="$release_notes_file" >> $GITHUB_ENV
12567
126-
- name: Echo release notes
68+
- name: Show release notes
12769
run: |
12870
set -euo pipefail
12971
cat "$CODER_RELEASE_NOTES_FILE"
@@ -243,9 +185,6 @@ jobs:
243185
set -euo pipefail
244186
245187
publish_args=()
246-
if [[ $CODER_RELEASE_DRAFT == *t* ]]; then
247-
publish_args+=(--draft)
248-
fi
249188
if [[ $CODER_DRY_RUN == *t* ]]; then
250189
publish_args+=(--dry-run)
251190
fi

scripts/release.sh

+24-58
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ cdroot
77

88
usage() {
99
cat <<EOH
10-
Usage: ./release.sh [--branch <name>] [--draft] [--dry-run] [--ref <ref>] [--major | --minor | --patch]
10+
Usage: ./release.sh [--dry-run] [--ref <ref>] [--major | --minor | --patch]
1111
1212
This script should be called to create a new release.
1313
@@ -23,47 +23,24 @@ be tagged at, otherwise the latest commit will be used.
2323
Set --minor to force a minor version bump, even when there are no breaking
2424
changes. Likewise for --major. By default a patch version will be created.
2525
26-
Set --dry-run to run the release workflow in CI as a dry-run (no release will
27-
be created).
26+
Set --dry-run to see what this script would do without making actual changes.
2827
2928
To mark a release as containing breaking changes, the commit title should
3029
either contain a known prefix with an exclamation mark ("feat!:",
3130
"feat(api)!:") or the PR that was merged can be tagged with the
3231
"release/breaking" label.
33-
34-
To test changes to this script, you can set --branch <my-branch>, which will
35-
run the release workflow in CI as a dry-run and use the latest commit on the
36-
specified branch as the release commit. This will also set --dry-run.
3732
EOH
3833
}
3934

40-
# Warn if CODER_IGNORE_MISSING_COMMIT_METADATA is set any other way than via
41-
# --branch.
42-
if [[ ${CODER_IGNORE_MISSING_COMMIT_METADATA:-0} != 0 ]]; then
43-
log "WARNING: CODER_IGNORE_MISSING_COMMIT_METADATA is enabled externally, we will ignore missing commit metadata."
44-
fi
45-
4635
branch=main
47-
draft=0
4836
dry_run=0
4937
ref=
5038
increment=
5139

52-
args="$(getopt -o h -l branch:,draft,dry-run,help,ref:,major,minor,patch -- "$@")"
40+
args="$(getopt -o h -l dry-run,help,ref:,major,minor,patch -- "$@")"
5341
eval set -- "$args"
5442
while true; do
5543
case "$1" in
56-
--branch)
57-
branch="$2"
58-
log "Using branch $branch, implies DRYRUN and CODER_IGNORE_MISSING_COMMIT_METADATA."
59-
dry_run=1
60-
export CODER_IGNORE_MISSING_COMMIT_METADATA=1
61-
shift 2
62-
;;
63-
--draft)
64-
draft=1
65-
shift
66-
;;
6744
--dry-run)
6845
dry_run=1
6946
shift
@@ -115,64 +92,53 @@ fi
11592

11693
# Check the current version tag from GitHub (by number) using the API to
11794
# ensure no local tags are considered.
95+
log "Checking GitHub for latest release..."
11896
mapfile -t versions < <(gh api -H "Accept: application/vnd.github+json" /repos/coder/coder/git/refs/tags -q '.[].ref | split("/") | .[2]' | grep '^v' | sort -r -V)
11997
old_version=${versions[0]}
98+
log "Latest release: $old_version"
99+
log
120100

121101
trap 'log "Check commit metadata failed, you can try to set \"export CODER_IGNORE_MISSING_COMMIT_METADATA=1\" and try again, if you know what you are doing."' EXIT
122102
# shellcheck source=scripts/release/check_commit_metadata.sh
123103
source "$SCRIPT_DIR/release/check_commit_metadata.sh" "$old_version" "$ref"
124104
trap - EXIT
125105

126-
new_version="$(execrelative ./release/tag_version.sh --dry-run --ref "$ref" --"$increment")"
106+
log "Executing DRYRUN of release tagging..."
107+
new_version="$(execrelative ./release/tag_version.sh --old-version "$old_version" --ref "$ref" --"$increment" --dry-run)"
108+
log
109+
read -p "Continue? (y/n) " -n 1 -r continue_release
110+
log
111+
if ! [[ $continue_release =~ ^[Yy]$ ]]; then
112+
exit 0
113+
fi
114+
127115
release_notes="$(execrelative ./release/generate_release_notes.sh --old-version "$old_version" --new-version "$new_version" --ref "$ref")"
128116

129-
log
130117
read -p "Preview release notes? (y/n) " -n 1 -r show_reply
131118
log
132119
if [[ $show_reply =~ ^[Yy]$ ]]; then
120+
log
133121
echo -e "$release_notes\n"
134122
fi
135123

136-
create_message="Create release"
137-
if ((draft)); then
138-
create_message="Create draft release"
139-
fi
140-
if ((dry_run)); then
141-
create_message+=" (DRYRUN)"
142-
fi
143-
read -p "$create_message? (y/n) " -n 1 -r create
124+
read -p "Create release? (y/n) " -n 1 -r create
144125
log
145126
if ! [[ $create =~ ^[Yy]$ ]]; then
146127
exit 0
147128
fi
148129

149-
args=()
130+
log
131+
# Run without dry-run to actually create the tag, note we don't update the
132+
# new_version variable here to ensure we're pushing what we showed before.
133+
maybedryrun "$dry_run" execrelative ./release/tag_version.sh --old-version "$old_version" --ref "$ref" --"$increment" >/dev/null
134+
maybedryrun "$dry_run" git push --tags -u origin "$new_version"
150135

151-
# Draft and dry-run are required args.
152-
if ((draft)); then
153-
args+=(-F draft=true)
154-
else
155-
args+=(-F draft=false)
156-
fi
157136
if ((dry_run)); then
158-
args+=(-F dry_run=true)
159-
else
160-
args+=(-F dry_run=false)
161-
162-
# We only set this on non-dry-run releases because it will show a
163-
# warning in CI.
164-
if [[ ${CODER_IGNORE_MISSING_COMMIT_METADATA:-0} == 1 ]]; then
165-
args+=(-F ignore_missing_commit_metadata=true)
166-
fi
137+
# We can't watch the release.yaml workflow if we're in dry-run mode.
138+
exit 0
167139
fi
168140

169141
log
170-
logrun gh workflow run release.yaml \
171-
--ref "$branch" \
172-
-F increment="$increment" \
173-
"${args[@]}"
174-
log
175-
176142
read -p "Watch release? (y/n) " -n 1 -r watch
177143
log
178144
if ! [[ $watch =~ ^[Yy]$ ]]; then

scripts/release/check_commit_metadata.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ main() {
9191
commit_sha_long=${parts[1]}
9292
commit_prefix=${parts[2]}
9393

94-
if [[ $ignore_missing_metadata != 1 ]]; then
95-
# Safety-check, guarantee all commits had their metadata fetched.
96-
if [[ ! -v labels[$commit_sha_long] ]]; then
94+
# Safety-check, guarantee all commits had their metadata fetched.
95+
if [[ ! -v labels[$commit_sha_long] ]]; then
96+
if [[ $ignore_missing_metadata != 1 ]]; then
9797
error "Metadata missing for commit $commit_sha_short"
98+
else
99+
log "WARNING: Metadata missing for commit $commit_sha_short"
98100
fi
99101
fi
100102

scripts/release/publish.sh

+1-15
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ fi
3535

3636
version=""
3737
release_notes_file=""
38-
draft=0
3938
dry_run=0
4039

41-
args="$(getopt -o "" -l version:,release-notes-file:,draft,dry-run -- "$@")"
40+
args="$(getopt -o "" -l version:,release-notes-file:,dry-run -- "$@")"
4241
eval set -- "$args"
4342
while true; do
4443
case "$1" in
@@ -50,10 +49,6 @@ while true; do
5049
release_notes_file="$2"
5150
shift 2
5251
;;
53-
--draft)
54-
draft=1
55-
shift
56-
;;
5752
--dry-run)
5853
dry_run=1
5954
shift
@@ -134,20 +129,11 @@ popd
134129
log
135130
log
136131

137-
log "Pushing git tag"
138-
maybedryrun "$dry_run" git push --quiet origin "$new_tag"
139-
140-
args=()
141-
if ((draft)); then
142-
args+=(--draft)
143-
fi
144-
145132
# We pipe `true` into `gh` so that it never tries to be interactive.
146133
true |
147134
maybedryrun "$dry_run" gh release create \
148135
--title "$new_tag" \
149136
--notes-file "$release_notes_file" \
150-
"${args[@]}" \
151137
"$new_tag" \
152138
"$temp_dir"/*
153139

0 commit comments

Comments
 (0)