From ad56dc7e2bc31f54d93f6807d3006c8fa002bd7a Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Wed, 12 Jun 2024 10:22:42 -0400 Subject: [PATCH] GHA: Validate release version number There's a reasonable chance this workflow will be triggered by a human (via `workflow_dispatch``), and a non-zero chance with an invalid version number for which a release should not be created. Detect this and provide a way for the operator to debug the source of the error. Also fix some whitespace inconsistencies. Signed-off-by: Chris Evich --- .github/workflows/release-artifacts.yml | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml index 536877c730..d966b846e5 100644 --- a/.github/workflows/release-artifacts.yml +++ b/.github/workflows/release-artifacts.yml @@ -25,15 +25,34 @@ jobs: build: runs-on: ubuntu-22.04 steps: + # If the job fails, these details are all but impossible to observe.yy + - name: Provide github event JSON for examination + run: | + echo "::group::Event JSON" + jq --color-output "." ${{ github.event_path }}"" + echo "::endgroup::" - name: Determine Version id: getversion run: | if [[ -z "${{ inputs.version }}" ]] then - VERSION=${{ github.event.release.tag_name }} + VERSION=${{ github.event.release.tag_name }} else - VERSION=${{ inputs.version }} + VERSION=${{ inputs.version }} fi + + if ! grep -Eq 'v[0-9]+(\.[0-9]+(\.[0-9]+(-.+)?)?)?$' <<<"$VERSION" + then + echo "Unable to parse release version '$VERSION' from github event JSON, or workflow 'version' input." + exit 1 + fi + + if grep -Eq '.+-dev$' <<<"$VERSION" + then + echo "Refusing to process a "-dev" version '$VERSION'" + exit 1 + fi + echo echo "version=$VERSION" >> $GITHUB_OUTPUT