Skip to content

Commit

Permalink
fix(package): Do not trust bash with anything important!
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
acederberg committed Aug 22, 2024
1 parent a65d531 commit c07651b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ jobs:
- name: Verify Ref.
id: release-ref-verify
run: |
github_ref_name='${{ github.event.inputs.release_version }}' || '${{ github.ref_name }}'
python3 ./scripts/validate_ref_name.py $github_ref_name
release_name=$(
python3 ./scripts/validate_ref_name.py \
'${{ github.event.inputs.release_version }}' \
'${{ github.ref_name }}'
)
echo "CAPTURA_RELEASE_NAME=$release_name" >> $GITHUB_ENV
- name: Get Body.
id: release-get-body
Expand Down Expand Up @@ -85,7 +89,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref_name }}
release_name: v${{ github.ref_name }}
release_name: v${{ github.CAPTURA_RELEASE_NAME }}
body: ${{ env.CAPTURA_RELEASE_NOTES }}
draft: false
prerelease: false
Expand Down
18 changes: 15 additions & 3 deletions scripts/validate_ref_name.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
"""Yes, this could be done in bash. But it has been inconsistent.
- First argument should be the override value.
- Second should be the actual value.
"""

# =========================================================================== #
import re
import sys
Expand All @@ -12,9 +18,15 @@

if __name__ == "__main__":

matched = semver.match(github_ref_name := sys.argv[1])
if len(sys.argv) != 3:
print("Not enough arguments.")

_, tag_override, tag = sys.argv
matched = semver.match(github_ref_name := tag_override or tag)

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 }`.")
# NOTE: Should only print this since it is used to determine the release
# name.
print(github_ref_name)

0 comments on commit c07651b

Please sign in to comment.