Skip to content

Merge pull request #20 from joakimwinum/dependabot/github_actions/act… #55

Merge pull request #20 from joakimwinum/dependabot/github_actions/act…

Merge pull request #20 from joakimwinum/dependabot/github_actions/act… #55

name: Build, Test, and Publish Python Package
on: [push]
jobs:
test-python:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
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' .
test-c:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Install Unity
run: ./setup_unity.sh
- name: cmake
run: mkdir build && cd build && cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
- name: make and test
run: cd build && make
build:
needs: [test-python, test-c]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
env:
MANYLINUX_DOCKER_IMAGE: quay.io/pypa/manylinux_2_28_x86_64
PACKAGE_NAME: bytecorefast
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- name: Setup Python
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build package (Linux)
if: runner.os == 'Linux'
run: |
docker run --rm --name manylinux -v $(pwd):/${{ env.PACKAGE_NAME }} $MANYLINUX_DOCKER_IMAGE /bin/bash -c "cd ${{ env.PACKAGE_NAME }} && /opt/python/cp311-cp311/bin/python3.11 -m build && mkdir dist/wheels && mv dist/*.whl dist/wheels && auditwheel repair dist/wheels/*.whl -w dist/ && rm -rf dist/wheels"
- name: Build package (macOS and Windows)
if: runner.os == 'macOS' || runner.os == 'Windows'
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@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: distribution-archives-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
combine:
needs: [test-python, test-c, 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@50769540e7f4bd5e21e526ee35c689e35e0d6874
with:
name: combined-distribution-archives
path: distribution-archives
publish:
if: startsWith(github.ref, 'refs/tags/')
needs: [test-python, test-c, build, combine]
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/bytecorefast
permissions:
id-token: write
env:
PACKAGE_NAME: bytecorefast
steps:
- uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871
- 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@f7600683efdcb7656dec5b29656edb7bc586e597
with:
verify-metadata: true
skip-existing: false
verbose: false
print-hash: true