Skip to content

fix(pyclient ci): validate version arg in create-release #1473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
versionName:
description: 'Semantic Version Number (i.e., 5.5.0 or patch, minor, major, prepatch, preminor, premajor, prerelease)'
description: 'Semantic Version Number (i.e., 5.5.0 or patch, minor, major)'
required: true
default: patch

Expand All @@ -27,10 +27,28 @@ jobs:
python-version: 3.8
- name: Change version number
id: version
# See this issue for explanation and testing:
# https://github.com/cmu-delphi/delphi-epidata/pull/1473
run: |
python -m pip install bump2version
echo -n "::set-output name=next_tag::"
bump2version --list ${{ github.event.inputs.versionName }} | grep new_version | sed -r s,"^.*=",,
allowed_pattern="^(major|minor|patch|[0-9]+\.[0-9]+\.[0-9]+)$"

if [[ ! ${{ github.event.inputs.versionName }} =~ $allowed_pattern ]]; then
echo "\nInvalid version name: ${{ github.event.inputs.versionName }}"
exit 1
fi

if [[ ${{ github.event.inputs.versionName }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# use given version number
NEXT_TAG="${{ github.event.inputs.versionName }}"
else
# calculate new version number based on given tag
NEXT_TAG=$(bump2version --dry-run --list ${{ github.event.inputs.versionName }} | grep ^new_version | sed -r s,"^.*=",,)
fi
# apply given or calculated version number
bump2version --new-version $NEXT_TAG _ignored_arg_
# save version number for later
echo "next_tag=$NEXT_TAG" >> $GITHUB_OUTPUT
- name: Get main branch SHA
id: base-sha
run: echo "sha=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT
Expand All @@ -44,9 +62,11 @@ jobs:
src/client/packaging/pypi/**
- name: Bump Python versions if client files changed
if: steps.changed-py.outputs.any_changed == 'true'
# _ignored_arg_ below is required because of tool quirk
# https://github.com/c4urself/bump2version/issues/22
run: |
cd src/client/packaging/pypi
bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} ignore_part
bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} _ignored_arg_
- name: Create pull request into prod
uses: peter-evans/create-pull-request@v3
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release-helper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
id: changed-py
uses: tj-actions/changed-files@v44
with:
files: |
src/client/delphi_epidata.py
src/client/packaging/pypi/**
files: |
src/client/delphi_epidata.py
src/client/packaging/pypi/**
outputs:
any_changed: ${{ steps.changed-py.outputs.any_changed }}

Expand All @@ -47,8 +47,8 @@ jobs:
id: extract_version
run: |
python -m pip install bump2version
echo -n "::set-output name=version::"
bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,
VERSION=$(bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: release-drafter/release-drafter@v5
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16.x'
node-version: "16.x"
- name: Cache Node.js modules
uses: actions/cache@v2
with:
Expand Down
1 change: 0 additions & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
aiohttp==3.9.4
black>=20.8b1
bump2version==1.0.1
covidcast==0.1.5
delphi_utils
docker==6.0.1
Expand Down
Loading