Skip to content

Merge pull request #26 from joakimwinum/dependabot/github_actions/pyp… #44

Merge pull request #26 from joakimwinum/dependabot/github_actions/pyp…

Merge pull request #26 from joakimwinum/dependabot/github_actions/pyp… #44

name: Build, Test, and Publish Python Package
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Lint with autopep8 and get statistics from flake8
run: |
# exit-zero treats all errors as warnings.
# show statistics for Python syntax errors or undefined names.
# the GitHub editor is 127 chars wide.
flake8 . --count --exit-zero --extend-ignore E402 --max-complexity=10 --max-line-length=127 --show-source --statistics
# stop the build if there are Python syntax errors.
autopep8 . --ignore E402 --recursive --diff --exit-code
- name: Install local package
run: |
python -m pip install --editable .
- name: Test with pytest
run: |
coverage run -m pytest
- name: Report coverage statistics on modules
run: |
coverage report --fail-under=80 --show-missing
- name: Type checking with mypy
run: |
mypy --strict --exclude='src' .
build:
needs: [test]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
env:
PACKAGE_NAME: bytecorecompiler
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Setup Python
uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build package
run: python -m build
- name: Test self building package
run: |
pip install dist/${{ env.PACKAGE_NAME }}-*.tar.gz
python -c "import ${{ env.PACKAGE_NAME }}; print(${{ env.PACKAGE_NAME }})"
shell: bash
- name: Upload distribution archives
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: distribution-archives-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
combine:
needs: [test, build]
runs-on: ubuntu-latest
steps:
- name: Download All Artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
path: distribution-archives
pattern: distribution-archives-*
merge-multiple: true
- name: List distribution archives
run: ls --recursive distribution-archives
- name: Upload combined distribution archives
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: combined-distribution-archives
path: distribution-archives
publish:
if: startsWith(github.ref, 'refs/tags/')
needs: [test, build, combine]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/bytecorecompiler
permissions:
id-token: write
env:
PACKAGE_NAME: bytecorecompiler
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Download combined distribution archives
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: combined-distribution-archives
path: dist
- name: List dist folder
run: ls --recursive dist
- name: Extract and store tag
run: |
TAG=${GITHUB_REF#refs/tags/}
echo "Tag: $TAG"
echo "TAG=$TAG" >> $GITHUB_ENV
- name: Verify version in combined distribution archives
run: |
for file in dist/*; do
filename=$(basename "$file")
if [[ $filename != ${{ env.PACKAGE_NAME }}-$TAG* ]]; then
echo "File $filename does not start with ${{ env.PACKAGE_NAME }}-$TAG"
exit 1
fi
done
echo "All files in dist directory start with ${{ env.PACKAGE_NAME }}-$TAG"
- name: Verify existence of source distribution archive
run: |
if [[ ! -f dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz ]]; then
echo "Error: dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz does not exist."
exit 1
fi
echo "dist/${{ env.PACKAGE_NAME }}-$TAG.tar.gz exists."
- name: Verify version in pyproject.toml
run: |
VERSION=$(grep --perl-regexp --only-matching '(?<=^version = ")[^"]*' pyproject.toml)
if [[ "$VERSION" != "$TAG" ]]; then
echo "Version in pyproject.toml $VERSION does not match the tag $TAG"
exit 1
fi
echo "Version in pyproject.toml matches the tag: $VERSION"
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@15c56dba361d8335944d31a2ecd17d700fc7bcbc
with:
verify-metadata: true
skip-existing: false
verbose: false
print-hash: true