Migrate to poetry #414
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
name: Build and Test | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- closed | |
jobs: | |
matrix-builder: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
inverted_matrix: ${{ steps.set-matrix.outputs.inverted_matrix }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: 3.9 | |
architecture: x64 | |
- id: set-matrix | |
env: | |
PY_VERSIONS: "[\"3.7\", \"3.8\", \"3.9\", \"3.10\", \"3.11\", \"3.12\", \"pypy-3.9\", \"pypy-3.10\"]" | |
OS_NAMES: "[\"ubuntu-20.04\"]" #, windows-latest, macOS-latest] | |
CELERY_VERSIONS: "[\">=4.0.0,<5.0.0\", \">=5.0.0,<6.0.0\"]" | |
run: | | |
python -m pip install --upgrade pip | |
MATRIX=$(python .github/workflows/resolve_versions.py matrix -c "$PY_VERSIONS" -o "$OS_NAMES" -n "celery" -s "$CELERY_VERSIONS") | |
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT | |
INV_MATRIX=$(python .github/workflows/resolve_versions.py matrix -c "$PY_VERSIONS" -o "$OS_NAMES" -n "celery" -s "$CELERY_VERSIONS" --invert) | |
echo "inverted_matrix=$INV_MATRIX" >> $GITHUB_OUTPUT | |
unsupported: | |
name: Skipping on Python ${{ matrix.python-version }} and ${{ matrix.os }} with celery${{ matrix.celery }} | |
needs: matrix-builder | |
strategy: | |
matrix: ${{ fromJSON(needs.matrix-builder.outputs.inverted_matrix) }} | |
fail-fast: false | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prepare badges | |
id: badges | |
run: | | |
CELERY_MAJOR=$(echo "${{ matrix.celery }}" | sed -r 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/') | |
echo "celery=${CELERY_MAJOR}" >> $GITHUB_OUTPUT | |
echo "source_name=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT | |
echo "source_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
echo "source_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
[[ "${{ matrix.python-version }}" == pypy* ]] \ | |
&& echo "python=$(echo "${{ matrix.python-version }}" | cut -d '-' -f1-2)" >> $GITHUB_OUTPUT \ | |
|| echo "python=${{ matrix.python-version }}" >> $GITHUB_OUTPUT | |
[[ "${{ matrix.os }}" == ubuntu* ]] && echo "platform=linux" >> $GITHUB_OUTPUT || echo "Not on linux" | |
[[ "${{ matrix.os }}" == windows* ]] && echo "platform=windows" >> $GITHUB_OUTPUT || echo "Not on window" | |
[[ "${{ matrix.os }}" == macOS* ]] && echo "platform=apple" >> $GITHUB_OUTPUT || echo "Not on macOS" | |
- name: Badge Creation (master) (unsupported) | |
uses: RubbaBoy/[email protected] | |
if: github.event.pull_request.merged == true && steps.badges.outcome == 'success' | |
with: | |
NAME: m_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub (in master)" | |
STATUS: "Unsupported" | |
COLOR: yellow | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} | |
- name: Badge Creation (tag) (unsupported) | |
uses: RubbaBoy/[email protected] | |
if: github.event_name == 'push' && github.ref_type == 'tag' && steps.badges.outcome == 'success' | |
with: | |
NAME: ${{ steps.badges.outputs.source_tag }}_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub ${{ steps.badges.outputs.source_tag }}" | |
STATUS: "Unsupported" | |
COLOR: yellow | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} | |
build: | |
name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }} with celery${{ matrix.celery }} | |
needs: matrix-builder | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: ${{ fromJSON(needs.matrix-builder.outputs.matrix) }} | |
fail-fast: false | |
timeout-minutes: 5 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
architecture: x64 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1 | |
with: | |
# Use 1.5.1 for Python 3.7, otherwise use latest. | |
version: ${{ matrix.python-version == '3.7' && '1.5.1' || 'latest' }} | |
virtualenvs-create: true | |
virtualenvs-in-project: true | |
- name: Load cached venv | |
id: cached-poetry-dependencies | |
uses: actions/cache@v3 | |
with: | |
path: .venv | |
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ matrix.celery }}-${{ hashFiles('**/poetry.lock') }} | |
- name: Install dependencies | |
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | |
run: | | |
poetry install --no-interaction --no-root --with=ci --with=dev | |
poetry add "celery${{ matrix.celery }}" | |
- name: Install project | |
run: poetry install --no-interaction | |
- name: Check with black | |
run: poetry run black --check . | |
- name: Check with mypy | |
if: ${{ !startsWith(matrix.python-version, 'pypy') }} | |
run: poetry run mypy | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude .github --exclude .venv | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude .github --exclude .venv | |
- name: Test with pytest | |
run: | | |
poetry run coverage run -m pytest -v -s tests | |
poetry run coverage report | |
- name: Code Climate Coverage Action | |
uses: paambaati/[email protected] | |
env: | |
# According to CodeClimate documentation, this is not considered a sensitive value. | |
# https://docs.codeclimate.com/docs/finding-your-test-coverage-token#regenerating-a-repos-test-reporter-id | |
CC_TEST_REPORTER_ID: 4967416d540739937e0eebfb13a3cf2f8dfbddd762f2b1ec800e83d18fb5efbb | |
with: | |
coverageCommand: poetry run coverage xml | |
debug: true | |
- name: Prepare badges | |
id: badges | |
run: | | |
CELERY_MAJOR=$(echo "${{ matrix.celery }}" | sed -r 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/') | |
echo "celery=${CELERY_MAJOR}" >> $GITHUB_OUTPUT | |
echo "source_name=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT | |
echo "source_branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | |
echo "source_tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
[[ "${{ matrix.python-version }}" == pypy* ]] \ | |
&& echo "python=$(echo "${{ matrix.python-version }}" | cut -d '-' -f1-2)" >> $GITHUB_OUTPUT \ | |
|| echo "python=${{ matrix.python-version }}" >> $GITHUB_OUTPUT | |
[[ "${{ matrix.os }}" == ubuntu* ]] && echo "platform=linux" >> $GITHUB_OUTPUT || echo "Not on linux" | |
[[ "${{ matrix.os }}" == windows* ]] && echo "platform=windows" >> $GITHUB_OUTPUT || echo "Not on window" | |
[[ "${{ matrix.os }}" == macOS* ]] && echo "platform=apple" >> $GITHUB_OUTPUT || echo "Not on macOS" | |
- name: Badge Creation (master) (success) | |
uses: RubbaBoy/[email protected] | |
if: github.event.pull_request.merged == true && steps.badges.outcome == 'success' | |
with: | |
NAME: m_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub (in master)" | |
STATUS: "Supported" | |
COLOR: green | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} | |
- name: Badge Creation (master) (failure) | |
uses: RubbaBoy/[email protected] | |
if: github.event.pull_request.merged == true && steps.badges.outcome != 'success' | |
with: | |
NAME: m_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub (in master)" | |
STATUS: "Failed" | |
COLOR: red | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} | |
- name: Badge Creation (tag) (success) | |
uses: RubbaBoy/[email protected] | |
if: github.event_name == 'push' && github.ref_type == 'tag' && steps.badges.outcome == 'success' | |
with: | |
NAME: ${{ steps.badges.outputs.source_tag }}_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub ${{ steps.badges.outputs.source_tag }}" | |
STATUS: "Supported" | |
COLOR: green | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} | |
- name: Badge Creation (tag) (failure) | |
uses: RubbaBoy/[email protected] | |
if: github.event_name == 'push' && github.ref_type == 'tag' && steps.badges.outcome != 'success' | |
with: | |
NAME: ${{ steps.badges.outputs.source_tag }}_${{ steps.badges.outputs.platform }}_${{ steps.badges.outputs.python }}_celery${{ steps.badges.outputs.celery }} | |
ICON: 'https://simpleicons.vercel.app/${{ steps.badges.outputs.platform }}/ffffff' | |
LABEL: "celery-pubsub ${{ steps.badges.outputs.source_tag }}" | |
STATUS: "Failed" | |
COLOR: red | |
GITHUB_TOKEN: ${{ secrets.BADGES_TOKEN }} |