From 77455f3805d3688b738c13a0a4953bb05bf6464e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20M=C3=A9ndez?= Date: Sat, 10 Feb 2024 12:49:07 -0600 Subject: [PATCH] New release & publish gh actions --- .../draft-release-and-upload-to-pypi.yml | 49 ------------------- .github/workflows/publish.yml | 36 ++++++++++++++ .github/workflows/release.yml | 20 ++++++++ README.md | 1 + 4 files changed, 57 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/draft-release-and-upload-to-pypi.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/draft-release-and-upload-to-pypi.yml b/.github/workflows/draft-release-and-upload-to-pypi.yml deleted file mode 100644 index 7673347..0000000 --- a/.github/workflows/draft-release-and-upload-to-pypi.yml +++ /dev/null @@ -1,49 +0,0 @@ -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -permissions: - contents: read - -name: Create Draft Release and Upload Package to Pypi - -jobs: - draft-release: - name: Create Draft Release - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: true - prerelease: false - - upload: - name: Upload Package to Pypi - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build - - name: Build package - run: python -m build - - name: Publish package - uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf - with: - user: __token__ - password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..fcc4dc9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,36 @@ +name: Publish to PyPI + +on: + release: + types: [published] + +permissions: + contents: read + +jobs: + deploy: + + runs-on: ubuntu-latest + + environment: release + permissions: + id-token: write # IMPORTANT: this permission is mandatory for trusted publishing + + steps: + - uses: actions/checkout@v4.1.1 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install hatch + - name: Build package + run: hatch build + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..097ada6 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,20 @@ +name: Create Draft Release + +on: + push: + tags: + - "v*" + +jobs: + + build: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + - uses: ncipollo/release-action@v1 + with: + - draft: true + - allowUpdates: true + - generateReleaseNotes: true diff --git a/README.md b/README.md index ab7c2aa..a9144b5 100644 --- a/README.md +++ b/README.md @@ -155,3 +155,4 @@ Tools used in building this package: Posts I learned from: - [Switching to Hatch](https://andrich.me/2023/08/switching-to-hatch/) +- [Automate Hatch Publish with GitHub Actions](https://blog.pecar.me/automate-hatch-publish)