Skip to content

Commit e41c741

Browse files
authored
Merge pull request #1473 from cmu-delphi/ds/bump-version
fix(pyclient ci): validate version arg in create-release
2 parents baaf548 + 9d3a9ca commit e41c741

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

.github/workflows/create-release.yml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
versionName:
7-
description: 'Semantic Version Number (i.e., 5.5.0 or patch, minor, major, prepatch, preminor, premajor, prerelease)'
7+
description: 'Semantic Version Number (i.e., 5.5.0 or patch, minor, major)'
88
required: true
99
default: patch
1010

@@ -27,10 +27,28 @@ jobs:
2727
python-version: 3.8
2828
- name: Change version number
2929
id: version
30+
# See this issue for explanation and testing:
31+
# https://github.com/cmu-delphi/delphi-epidata/pull/1473
3032
run: |
3133
python -m pip install bump2version
32-
echo -n "::set-output name=next_tag::"
33-
bump2version --list ${{ github.event.inputs.versionName }} | grep new_version | sed -r s,"^.*=",,
34+
allowed_pattern="^(major|minor|patch|[0-9]+\.[0-9]+\.[0-9]+)$"
35+
36+
if [[ ! ${{ github.event.inputs.versionName }} =~ $allowed_pattern ]]; then
37+
echo "\nInvalid version name: ${{ github.event.inputs.versionName }}"
38+
exit 1
39+
fi
40+
41+
if [[ ${{ github.event.inputs.versionName }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
42+
# use given version number
43+
NEXT_TAG="${{ github.event.inputs.versionName }}"
44+
else
45+
# calculate new version number based on given tag
46+
NEXT_TAG=$(bump2version --dry-run --list ${{ github.event.inputs.versionName }} | grep ^new_version | sed -r s,"^.*=",,)
47+
fi
48+
# apply given or calculated version number
49+
bump2version --new-version $NEXT_TAG _ignored_arg_
50+
# save version number for later
51+
echo "next_tag=$NEXT_TAG" >> $GITHUB_OUTPUT
3452
- name: Get main branch SHA
3553
id: base-sha
3654
run: echo "sha=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT
@@ -44,9 +62,11 @@ jobs:
4462
src/client/packaging/pypi/**
4563
- name: Bump Python versions if client files changed
4664
if: steps.changed-py.outputs.any_changed == 'true'
65+
# _ignored_arg_ below is required because of tool quirk
66+
# https://github.com/c4urself/bump2version/issues/22
4767
run: |
4868
cd src/client/packaging/pypi
49-
bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} ignore_part
69+
bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} _ignored_arg_
5070
- name: Create pull request into prod
5171
uses: peter-evans/create-pull-request@v3
5272
with:

.github/workflows/release-helper.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ jobs:
2525
id: changed-py
2626
uses: tj-actions/changed-files@v44
2727
with:
28-
files: |
29-
src/client/delphi_epidata.py
30-
src/client/packaging/pypi/**
28+
files: |
29+
src/client/delphi_epidata.py
30+
src/client/packaging/pypi/**
3131
outputs:
3232
any_changed: ${{ steps.changed-py.outputs.any_changed }}
3333

@@ -47,8 +47,8 @@ jobs:
4747
id: extract_version
4848
run: |
4949
python -m pip install bump2version
50-
echo -n "::set-output name=version::"
51-
bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,
50+
VERSION=$(bump2version --dry-run --list patch | grep ^current_version | sed -r s,"^.*=",,)
51+
echo "version=$VERSION" >> $GITHUB_OUTPUT
5252
- name: Create Release
5353
id: create_release
5454
uses: release-drafter/release-drafter@v5
@@ -114,7 +114,7 @@ jobs:
114114
uses: actions/checkout@v2
115115
- uses: actions/setup-node@v2
116116
with:
117-
node-version: '16.x'
117+
node-version: "16.x"
118118
- name: Cache Node.js modules
119119
uses: actions/cache@v2
120120
with:

requirements.dev.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
aiohttp==3.9.4
22
black>=20.8b1
3-
bump2version==1.0.1
43
covidcast==0.1.5
54
delphi_utils
65
docker==6.0.1

0 commit comments

Comments
 (0)