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
This commit is contained in:
Mathias Fredriksson
2023-01-12 17:50:58 +02:00
committed by GitHub
parent 575bfabfcb
commit a5073a8770
3 changed files with 34 additions and 18 deletions

View File

@ -1,5 +1,6 @@
# GitHub release workflow. # GitHub release workflow.
name: Release name: Release
run-name: Release ${{ github.ref_name }}${{ inputs.dry_run && ' (DRYRUN)' || '' }}
on: on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
@ -22,10 +23,6 @@ on:
type: boolean type: boolean
required: true required: true
default: false default: false
snapshot:
description: Force a dev version to be generated, implies dry_run.
type: boolean
default: false
ignore_missing_commit_metadata: ignore_missing_commit_metadata:
description: WARNING! This option disables the requirement that all commits have a PR. Not needed for dry_run. description: WARNING! This option disables the requirement that all commits have a PR. Not needed for dry_run.
type: boolean type: boolean
@ -39,11 +36,17 @@ permissions:
# Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage) # Necessary for GCP authentication (https://github.com/google-github-actions/setup-gcloud#usage)
id-token: write id-token: write
env:
CODER_RELEASE: ${{ !github.event.inputs.snapshot }}
concurrency: ${{ github.workflow }}-${{ github.ref }} concurrency: ${{ github.workflow }}-${{ github.ref }}
env:
# Use `inputs` (vs `github.event.inputs`) to ensure that booleans are actual
# booleans, not strings.
# https://github.blog/changelog/2022-06-10-github-actions-inputs-unified-across-manual-and-reusable-workflows/
CODER_RELEASE: ${{ !inputs.dry_run }}
CODER_RELEASE_INCREMENT: ${{ inputs.increment }}
CODER_RELEASE_DRAFT: ${{ inputs.draft }}
CODER_DRY_RUN: ${{ inputs.dry_run }}
jobs: jobs:
release: release:
name: Create and publish name: Create and publish
@ -52,6 +55,12 @@ jobs:
# Necessary for Docker manifest # Necessary for Docker manifest
DOCKER_CLI_EXPERIMENTAL: "enabled" DOCKER_CLI_EXPERIMENTAL: "enabled"
steps: steps:
- name: Check release on main (or dry-run)
if: ${{ github.ref_name != 'main' && !inputs.dry_run }}
run: |
echo "Release not allowed on ${{ github.ref_name }}, use dry-run."
exit 1
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
@ -76,7 +85,7 @@ jobs:
ref=HEAD ref=HEAD
old_version="$(git describe --abbrev=0 "$ref^1")" old_version="$(git describe --abbrev=0 "$ref^1")"
if [[ "${{ github.event.inputs.ignore_missing_commit_metadata }}" == *t* ]]; then if [[ "${{ inputs.ignore_missing_commit_metadata }}" == *t* ]]; then
export CODER_IGNORE_MISSING_COMMIT_METADATA=1 export CODER_IGNORE_MISSING_COMMIT_METADATA=1
fi fi
@ -87,7 +96,7 @@ jobs:
fi fi
version_args=() version_args=()
if [[ "${{ github.event.inputs.dry_run || github.event.inputs.snapshot }}" == *t* ]]; then if [[ $CODER_DRY_RUN == *t* ]]; then
# Allow dry-run of branches to pass. # Allow dry-run of branches to pass.
export CODER_IGNORE_MISSING_COMMIT_METADATA=1 export CODER_IGNORE_MISSING_COMMIT_METADATA=1
version_args+=(--dry-run) version_args+=(--dry-run)
@ -104,7 +113,7 @@ jobs:
./scripts/release/tag_version.sh \ ./scripts/release/tag_version.sh \
"${version_args[@]}" \ "${version_args[@]}" \
--ref "$ref" \ --ref "$ref" \
--${{ github.event.inputs.increment }} --"$CODER_RELEASE_INCREMENT"
)" )"
# Generate notes. # Generate notes.
@ -232,10 +241,10 @@ jobs:
set -euo pipefail set -euo pipefail
publish_args=() publish_args=()
if [[ "${{ github.event.inputs.draft }}" == *t* ]]; then if [[ $CODER_RELEASE_DRAFT == *t* ]]; then
publish_args+=(--draft) publish_args+=(--draft)
fi fi
if [[ "${{ github.event.inputs.dry_run || github.event.inputs.snapshot }}" == *t* ]]; then if [[ $CODER_DRY_RUN == *t* ]]; then
publish_args+=(--dry-run) publish_args+=(--dry-run)
fi fi
declare -p publish_args declare -p publish_args
@ -263,7 +272,7 @@ jobs:
uses: "google-github-actions/setup-gcloud@v1" uses: "google-github-actions/setup-gcloud@v1"
- name: Publish Helm Chart - name: Publish Helm Chart
if: ${{ !github.event.inputs.dry_run && !github.event.inputs.snapshot }} if: ${{ !inputs.dry_run }}
run: | run: |
set -euo pipefail set -euo pipefail
version="$(./scripts/version.sh)" version="$(./scripts/version.sh)"
@ -274,8 +283,8 @@ jobs:
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2 gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/coder_helm_${version}.tgz gs://helm.coder.com/v2
gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2 gsutil -h "Cache-Control:no-cache,max-age=0" cp build/helm/index.yaml gs://helm.coder.com/v2
- name: Upload artifacts to actions (if dry-run or snapshot) - name: Upload artifacts to actions (if dry-run)
if: ${{ github.event.inputs.dry_run || github.event.inputs.snapshot }} if: ${{ inputs.dry_run }}
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: release-artifacts name: release-artifacts

View File

@ -131,11 +131,18 @@ maybedryrun() {
log "DRYRUN: $*" log "DRYRUN: $*"
else else
shift shift
log $ "$@" logrun "$@"
"$@"
fi fi
} }
# logrun prints the given program and flags, and then executes it.
#
# Usage: logrun gh release create ...
logrun() {
log $ "$*"
"$@"
}
# log prints a message to stderr. # log prints a message to stderr.
log() { log() {
echo "$*" 1>&2 echo "$*" 1>&2

View File

@ -167,7 +167,7 @@ else
fi fi
log log
gh workflow run release.yaml \ logrun gh workflow run release.yaml \
--ref "$branch" \ --ref "$branch" \
-F increment="$increment" \ -F increment="$increment" \
"${args[@]}" "${args[@]}"