From cd0e2a9ca76249f88b16d427be2f07747a7941d2 Mon Sep 17 00:00:00 2001 From: Tomas Peterka Date: Wed, 7 Feb 2024 15:37:18 +0100 Subject: [PATCH] fix(ci): solve the problem that tag made by workflow cannot trigger --- .github/workflows/release-python.yaml | 43 --------------------------- .github/workflows/release.yml | 40 +++++++++++++++++++++---- pyproject.toml | 2 +- 3 files changed, 35 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/release-python.yaml diff --git a/.github/workflows/release-python.yaml b/.github/workflows/release-python.yaml deleted file mode 100644 index c39902c..0000000 --- a/.github/workflows/release-python.yaml +++ /dev/null @@ -1,43 +0,0 @@ -name: "[auto] release-python" - -on: - push: - tags: - - v* - -env: - PYTHON_VERSION: "3.10" - -jobs: - build: - name: Release new version to PyPI - runs-on: ubuntu-latest - steps: - - name: Check version format vMAJOR.MINOR.PATCH(-SUFFIX) - run: | - if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+(\.[a-zA-Z0-9]+)*)?$ ]]; then - echo "Invalid version format. Expected vMAJOR.MINOR.PATCH(-SUFFIX)?, got ${GITHUB_REF_NAME}" - exit 1 - fi - - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Install the project - uses: dronetag/actions/release-python@main - with: - pypi_name: dronetag - pypi_host: ${{ secrets.PRIV_PIP_HOST }} - pypi_user: ${{ secrets.PRIV_PIP_USER }} - pypi_pass: ${{ secrets.PRIV_PIP_PASSWORD }} - version: "${GITHUB_REF_NAME#v}" - - - name: Commit version on release branch - run: | - if [[ $(git rev-parse heads/main) = $(git rev-parse ${GITHUB_REF}) ]]; then - echo "We are at the top of main branch so we can commit the version bump" - git checkout main - git add pyproject.toml - git commit -m "Release ${GITHUB_REF_NAME#v} [skip ci]" - git push - fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 58d6952..5a89cba 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: "RELEASE" +name: "Release" on: workflow_dispatch: @@ -13,11 +13,39 @@ jobs: with: { fetch-depth: 0 } # Required to determine version - name: Get next release version - uses: dronetag/actions/get-next-version@main - id: get-next-version + uses: dronetag/actions/semantic-release@main + id: semantic - - name: Create the tag + - name: Build package + uses: dronetag/actions/build-python@main + with: + version: ${{ steps.semantic.outputs.version }} + + - name: Commit version on release branch + if: ${{ steps.semantic.outputs.existed == 'false' }} + run: | + if [[ $(git rev-parse origin/${{github.event.repository.default_branch}}) = $(git rev-parse HEAD) ]]; then + git checkout ${{github.event.repository.default_branch}} # in case we are on tag + if [[ ! $(git diff --exit-code) ]]; then + git config --local user.email "" && git config --local user.name "GitHub Action" + git diff --name-only | xargs git add + git add changelog.md + git commit -m "Release ${{ steps.semantic.outputs.version }} [skip ci]" + git push origin ${{github.event.repository.default_branch}} + fi + fi + + - name: Create the tag (if it does not exist yet) run: | + git show-ref --tags --verify --quiet "refs/tags/v${{ steps.semantic.outputs.version }}" && exit 0 git config --local user.email "" && git config --local user.name "GitHub Action" - git tag v${{ steps.get-next-version.outputs.version }} - git push origin v${{ steps.get-next-version.outputs.version }} + git tag v${{ steps.semantic.outputs.version }} + git push origin v${{ steps.semantic.outputs.version }} + + - name: Release + uses: dronetag/actions/release-python@main + with: + pypi_name: dronetag + pypi_host: ${{ secrets.PRIV_PIP_HOST }} + pypi_user: ${{ secrets.PRIV_PIP_USER }} + pypi_pass: ${{ secrets.PRIV_PIP_PASSWORD }} diff --git a/pyproject.toml b/pyproject.toml index 82a0c96..057393a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools >= 61.0"] +requires = ["setuptools >= 59.0"] build-backend = "setuptools.build_meta" [project]