Skip to content

Improve how mypy is run (#128) #261

Improve how mypy is run (#128)

Improve how mypy is run (#128) #261

Workflow file for this run

name: CI
on:
merge_group:
pull_request:
push:
# We need to explicitly include tags because otherwise when adding
# `branches-ignore` it will only trigger on branches.
tags:
- '*'
branches-ignore:
# Ignore pushes to merge queues.
# We only want to test the merge commit (`merge_group` event), the hashes
# in the push were already tested by the PR checks
- 'gh-readonly-queue/**'
workflow_dispatch:
env:
# Please make sure this version is included in the `matrix`, as the
# `matrix` section can't use `env`, so it must be entered manually
DEFAULT_PYTHON_VERSION: '3.11'
# It would be nice to be able to also define a DEFAULT_UBUNTU_VERSION
# but sadly `env` can't be used either in `runs-on`.
jobs:
nox:
name: Test with nox
strategy:
fail-fast: false
matrix:
os:
- ubuntu-20.04
python:
- "3.11"
nox-session:
# To speed things up a bit we use the special ci_checks_max session
# that uses the same venv to run multiple linting sessions
- "ci_checks_max"
- "pytest_min"
runs-on: ${{ matrix.os }}
steps:
- name: Print environment (debug)
run: env
- name: Fetch sources
uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
cache: 'pip'
- name: Install required Python packages
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev-noxfile]
pip freeze
- name: Create nox venv
env:
NOX_SESSION: ${{ matrix.nox-session }}
run: nox --install-only -e "$NOX_SESSION"
- name: Print pip freeze for nox venv (debug)
env:
NOX_SESSION: ${{ matrix.nox-session }}
run: |
. ".nox/$NOX_SESSION/bin/activate"
pip freeze
deactivate
- name: Run nox
env:
NOX_SESSION: ${{ matrix.nox-session }}
run: nox -R -e "$NOX_SESSION"
timeout-minutes: 60
build:
name: Build distribution packages
runs-on: ubuntu-20.04
steps:
- name: Fetch sources
uses: actions/checkout@v3
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
cache: 'pip'
- name: Install required Python packages
run: |
python -m pip install -U pip
python -m pip install -U build
pip freeze
- name: Build the source and binary distribution
run: python -m build
- name: Upload distribution files
uses: actions/upload-artifact@v3
with:
name: dist-packages
path: dist/
if-no-files-found: error
test-docs:
name: Test documentation website generation
if: github.event_name != 'push'
runs-on: ubuntu-20.04
steps:
- name: Fetch sources
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Git user and e-mail
uses: frequenz-floss/setup-git-user@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
cache: 'pip'
- name: Install build dependencies
run: |
python -m pip install -U pip
python -m pip install .[dev-mkdocs]
pip freeze
- name: Generate the documentation
env:
MIKE_VERSION: gh-${{ github.job }}
run: |
mike deploy $MIKE_VERSION
mike set-default $MIKE_VERSION
- name: Upload site
uses: actions/upload-artifact@v3
with:
name: docs-site
path: site/
if-no-files-found: error
publish-docs:
name: Publish documentation website to GitHub pages
needs: ["nox", "build"]
if: github.event_name == 'push'
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Calculate and check version
id: mike-metadata
env:
REF: ${{ github.ref }}
REF_NAME: ${{ github.ref_name }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
aliases=
version=
if test "$REF_NAME" = "$DEFAULT_BRANCH"
then
version=next
# A tag that starts with vX.Y or X.Y
elif echo "$REF" | grep -q '^refs/tags' && echo "$REF_NAME" | grep -Pq '^v?\d+\.\d+\.'
then
if echo "$REF_NAME" | grep -Pq -- "-" # pre-release
then
echo "::notice title=Documentation was not published::" \
"The tag '$REF_NAME' looks like a pre-release."
exit 0
fi
version=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+\.[0-9]+)\..*$/\1/') # vX.Y
major=$(echo "$REF_NAME" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
default_major=$(echo "$DEFAULT_BRANCH" | sed -r 's/^(v?[0-9]+)\..*$/\1/') # vX
aliases=$major
if test "$major" = "$default_major"
then
aliases="$aliases latest"
fi
else
echo "::warning title=Documentation was not published::" \
"Don't know how to handle '$REF' to make 'mike' version."
exit 0
fi
echo "version=$version" >> $GITHUB_OUTPUT
echo "aliases=$aliases" >> $GITHUB_OUTPUT
- name: Fetch sources
if: steps.mike-metadata.outputs.version
uses: actions/checkout@v3
with:
submodules: true
- name: Setup Git user and e-mail
if: steps.mike-metadata.outputs.version
uses: frequenz-floss/setup-git-user@v2
- name: Set up Python
if: steps.mike-metadata.outputs.version
uses: actions/setup-python@v4
with:
python-version: ${{ env.DEFAULT_PYTHON_VERSION }}
cache: 'pip'
- name: Install build dependencies
if: steps.mike-metadata.outputs.version
run: |
python -m pip install -U pip
python -m pip install .[dev-mkdocs]
pip freeze
- name: Fetch the gh-pages branch
if: steps.mike-metadata.outputs.version
run: git fetch origin gh-pages --depth=1
- name: Publish site
if: steps.mike-metadata.outputs.version
env:
VERSION: ${{ steps.mike-metadata.outputs.version }}
ALIASES: ${{ steps.mike-metadata.outputs.aliases }}
run: |
mike deploy --push --update-aliases "$VERSION" $ALIASES
create-github-release:
name: Create GitHub release
needs: ["publish-docs"]
# Create a release only on tags creation
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
permissions:
# We need write permissions on contents to create GitHub releases and on
# discussions to create the release announcement in the discussion forums
contents: write
discussions: write
runs-on: ubuntu-20.04
steps:
- name: Download distribution files
uses: actions/download-artifact@v3
with:
name: dist-packages
path: dist
- name: Download RELEASE_NOTES.md
run: |
set -ux
gh api \
-X GET \
-f ref=$REF \
-H "Accept: application/vnd.github.raw" \
"/repos/$REPOSITORY/contents/RELEASE_NOTES.md" \
> RELEASE_NOTES.md
env:
REF: ${{ github.ref }}
REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create GitHub release
run: |
set -ux
extra_opts=
if echo "$REF_NAME" | grep -- -; then extra_opts=" --prerelease"; fi
gh release create \
-R "$REPOSITORY" \
--notes-file RELEASE_NOTES.md \
--generate-notes \
$extra_opts \
$REF_NAME \
dist/*
env:
REF_NAME: ${{ github.ref_name }}
REPOSITORY: ${{ github.repository }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-pypi:
name: Publish packages to PyPI
needs: ["create-github-release"]
runs-on: ubuntu-20.04
permissions:
# For trusted publishing. See:
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
id-token: write
steps:
- name: Download distribution files
uses: actions/download-artifact@v3
with:
name: dist-packages
path: dist
- name: Publish the Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1