11# GitHub release workflow.
22name : Release
3+ run-name : Release ${{ github.ref_name }}${{ inputs.dry_run && ' (DRYRUN)' || '' }}
34on :
45 workflow_dispatch :
56 inputs :
2223 type : boolean
2324 required : true
2425 default : false
25- snapshot :
26- description : Force a dev version to be generated, implies dry_run.
27- type : boolean
28- default : false
2926 ignore_missing_commit_metadata :
3027 description : WARNING! This option disables the requirement that all commits have a PR. Not needed for dry_run.
3128 type : boolean
@@ -39,11 +36,17 @@ permissions:
3936 # Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
4037 id-token : write
4138
42- env :
43- CODER_RELEASE : ${{ !github.event.inputs.snapshot }}
44-
4539concurrency : ${{ github.workflow }}-${{ github.ref }}
4640
41+ env :
42+ # Use `inputs` (vs `github.event.inputs`) to ensure that booleans are actual
43+ # booleans, not strings.
44+ # https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
45+ CODER_RELEASE : ${{ !inputs.dry_run }}
46+ CODER_RELEASE_INCREMENT : ${{ inputs.increment }}
47+ CODER_RELEASE_DRAFT : ${{ inputs.draft }}
48+ CODER_DRY_RUN : ${{ inputs.dry_run }}
49+
4750jobs :
4851 release :
4952 name : Create and publish
5255 # Necessary for Docker manifest
5356 DOCKER_CLI_EXPERIMENTAL : " enabled"
5457 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+
5564 - uses : actions/checkout@v3
5665 with :
5766 fetch-depth : 0
7685 ref=HEAD
7786 old_version="$(git describe --abbrev=0 "$ref^1")"
7887
79- if [[ "${{ github.event. inputs.ignore_missing_commit_metadata }}" == *t* ]]; then
88+ if [[ "${{ inputs.ignore_missing_commit_metadata }}" == *t* ]]; then
8089 export CODER_IGNORE_MISSING_COMMIT_METADATA=1
8190 fi
8291
8796 fi
8897
8998 version_args=()
90- if [[ "${{ github.event.inputs.dry_run || github.event.inputs.snapshot }}" == *t* ]]; then
99+ if [[ $CODER_DRY_RUN == *t* ]]; then
91100 # Allow dry-run of branches to pass.
92101 export CODER_IGNORE_MISSING_COMMIT_METADATA=1
93102 version_args+=(--dry-run)
@@ -104,7 +113,7 @@ jobs:
104113 ./scripts/release/tag_version.sh \
105114 "${version_args[@]}" \
106115 --ref "$ref" \
107- --${{ github.event.inputs.increment }}
116+ --"$CODER_RELEASE_INCREMENT"
108117 )"
109118
110119 # Generate notes.
@@ -232,10 +241,10 @@ jobs:
232241 set -euo pipefail
233242
234243 publish_args=()
235- if [[ "${{ github.event.inputs.draft }}" == *t* ]]; then
244+ if [[ $CODER_RELEASE_DRAFT == *t* ]]; then
236245 publish_args+=(--draft)
237246 fi
238- if [[ "${{ github.event.inputs.dry_run || github.event.inputs.snapshot }}" == *t* ]]; then
247+ if [[ $CODER_DRY_RUN == *t* ]]; then
239248 publish_args+=(--dry-run)
240249 fi
241250 declare -p publish_args
@@ -263,7 +272,7 @@ jobs:
263272 uses : " google-github-actions/setup-gcloud@v1"
264273
265274 - name : Publish Helm Chart
266- if : ${{ !github.event. inputs.dry_run && !github.event.inputs.snapshot }}
275+ if : ${{ !inputs.dry_run }}
267276 run : |
268277 set -euo pipefail
269278 version="$(./scripts/version.sh)"
@@ -274,8 +283,8 @@ jobs:
274283 gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2
275284 gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2
276285
277- - name : Upload artifacts to actions (if dry-run or snapshot )
278- if : ${{ github.event. inputs.dry_run || github.event.inputs.snapshot }}
286+ - name : Upload artifacts to actions (if dry-run)
287+ if : ${{ inputs.dry_run }}
279288 uses : actions/upload-artifact@v2
280289 with :
281290 name : release-artifacts
0 commit comments