Skip to content

Commit

Permalink
fix(package): Ref name validation moved to python since only works lo…
Browse files Browse the repository at this point in the history
…cally.

[skip ci]
  • Loading branch information
acederberg committed Aug 22, 2024
1 parent 2341294 commit 0d3c8f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ jobs:
with:
fetch-depth: 0

- name: Ensure Python is Installed.
uses: actions/setup-python@v4
with:
python-version: '3.11'

# NOTE Check that the ref matches semver.
- name: Verify Ref.
id: release-ref-verify
run: |
github_ref_name='${{ github.event.inputs.release_version }}' || '${{ github.ref_name }}'
if [[ \
! $( \
echo $github_ref_name \
| grep '^\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\(-[a-z0-9]\+\)\?$' \
) \
]]; then
echo 'Illegal git ref name `${{ github.ref_name }}`. Exitting.'
exit 1
else
echo 'Valid git ref name `${{ github.ref_name }}`.'
fi
python3 ./scripts/validate_ref_name.py $github_ref_name
- name: Get Body.
id: release-get-body
Expand Down
20 changes: 20 additions & 0 deletions scripts/validate_ref_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# =========================================================================== #
import re
import sys

semver = re.compile(
"^(?P<major>0|[1-9]\\d*)\\.(?P<minor>0|[1-9]\\d*)\\.(?P<patch>0|[1-9]\\d*)"
"(?:-(?P<prerelease>(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)"
"(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?"
"(?:\\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$"
)


if __name__ == "__main__":

matched = semver.match(github_ref_name := sys.argv[1])
if matched is None:
print(f"Illegal git ref name `{ github_ref_name }`. Exitting.")
sys.exit(1)
else:
print(f"Valid git ref name `{ github_ref_name }`.")

0 comments on commit 0d3c8f4

Please sign in to comment.