Skip to content

Prepare for publishing #13

Prepare for publishing

Prepare for publishing #13

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install -e .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- 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