diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e34cfbe..936e92d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,67 +1,18 @@ -name: Build, Release, and Publish +name: Publish Python 🐍 distribution πŸ“¦ to PyPI and TestPyPI on: workflow_dispatch: -permissions: - contents: write - packages: write - jobs: build: + name: Build distribution πŸ“¦ runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 with: - fetch-depth: 0 # Shallow clones should be disabled for a better release experience - - - name: Extract Current Version Number - id: extract_current_version - run: | - CURRENT_VERSION=$(grep '__version__' src/pystatpower/__init__.py | cut -d '"' -f 2) - echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_OUTPUT - - - name: Get Previous Version Number - id: get_previous_version - run: | - PREVIOUS_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0") - PREVIOUS_VERSION=$(echo "$PREVIOUS_VERSION" | xargs) # εŽ»ι™€ε―θƒ½ηš„η©Ίζ Ό - echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_OUTPUT - - - name: Compare Versions - id: compare_versions - run: | - CURRENT_VERSION="${{ steps.extract_current_version.outputs.CURRENT_VERSION }}" - PREVIOUS_VERSION="${{ steps.get_previous_version.outputs.PREVIOUS_VERSION }}" - python - < previous_version: - print(f"Version increased from {previous_version} to {current_version}. Continuing the workflow.") - else: - print(f"Version did not increase. Stopping the workflow.") - sys.exit(1) - except Exception as e: - print(f"Error comparing versions: {e}") - sys.exit(1) - EOF - - - name: Determine Release Type - id: determine_release_type - run: | - VERSION="${{ steps.extract_current_version.outputs.CURRENT_VERSION }}" - if [[ "$VERSION" =~ [abrc] ]]; then - echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT - else - echo "IS_PRERELEASE=false" >> $GITHUB_OUTPUT - fi + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 @@ -76,54 +27,28 @@ jobs: - name: Build package run: python -m build - - name: Upload distribution + - name: Upload the distribution packages uses: actions/upload-artifact@v4 with: name: distribution - path: dist/* - - - name: Create Tag - run: | - git config --local user.name "github-actions[bot]" - git config --local user.email "github-actions[bot]@users.noreply.github.com" - git tag ${{ steps.extract_current_version.outputs.CURRENT_VERSION }} - git push origin ${{ steps.extract_current_version.outputs.CURRENT_VERSION }} - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.extract_current_version.outputs.CURRENT_VERSION }} - release_name: ${{ steps.extract_current_version.outputs.CURRENT_VERSION }} - draft: false - prerelease: ${{ steps.determine_release_type.outputs.IS_PRERELEASE }} + path: dist/ - - name: Upload Release Asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/pystatpower-${{ steps.extract_current_version.outputs.CURRENT_VERSION }}.tar.gz - asset_name: ${{ steps.extract_current_version.outputs.CURRENT_VERSION }}.tar.gz - asset_content_type: application/gzip - - pypi-publish: + publish-to-pypi: + name: Publish Python 🐍 distribution πŸ“¦ to PyPI + if: startsWith(github.ref, 'refs/tags/') + needs: + - build runs-on: ubuntu-latest - needs: build environment: name: release url: https://pypi.org/p/pystatpower permissions: - id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write # IMPORTANT: mandatory for trusted publishing steps: - - name: Download distribution + - name: Download all the dists uses: actions/download-artifact@v4 with: - name: distribution - path: dist - - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@v1.10.1 + name: python-package-distributions + path: dist/ + - name: Publish distribution πŸ“¦ to PyPI + uses: pypa/gh-action-pypi-publish@release/v1