diff --git a/.bumpversion.cfg b/.bumpversion.cfg index d6a12c902..84caef621 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -9,10 +9,6 @@ tag = False [bumpversion:file:src/client/delphi_epidata.R] -[bumpversion:file:src/client/delphi_epidata.py] - [bumpversion:file:src/client/packaging/npm/package.json] -[bumpversion:file:src/client/packaging/pypi/pyproject.toml] - [bumpversion:file:dev/local/setup.cfg] diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 329fa76aa..77e087d72 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,11 +27,43 @@ 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,"^.*=",, - - name: Create pull request into prod + if [[ ${{ github.event.inputs.versionName }} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + # use given version number + NEXT_TAG="${{ github.event.inputs.versionName }}" + elif [[ ${{ github.event.inputs.versionName }} =~ ^(major|minor|patch)$ ]]; then + # calculate new version number based on given tag + NEXT_TAG=$(bump2version --dry-run --list ${{ github.event.inputs.versionName }} | grep ^new_version | sed -r s,"^.*=",,) + else + echo "\nInvalid version name: ${{ github.event.inputs.versionName }}" + exit 1 + 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 Python client file changes + id: changed-py + uses: dorny/paths-filter@v3 + with: + base: "main" + ref: "dev" + filters: | + python_client_changed: + - src/client/delphi_epidata.py + - src/client/packaging/pypi/** + - name: Bump Python versions if client files changed + if: steps.changed-py.outputs.python_client_changed == 'true' + # _ignored_arg_ below is required because of tool quirk + # https://github.com/c4urself/bump2version/issues/22 + run: | + cd src/client/packaging/pypi + # this is using the new literal version number (steps.version.outputs.next_tag) output from the bump2version step above, not the workflow input (github.event.inputs.versionName) which can be relative + bump2version --allow-dirty --new-version ${{ steps.version.outputs.next_tag }} _ignored_arg_ + - name: Create pull request into main uses: peter-evans/create-pull-request@v3 with: branch: release/delphi-epidata-${{ steps.version.outputs.next_tag }} diff --git a/.github/workflows/release-helper.yml b/.github/workflows/release-helper.yml index d4c24dfcc..bc87d3b0e 100644 --- a/.github/workflows/release-helper.yml +++ b/.github/workflows/release-helper.yml @@ -13,6 +13,29 @@ jobs: if: github.repository_owner != 'cmu-delphi' run: exit 1 + client_changed: + needs: correct_repository + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 2 + - name: Get Python client file changes + id: changed-py + uses: dorny/paths-filter@v3 + with: + # when base and ref are the same, changes are detected against the most recent commit before the push. + # see https://github.com/dorny/paths-filter#usage for details. + base: 'main' + ref: 'main' + filters: | + python_client_changed: + - src/client/delphi_epidata.py + - src/client/packaging/pypi/** + outputs: + python_client_changed: ${{ steps.changed-py.outputs.python_client_changed }} + create_release: needs: correct_repository runs-on: ubuntu-latest @@ -29,8 +52,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 @@ -45,7 +68,8 @@ jobs: tag_name: ${{ steps.create_release.outputs.tag_name }} release_python_client: - needs: create_release + needs: [client_changed, create_release] + if: needs.client_changed.outputs.python_client_changed == 'true' runs-on: ubuntu-latest steps: - name: Check out code @@ -95,7 +119,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/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 new file mode 100644 index 000000000..5184e1935 --- /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]