diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b321160..e2f491f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,9 +2,9 @@ name: Releases on: pull_request: - push: - branches: - - master + push: + branches: + - master release: types: - created @@ -17,8 +17,6 @@ jobs: id-token: write steps: - uses: actions/checkout@master - - name: Create commit identifier - run: echo "COMMIT_ID=`echo ${{ github.sha }} | head -c 5`" >> $GITHUB_ENV - name: Set up Python uses: actions/setup-python@v5 with: @@ -27,21 +25,28 @@ jobs: uses: abatilo/actions-poetry@v3 with: poetry-version: "1.3.2" - - name: Version poetry package for test - if: endsWith(github.ref, '/merge') - run: poetry version "`poetry version | awk '{print $2}'`+$COMMIT_ID" - - name: Version poetry package for release - if: startsWith(github.ref, 'refs/tags') - run: poetry version "${{ github.ref_name }}+$COMMIT_ID" + - name: Get previous Tag + if: github.ref == 'refs/heads/master' + id: previoustag + uses: WyriHaximus/github-action-get-previous-tag@v1 + - name: Set Build version + if: github.event.pull_request.merged == true + run: | + COMMIT_ID=`echo ${{ github.sha }} | head -c 8` + poetry version "${{ steps.previoustag.outputs.tag }}+$COMMIT_ID" + - name: Set Release version + if: github.event_name == 'release' && github.event.action == 'created' + run: poetry version ${{ github.ref_name }} - name: Build poetry package run: poetry build - name: Publish distribution 📦 to Test PyPI + if: github.event.pull_request.merged == true uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.TEST_PYPI_API_TOKEN }} repository-url: https://test.pypi.org/legacy/ - name: Publish distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags') + if: github.event_name == 'release' && github.event.action == 'created' uses: pypa/gh-action-pypi-publish@release/v1 with: password: ${{ secrets.PYPI_API_TOKEN }}