Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5073a8

Browse files
authored
ci: Fix release workflow input booleans, remove snapshot (#5688)
* s/github.event.inputs/inputs/g * Add run name and prevent non-dry-run releases on non-main branches * Add logrun to lib.sh
1 parent 575bfab commit a5073a8

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

.github/workflows/release.yaml

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# GitHub release workflow.
22
name: Release
3+
run-name: Release ${{ github.ref_name }}${{ inputs.dry_run && ' (DRYRUN)' || '' }}
34
on:
45
workflow_dispatch:
56
inputs:
@@ -22,10 +23,6 @@ on:
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-
4539
concurrency: ${{ 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+
4750
jobs:
4851
release:
4952
name: Create and publish
@@ -52,6 +55,12 @@ jobs:
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
@@ -76,7 +85,7 @@ jobs:
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
@@ -87,7 +96,7 @@ jobs:
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

scripts/lib.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,18 @@ maybedryrun() {
131131
log "DRYRUN: $*"
132132
else
133133
shift
134-
log $ "$@"
135-
"$@"
134+
logrun "$@"
136135
fi
137136
}
138137

138+
# logrun prints the given program and flags, and then executes it.
139+
#
140+
# Usage: logrun gh release create ...
141+
logrun() {
142+
log $ "$*"
143+
"$@"
144+
}
145+
139146
# log prints a message to stderr.
140147
log() {
141148
echo "$*" 1>&2

scripts/release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ else
167167
fi
168168

169169
log
170-
gh workflow run release.yaml \
170+
logrun gh workflow run release.yaml \
171171
--ref "$branch" \
172172
-F increment="$increment" \
173173
"${args[@]}"

0 commit comments

Comments
 (0)