💚 Fix-add "tool.semantic_release.commit_parser_options" c… #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will install Python dependencies, run tests and lint with a single version of Python | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: "CI & CD" | |
on: | |
push: | |
branches: [ "master", "development" ] | |
pull_request: | |
branches: [ "master", "development" ] | |
permissions: | |
contents: write | |
id-token: write | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
os: ${{ steps.setup-matrix.outputs.os }} | |
python-version: ${{ steps.setup-matrix.outputs.python-version }} | |
steps: | |
- name: Determine event type and set matrix | |
id: setup-matrix | |
run: | | |
if [ "${{ github.event_name }}" == "push" ]; then | |
echo "os=['ubuntu-latest']" >> "$GITHUB_OUTPUT" | |
echo "python-version=['3.10']" >> "$GITHUB_OUTPUT" | |
elif [ "${{ github.event_name }}" == "pull_request" ]; then | |
echo "os=['ubuntu-latest','macos-latest','windows-latest']" >> "$GITHUB_OUTPUT" | |
echo "python-version=['3.10','3.11','3.x']" >> "$GITHUB_OUTPUT" | |
fi | |
CI: | |
needs: setup | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: ${{ fromJSON(needs.setup.outputs.os) }} | |
python-version: ${{ fromJSON(needs.setup.outputs.python-version) }} | |
include: | |
- os: ubuntu-latest | |
python-version: "3.10" | |
representative: True | |
defaults: | |
run: | |
shell: bash | |
steps: | |
- name: Check-out repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install poetry | |
uses: snok/install-poetry@v1 | |
- name: Install package | |
run: poetry install --with dev | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
echo "Linting errors in picometer/tests:" | |
poetry run flake8 ./picometer --count --select=E9,F63,F7,F82 --show-source --statistics | |
poetry run flake8 ./tests --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
echo "Linting warnings in picometer/tests:" | |
poetry run flake8 ./picometer --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics | |
poetry run flake8 ./tests --count --exit-zero --max-complexity=10 --max-line-length=88 --statistics | |
- name: Test with pytest | |
run: poetry run pytest tests/ --cov=picometer --cov-report=xml | |
- name: Use Codecov to track coverage | |
uses: codecov/codecov-action@v4 | |
if: ${{ matrix.representative }} | |
env: | |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
with: | |
files: ./coverage.xml # coverage report | |
- name: Build documentation | |
run: poetry run make html --directory docs/ | |
if: ${{ matrix.representative }} | |
CD: | |
# Only run this job if the "CI" job passes | |
needs: CI | |
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
# Set up operating system | |
runs-on: ubuntu-latest | |
# Define job steps | |
steps: | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Downgrade pip to version before 24.1 | |
run: pip install "pip<24.1" --force-reinstall # Rm when hikari 0.2.4 is out | |
- name: Check-out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ssh-key: ${{ secrets.CONTINUOUS_DEPLOYMENT_KEY }} | |
- name: Use Python Semantic Release to prepare release | |
id: release | |
uses: python-semantic-release/python-semantic-release@v9 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to TestPyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: steps.release.outputs.released == 'true' | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
password: ${{ secrets.TEST_PYPI_PICOMETER_API_TOKEN }} | |
- name: Test install from TestPyPI | |
run: | | |
pip install \ | |
--index-url https://test.pypi.org/simple/ \ | |
--extra-index-url https://pypi.org/simple \ | |
picometer | |
- name: Publish to PyPI | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
if: steps.release.outputs.released == 'true' | |
with: | |
password: ${{ secrets.PYPI_PICOMETER_API_TOKEN }} | |
- name: Publish package distributions to GitHub Releases | |
uses: python-semantic-release/publish-action@v9 | |
if: steps.release.outputs.released == 'true' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} |