From 65fdd77f8b29db2dc8df292c524c95c0714b0bc0 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 09:52:02 +0000 Subject: [PATCH 1/6] GHA: Auto publish release when triggered on main When the publish-release workflow is triggered on main, it will auto publish to test.pypi.org. --- .github/workflows/publish-release.yml | 3 ++- .github/workflows/test-release.yml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 77d6843a..3bba6341 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -15,7 +15,7 @@ on: default: "main" jobs: - checks: + publish: runs-on: "ubuntu-latest" steps: - name: Setup python @@ -29,6 +29,7 @@ jobs: - uses: actions/checkout@v3.3.0 with: ref: ${{ inputs.repo_release_ref }} + fetch-depth: 0 # checkout all history, needed for hatch versioning - name: Set SETUPTOOLS_SCM_PRETEND_VERSION run: echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" >> $GITHUB_ENV diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml index f0d1f3a0..7cbada21 100644 --- a/.github/workflows/test-release.yml +++ b/.github/workflows/test-release.yml @@ -1,5 +1,5 @@ -name: Test release -run-name: "Test release (${{ inputs.gitlint_version }}, pypi_source=${{ inputs.pypi_source }}, repo_test_ref=${{ inputs.repo_test_ref }})" +name: Test Release +run-name: "Test Release (${{ inputs.gitlint_version }}, pypi_source=${{ inputs.pypi_source }}, repo_test_ref=${{ inputs.repo_test_ref }})" on: workflow_dispatch: inputs: From 4796967f7cfd685349017df821e3412b55cbdcd9 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 10:01:56 +0000 Subject: [PATCH 2/6] Attemp to fix setting SETUPTOOLS_SCM_PRETEND_VERSION --- .github/workflows/publish-release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 3bba6341..3fc306d8 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -32,7 +32,9 @@ jobs: fetch-depth: 0 # checkout all history, needed for hatch versioning - name: Set SETUPTOOLS_SCM_PRETEND_VERSION - run: echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" >> $GITHUB_ENV + run: | + echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" + echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" >> $GITHUB_ENV - name: Test SETUPTOOLS_SCM_PRETEND_VERSION run: echo $SETUPTOOLS_SCM_PRETEND_VERSION From 9f7dc7dc86d918af9abf3ccd79407c68821ce052 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 10:05:44 +0000 Subject: [PATCH 3/6] fixup! Attemp to fix setting SETUPTOOLS_SCM_PRETEND_VERSION --- .github/workflows/publish-release.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 3fc306d8..560ed988 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -31,6 +31,9 @@ jobs: ref: ${{ inputs.repo_release_ref }} fetch-depth: 0 # checkout all history, needed for hatch versioning + - name: Hatch env create + run: hatch env create + - name: Set SETUPTOOLS_SCM_PRETEND_VERSION run: | echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" @@ -40,10 +43,8 @@ jobs: run: echo $SETUPTOOLS_SCM_PRETEND_VERSION - name: Build (gitlint-core) - run: | - hatch build + run: hatch build working-directory: ./gitlint-core - name: Build (gitlint) - run: | - hatch build + run: hatch build From 4ba885cf5fd4ca1c4106d3bf8007153fde142c40 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 10:27:54 +0000 Subject: [PATCH 4/6] Comments + attemp to use hatch publish --- .github/workflows/publish-release.yml | 34 +++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 560ed988..146de2b0 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -21,7 +21,7 @@ jobs: - name: Setup python uses: actions/setup-python@v4.5.0 with: - python-version: ${{ matrix.python-version }} + python-version: "3.11" - name: Install Hatch run: python -m pip install hatch==1.6.3 @@ -31,20 +31,44 @@ jobs: ref: ${{ inputs.repo_release_ref }} fetch-depth: 0 # checkout all history, needed for hatch versioning + # Create hatch env explicitly to avoid hatch output ("Setting up build environment for missing dependencies") + # during the next step (hatch version) - name: Hatch env create run: hatch env create + # Hatch versioning is based on git (using hatch-vcs). If there is no explicit tag for the commit we're trying to + # publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d + # With the string after '+' being the 'g' of the commit. + # + # However, PyPI doesn't allow '+' in version numbers (=no PEP440 local versions allowed on PyPI). + # To work around this, we override the version string by setting the SETUPTOOLS_SCM_PRETEND_VERSION env var + # to the version string without the '+' and everything after it. + # We then only actual publish such releases on the main branch to guarantee the dev numbering scheme remains + # unique. + # Note that when a tag *is* present (i.e. v0.19.0), hatch versioning will return the tag name (i.e. 0.19.0) + # and this step has no effect, ie. SETUPTOOLS_SCM_PRETEND_VERSION will be the same as `hatch version`. - name: Set SETUPTOOLS_SCM_PRETEND_VERSION run: | - echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(hatch version | cut -d+ -f1)" >> $GITHUB_ENV - - name: Test SETUPTOOLS_SCM_PRETEND_VERSION - run: echo $SETUPTOOLS_SCM_PRETEND_VERSION - - name: Build (gitlint-core) run: hatch build working-directory: ./gitlint-core - name: Build (gitlint) run: hatch build + + - name: Publish (gitlint-core) + run: hatch publish -r test + working-directory: ./gitlint-core + env: + HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }} + HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }} + if: inputs.pypi_target == 'test.pypi.org' && inputs.repo_release_ref == 'main' + + - name: Publish (gitlint) + run: hatch publish -r test + env: + HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }} + HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }} + if: inputs.pypi_target == 'test.pypi.org' && inputs.repo_release_ref == 'main' From 2e7f4281b35ca17e7802b8f4e2878919dfc4764c Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 10:44:30 +0000 Subject: [PATCH 5/6] Run hatch version instead of hatch env create --- .github/workflows/publish-release.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 146de2b0..4bd81fa0 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -31,10 +31,10 @@ jobs: ref: ${{ inputs.repo_release_ref }} fetch-depth: 0 # checkout all history, needed for hatch versioning - # Create hatch env explicitly to avoid hatch output ("Setting up build environment for missing dependencies") + # Run hatch version once to avoid additional output ("Setting up build environment for missing dependencies") # during the next step (hatch version) - - name: Hatch env create - run: hatch env create + - name: Hatch version + run: hatch version # Hatch versioning is based on git (using hatch-vcs). If there is no explicit tag for the commit we're trying to # publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d @@ -69,6 +69,6 @@ jobs: - name: Publish (gitlint) run: hatch publish -r test env: - HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_CORE_USERNAME }} - HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_CORE_PASSWORD }} + HATCH_INDEX_USER: ${{ secrets.TEST_PYPI_GITLINT_USERNAME }} + HATCH_INDEX_AUTH: ${{ secrets.TEST_PYPI_GITLINT_PASSWORD }} if: inputs.pypi_target == 'test.pypi.org' && inputs.repo_release_ref == 'main' From a213a3a8dc4de25d063e74f2e6cbacd7ff7319ed Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Mon, 23 Jan 2023 10:51:11 +0000 Subject: [PATCH 6/6] fixup! Run hatch version instead of hatch env create --- .github/workflows/publish-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 4bd81fa0..60f16de8 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -32,7 +32,7 @@ jobs: fetch-depth: 0 # checkout all history, needed for hatch versioning # Run hatch version once to avoid additional output ("Setting up build environment for missing dependencies") - # during the next step (hatch version) + # during the next step - name: Hatch version run: hatch version @@ -40,7 +40,7 @@ jobs: # publish, hatch versioning strings will have this format: 0.19.0.dev52+g9f7dc7d # With the string after '+' being the 'g' of the commit. # - # However, PyPI doesn't allow '+' in version numbers (=no PEP440 local versions allowed on PyPI). + # However, PyPI doesn't allow '+' in version numbers (no PEP440 local versions allowed on PyPI). # To work around this, we override the version string by setting the SETUPTOOLS_SCM_PRETEND_VERSION env var # to the version string without the '+' and everything after it. # We then only actual publish such releases on the main branch to guarantee the dev numbering scheme remains