From 1f50b0bd11b6e8243d3531f107db1103f6ba3c42 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Thu, 6 Jun 2024 21:39:14 -0700 Subject: [PATCH 1/2] fix(ci): use bump-my-version and fix release CI --- .github/workflows/create-release.yml | 23 ++++++++++++++++----- requirements.dev.txt | 1 - src/client/packaging/pypi/.bumpversion.cfg | 8 -------- src/client/packaging/pypi/pyproject.toml | 24 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) delete mode 100644 src/client/packaging/pypi/.bumpversion.cfg diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index f2973b92f..f3f7e3775 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -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 @@ -27,10 +27,23 @@ 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,"^.*=",, + python -m pip install bump-my-version + echo -n "next_tag=" >> $GITHUB_OUTPUT + 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 + echo "${{ github.event.inputs.versionName }}" + else + echo $(bump-my-version show-bump | grep ${{ github.event.inputs.versionName }} | sed -r s,"^.*─ ",,) + fi - name: Get main branch SHA id: base-sha run: echo "sha=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT @@ -46,7 +59,7 @@ jobs: if: steps.changed-py.outputs.any_changed == 'true' run: | cd src/client/packaging/pypi - bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} ignore_part + bump-my-version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} - name: Create pull request into prod uses: peter-evans/create-pull-request@v3 with: diff --git a/requirements.dev.txt b/requirements.dev.txt index ff7da9923..92c707c13 100644 --- a/requirements.dev.txt +++ b/requirements.dev.txt @@ -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 diff --git a/src/client/packaging/pypi/.bumpversion.cfg b/src/client/packaging/pypi/.bumpversion.cfg deleted file mode 100644 index 35a97c480..000000000 --- a/src/client/packaging/pypi/.bumpversion.cfg +++ /dev/null @@ -1,8 +0,0 @@ -[bumpversion] -current_version = 4.1.23 -commit = False -tag = False - -[bumpversion:file:../../delphi_epidata.py] - -[bumpversion:file:pyproject.toml] \ No newline at end of file diff --git a/src/client/packaging/pypi/pyproject.toml b/src/client/packaging/pypi/pyproject.toml index 2aadda4e9..ddac7a5b6 100644 --- a/src/client/packaging/pypi/pyproject.toml +++ b/src/client/packaging/pypi/pyproject.toml @@ -42,3 +42,27 @@ dependencies = ["aiohttp", "delphi-utils", "requests>=2.7.0", "tenacity"] [project.urls] "Homepage" = "https://github.com/cmu-delphi/delphi-epidata" "Changelog" = "https://github.com/cmu-delphi/delphi-epidata/blob/main/src/client/packaging/pypi/CHANGELOG.md" + +[tool.bumpversion] +current_version = "4.1.23" +parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" +serialize = ["{major}.{minor}.{patch}"] +search = "{current_version}" +replace = "{new_version}" +regex = false +ignore_missing_version = false +ignore_missing_files = false +tag = false +sign_tags = false +tag_name = "v{new_version}" +tag_message = "Bump version: {current_version} → {new_version}" +allow_dirty = false +commit = false +message = "Bump version: {current_version} → {new_version}" +commit_args = "" + +[[tool.bumpversion.files]] +filename = "../../delphi_epidata.py" + +[[tool.bumpversion.files]] +filename = "pyproject.toml" From 9d3a9cae126148bfbbeb67ba9c85d32a0de7e581 Mon Sep 17 00:00:00 2001 From: Dmitry Shemetov Date: Fri, 7 Jun 2024 16:19:57 -0700 Subject: [PATCH 2/2] fix(ci): use bump2version and validate * add comments * revert bumpversion configs Co-authored-by: george --- .github/workflows/create-release.yml | 17 ++++++++++----- .github/workflows/release-helper.yml | 12 +++++------ src/client/packaging/pypi/.bumpversion.cfg | 8 ++++++++ src/client/packaging/pypi/pyproject.toml | 24 ---------------------- 4 files changed, 26 insertions(+), 35 deletions(-) create mode 100644 src/client/packaging/pypi/.bumpversion.cfg diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index f3f7e3775..a4e33af65 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -30,8 +30,7 @@ jobs: # See this issue for explanation and testing: # https://github.com/cmu-delphi/delphi-epidata/pull/1473 run: | - python -m pip install bump-my-version - echo -n "next_tag=" >> $GITHUB_OUTPUT + python -m pip install bump2version allowed_pattern="^(major|minor|patch|[0-9]+\.[0-9]+\.[0-9]+)$" if [[ ! ${{ github.event.inputs.versionName }} =~ $allowed_pattern ]]; then @@ -40,10 +39,16 @@ jobs: fi if [[ ${{ github.event.inputs.versionName }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "${{ github.event.inputs.versionName }}" + # use given version number + NEXT_TAG="${{ github.event.inputs.versionName }}" else - echo $(bump-my-version show-bump | grep ${{ github.event.inputs.versionName }} | sed -r s,"^.*─ ",,) + # 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 @@ -57,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 - bump-my-version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} + 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: diff --git a/.github/workflows/release-helper.yml b/.github/workflows/release-helper.yml index 83645a325..4fef82c34 100644 --- a/.github/workflows/release-helper.yml +++ b/.github/workflows/release-helper.yml @@ -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 }} @@ -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 @@ -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: diff --git a/src/client/packaging/pypi/.bumpversion.cfg b/src/client/packaging/pypi/.bumpversion.cfg new file mode 100644 index 000000000..35a97c480 --- /dev/null +++ b/src/client/packaging/pypi/.bumpversion.cfg @@ -0,0 +1,8 @@ +[bumpversion] +current_version = 4.1.23 +commit = False +tag = False + +[bumpversion:file:../../delphi_epidata.py] + +[bumpversion:file:pyproject.toml] \ No newline at end of file diff --git a/src/client/packaging/pypi/pyproject.toml b/src/client/packaging/pypi/pyproject.toml index ddac7a5b6..2aadda4e9 100644 --- a/src/client/packaging/pypi/pyproject.toml +++ b/src/client/packaging/pypi/pyproject.toml @@ -42,27 +42,3 @@ dependencies = ["aiohttp", "delphi-utils", "requests>=2.7.0", "tenacity"] [project.urls] "Homepage" = "https://github.com/cmu-delphi/delphi-epidata" "Changelog" = "https://github.com/cmu-delphi/delphi-epidata/blob/main/src/client/packaging/pypi/CHANGELOG.md" - -[tool.bumpversion] -current_version = "4.1.23" -parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" -serialize = ["{major}.{minor}.{patch}"] -search = "{current_version}" -replace = "{new_version}" -regex = false -ignore_missing_version = false -ignore_missing_files = false -tag = false -sign_tags = false -tag_name = "v{new_version}" -tag_message = "Bump version: {current_version} → {new_version}" -allow_dirty = false -commit = false -message = "Bump version: {current_version} → {new_version}" -commit_args = "" - -[[tool.bumpversion.files]] -filename = "../../delphi_epidata.py" - -[[tool.bumpversion.files]] -filename = "pyproject.toml"