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 <cevich@redhat.com>
This commit is contained in:
Chris Evich
2024-06-12 10:22:42 -04:00
parent 00bcd9aa81
commit ad56dc7e2b

View File

@ -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