|
1 | 1 | # GitHub release workflow.
|
2 | 2 | name: Release
|
3 | 3 | on:
|
4 |
| - push: |
5 |
| - tags: |
6 |
| - - "v*" |
7 | 4 | workflow_dispatch:
|
8 | 5 | inputs:
|
| 6 | + release_channel: |
| 7 | + type: choice |
| 8 | + description: Release channel |
| 9 | + options: |
| 10 | + - mainline |
| 11 | + - stable |
| 12 | + release_notes: |
| 13 | + description: Release notes for the publishing the release. This is required to create a release. |
9 | 14 | dry_run:
|
10 | 15 | description: Perform a dry-run release (devel). Note that ref must be an annotated tag when run without dry-run.
|
11 | 16 | type: boolean
|
|
28 | 33 | # https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
|
29 | 34 | CODER_RELEASE: ${{ !inputs.dry_run }}
|
30 | 35 | CODER_DRY_RUN: ${{ inputs.dry_run }}
|
| 36 | + CODER_RELEASE_CHANNEL: ${{ inputs.release_channel }} |
| 37 | + CODER_RELEASE_NOTES: ${{ inputs.release_notes }} |
31 | 38 |
|
32 | 39 | jobs:
|
33 | 40 | release:
|
@@ -62,21 +69,45 @@ jobs:
|
62 | 69 | echo "CODER_FORCE_VERSION=$version" >> $GITHUB_ENV
|
63 | 70 | echo "$version"
|
64 | 71 |
|
65 |
| - - name: Create release notes |
66 |
| - env: |
67 |
| - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
68 |
| - # We always have to set this since there might be commits on |
69 |
| - # main that didn't have a PR. |
70 |
| - CODER_IGNORE_MISSING_COMMIT_METADATA: "1" |
| 72 | + # Verify that all expectations for a release are met. |
| 73 | + - name: Verify release input |
| 74 | + if: ${{ !inputs.dry_run }} |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | +
|
| 78 | + if [[ "${GITHUB_REF}" != "refs/tags/v"* ]]; then |
| 79 | + echo "Ref must be a semver tag when creating a release, did you use scripts/release.sh?" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + # 2.10.2 -> release/2.10 |
| 84 | + version="$(./scripts/version.sh)" |
| 85 | + release_branch=release/${version%.*} |
| 86 | + branch_contains_tag=$(git branch --remotes --contains "${GITHUB_REF}" --list "*/${release_branch}" --format='%(refname)') |
| 87 | + if [[ -z "${branch_contains_tag}" ]]; then |
| 88 | + echo "Ref tag must exist in a branch named ${release_branch} when creating a release, did you use scripts/release.sh?" |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | +
|
| 92 | + if [[ -z "${CODER_RELEASE_NOTES}" ]]; then |
| 93 | + echo "Release notes are required to create a release, did you use scripts/release.sh?" |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + echo "Release inputs verified:" |
| 98 | + echo |
| 99 | + echo "- Ref: ${GITHUB_REF}" |
| 100 | + echo "- Version: ${version}" |
| 101 | + echo "- Release channel: ${CODER_RELEASE_CHANNEL}" |
| 102 | + echo "- Release branch: ${release_branch}" |
| 103 | + echo "- Release notes: true" |
| 104 | +
|
| 105 | + - name: Create release notes file |
71 | 106 | run: |
|
72 | 107 | set -euo pipefail
|
73 |
| - ref=HEAD |
74 |
| - old_version="$(git describe --abbrev=0 "$ref^1")" |
75 |
| - version="v$(./scripts/version.sh)" |
76 | 108 |
|
77 |
| - # Generate notes. |
78 | 109 | release_notes_file="$(mktemp -t release_notes.XXXXXX)"
|
79 |
| - ./scripts/release/generate_release_notes.sh --check-for-changelog --old-version "$old_version" --new-version "$version" --ref "$ref" >> "$release_notes_file" |
| 110 | + echo "$CODER_RELEASE_NOTES" > "$release_notes_file" |
80 | 111 | echo CODER_RELEASE_NOTES_FILE="$release_notes_file" >> $GITHUB_ENV
|
81 | 112 |
|
82 | 113 | - name: Show release notes
|
@@ -265,6 +296,9 @@ jobs:
|
265 | 296 | set -euo pipefail
|
266 | 297 |
|
267 | 298 | publish_args=()
|
| 299 | + if [[ $CODER_RELEASE_CHANNEL == "stable" ]]; then |
| 300 | + publish_args+=(--stable) |
| 301 | + fi |
268 | 302 | if [[ $CODER_DRY_RUN == *t* ]]; then
|
269 | 303 | publish_args+=(--dry-run)
|
270 | 304 | fi
|
|
0 commit comments