From a8af68467453b296150f1743dfd4029966912a60 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 17:13:18 +0100 Subject: [PATCH 1/6] Added automatic version bump flow --- .github/workflows/version_bump.yml | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 .github/workflows/version_bump.yml diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml new file mode 100644 index 000000000..918d50840 --- /dev/null +++ b/.github/workflows/version_bump.yml @@ -0,0 +1,100 @@ +name: Version Bump +run-name: Version bump ${{ inputs.bump_type }}${{ inputs.test_mode && ' (TEST)' || '' }} + +on: + workflow_dispatch: + inputs: + bump_type: + description: "Version bump type" + required: true + default: "patch" + type: choice + options: + - patch + - minor + - major + test_mode: + description: "Run in test mode (publishes to Test PyPI)" + required: true + default: false + type: boolean + +permissions: + contents: write + +jobs: + bump-version: + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@v2.10.4 + with: + egress-policy: audit + + - uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5.4.0 + with: + python-version: "3.9" + + - name: Setup Poetry + uses: abatilo/actions-poetry@0dd19c9498c3dc8728967849d0d2eae428a8a3d8 + with: + poetry-version: "1.3.1" + + - name: Configure Git + run: | + git config user.name github-actions[bot] + git config user.email github-actions[bot]@users.noreply.github.com + + - name: Bump version + run: | + if [[ "${{ inputs.test_mode }}" == "true" ]]; then + TIMESTAMP=$(date +%Y%m%d%H%M%S) + TEST_VERSION="0.0.0-test.${TIMESTAMP}" + poetry version ${TEST_VERSION} + echo "NEW_VERSION=${TEST_VERSION}" >> $GITHUB_ENV + echo "TAG_PREFIX=test-" >> $GITHUB_ENV + echo "BRANCH_NAME=test/version-bump" >> $GITHUB_ENV + else + CURRENT_VERSION=$(poetry version -s) + poetry version ${{ inputs.bump_type }} + NEW_VERSION=$(poetry version -s) + echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV + echo "TAG_PREFIX=v" >> $GITHUB_ENV + echo "BRANCH_NAME=master" >> $GITHUB_ENV + fi + + - name: Commit and push changes + run: | + git add pyproject.toml + git commit -m "Version bump to ${TAG_PREFIX}${NEW_VERSION}" + if [[ "${{ inputs.test_mode }}" == "true" ]]; then + git checkout -b ${BRANCH_NAME} + fi + git push origin HEAD:${BRANCH_NAME} + + - name: Create and push tag + run: | + git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "Release version ${NEW_VERSION}" + git push origin "${TAG_PREFIX}${NEW_VERSION}" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} + name: ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} + generate_release_notes: true + draft: false + prerelease: ${{ inputs.test_mode }} + + - name: Notify Slack + uses: ./.github/workflows/JOB_slack_message.yml + with: + icon: ":arrows_counterclockwise:" + message: | + ${{ inputs.test_mode && '[TEST] ' || '' }}Version ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} has been bumped and tagged + Type: ${{ inputs.bump_type }} From fde54bec1fdef10790cbba1dfc105941857c9a8c Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 17:25:19 +0100 Subject: [PATCH 2/6] Cleaned up flow --- .github/workflows/version_bump.yml | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 918d50840..6b96d0f99 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -40,11 +40,6 @@ jobs: with: python-version: "3.9" - - name: Setup Poetry - uses: abatilo/actions-poetry@0dd19c9498c3dc8728967849d0d2eae428a8a3d8 - with: - poetry-version: "1.3.1" - - name: Configure Git run: | git config user.name github-actions[bot] @@ -54,15 +49,12 @@ jobs: run: | if [[ "${{ inputs.test_mode }}" == "true" ]]; then TIMESTAMP=$(date +%Y%m%d%H%M%S) - TEST_VERSION="0.0.0-test.${TIMESTAMP}" - poetry version ${TEST_VERSION} - echo "NEW_VERSION=${TEST_VERSION}" >> $GITHUB_ENV + echo "NEW_VERSION=0.0.0-test.${TIMESTAMP}" >> $GITHUB_ENV echo "TAG_PREFIX=test-" >> $GITHUB_ENV echo "BRANCH_NAME=test/version-bump" >> $GITHUB_ENV else - CURRENT_VERSION=$(poetry version -s) - poetry version ${{ inputs.bump_type }} - NEW_VERSION=$(poetry version -s) + python deploy/increase_version.py --${{ inputs.bump_type }} + NEW_VERSION=$(cat .version) echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV echo "TAG_PREFIX=v" >> $GITHUB_ENV echo "BRANCH_NAME=master" >> $GITHUB_ENV @@ -70,8 +62,8 @@ jobs: - name: Commit and push changes run: | - git add pyproject.toml - git commit -m "Version bump to ${TAG_PREFIX}${NEW_VERSION}" + git add pyproject.toml darwin/__init__.py + git commit -m "Version bump to ${{ env.NEW_VERSION }}" if [[ "${{ inputs.test_mode }}" == "true" ]]; then git checkout -b ${BRANCH_NAME} fi @@ -79,7 +71,7 @@ jobs: - name: Create and push tag run: | - git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "Release version ${NEW_VERSION}" + git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "bump version to ${TAG_PREFIX}${NEW_VERSION}" git push origin "${TAG_PREFIX}${NEW_VERSION}" - name: Create GitHub Release From cae957f9c1d919fccc27e85bc06eb13d3ce66115 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 17:45:12 +0100 Subject: [PATCH 3/6] remove notify slack action as redudant --- .github/workflows/version_bump.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 6b96d0f99..98f44d3bb 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -82,11 +82,3 @@ jobs: generate_release_notes: true draft: false prerelease: ${{ inputs.test_mode }} - - - name: Notify Slack - uses: ./.github/workflows/JOB_slack_message.yml - with: - icon: ":arrows_counterclockwise:" - message: | - ${{ inputs.test_mode && '[TEST] ' || '' }}Version ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} has been bumped and tagged - Type: ${{ inputs.bump_type }} From 9b494474d7a59d46175b473e77cbbc9a99cf3669 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 17:52:43 +0100 Subject: [PATCH 4/6] avoiding recreating a relese since it's managed in EVENT_tag worfklow --- .github/workflows/version_bump.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 98f44d3bb..1a720002b 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -73,12 +73,3 @@ jobs: run: | git tag -a "${TAG_PREFIX}${NEW_VERSION}" -m "bump version to ${TAG_PREFIX}${NEW_VERSION}" git push origin "${TAG_PREFIX}${NEW_VERSION}" - - - name: Create GitHub Release - uses: softprops/action-gh-release@v1 - with: - tag_name: ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} - name: ${{ env.TAG_PREFIX }}${{ env.NEW_VERSION }} - generate_release_notes: true - draft: false - prerelease: ${{ inputs.test_mode }} From cd7479f281cf2c71e5391e3bdb6f731e3aa8a685 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 18:01:38 +0100 Subject: [PATCH 5/6] Skip tests if python hasn't been changed --- .github/workflows/EVENT_pull_request.yml | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/.github/workflows/EVENT_pull_request.yml b/.github/workflows/EVENT_pull_request.yml index 7c9f50e40..b7ea05bed 100644 --- a/.github/workflows/EVENT_pull_request.yml +++ b/.github/workflows/EVENT_pull_request.yml @@ -14,7 +14,6 @@ concurrency: cancel-in-progress: true jobs: - get_changed_files: name: Get changed files uses: ./.github/workflows/JOB_get_changed_files.yml @@ -24,6 +23,7 @@ jobs: format: name: Check format of python needs: get_changed_files + if: needs.get_changed_files.outputs.python_changed_files != '' uses: ./.github/workflows/JOB_format.yml with: files: ${{ needs.get_changed_files.outputs.python_changed_files }} @@ -33,23 +33,17 @@ jobs: lint: name: Lint python needs: get_changed_files + if: needs.get_changed_files.outputs.python_changed_files != '' uses: ./.github/workflows/JOB_lint.yml with: files: ${{ needs.get_changed_files.outputs.python_changed_files }} permissions: contents: read - # typecheck: - # name: Analyse types in python - # needs: get_changed_files - # uses: ./.github/workflows/JOB_typecheck.yml - # with: - # files: ${{ needs.get_changed_files.outputs.python_changed_files }} - # permissions: - # contents: read - run_tests: name: Run tests + needs: get_changed_files + if: needs.get_changed_files.outputs.python_changed_files != '' uses: ./.github/workflows/JOB_tests.yml permissions: contents: read From 7dd276f02071f3e73592102c6eb6a398a55024d4 Mon Sep 17 00:00:00 2001 From: umberto di fabrizio Date: Tue, 25 Feb 2025 18:01:55 +0100 Subject: [PATCH 6/6] tag specific harden-runner version --- .github/workflows/version_bump.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/version_bump.yml b/.github/workflows/version_bump.yml index 1a720002b..26fb890ff 100644 --- a/.github/workflows/version_bump.yml +++ b/.github/workflows/version_bump.yml @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@v2.10.4 + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e with: egress-policy: audit