From 503435fba970d44be2df5ad754b1d09dc88feed3 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 9 Jan 2025 15:31:08 +0200 Subject: [PATCH] Prepare for publishing --- .github/workflows/python-package.yml | 61 +++++++++++++++++++++++++++- pyproject.toml | 3 ++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 7ecb136..184af2b 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -10,8 +10,7 @@ on: branches: [ "main" ] jobs: - build: - + test: runs-on: ubuntu-latest strategy: fail-fast: false @@ -40,3 +39,61 @@ jobs: - name: Test with pytest run: | pytest + + deploy: + name: upload release to PyPI + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: test + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/aliftools + permissions: + # IMPORTANT: this permission is mandatory for trusted publishing + id-token: write + steps: + - uses: actions/checkout@v4 + with: + # setuptools_scm requires the git clone to not be 'shallow' + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Extract release notes from annotated tag message + id: release_notes + env: + # e.g. v0.1.0a1, v1.2.0b2 or v2.3.0rc3, but not v1.0.0 + PRERELEASE_TAG_PATTERN: "v[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+([ab]|rc)[[:digit:]]+" + run: | + # GH checkout action doesn't preserve tag annotations, we must fetch them + # https://github.com/actions/checkout/issues/290 + git fetch --tags --force + # Dump tag message body to temporary .md file + echo "$(git tag -l --format='%(contents:body)' ${{ github.ref_name }})" > "${{ runner.temp }}/release_body.md" + # Set RELEASE_NAME env var to tag message subject + echo "RELEASE_NAME=$(git tag -l --format='%(contents:subject)' ${{ github.ref_name }})" >> $GITHUB_ENV + # if the tag has a pre-release suffix mark the Github Release accordingly + if egrep -q "$PRERELEASE_TAG_PATTERN" <<< "${{ github.ref_name }}"; then + echo "Tag contains a pre-release suffix" + echo "IS_PRERELEASE=true" >> "$GITHUB_ENV" + else + echo "Tag does not contain pre-release suffix" + echo "IS_PRERELEASE=false" >> "$GITHUB_ENV" + fi + + - name: Create GitHub release + id: create_release + uses: softprops/action-gh-release@v2 + with: + body_path: "${{ runner.temp }}/release_body.md" + draft: false + prerelease: ${{ env.IS_PRERELEASE }} + + - name: Build + run: pipx run build + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@v1.12.3 diff --git a/pyproject.toml b/pyproject.toml index ebc27bb..9043e87 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,9 @@ make-sample = "alifTools.sample:main" [tool.setuptools_scm] version_file = "Lib/alifTools/_version.py" +[tool.distutils.bdist_wheel] +universal = true + [tool.black] exclude = ''' (