Skip to content

Commit

Permalink
Merge pull request #70 from smarie/feature/69_virtualenv
Browse files Browse the repository at this point in the history
Switched nox backend to virtualenv and fixed compat with pytest8
  • Loading branch information
smarie committed Mar 15, 2024
2 parents 2c934ec + c2d7846 commit e6f78e2
Show file tree
Hide file tree
Showing 13 changed files with 532 additions and 379 deletions.
127 changes: 79 additions & 48 deletions .github/workflows/base.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# .github/workflows/base.yml
name: Build
on:
# this one is to trigger the workflow manually from the interface
workflow_dispatch:

push:
tags:
- '*'
Expand All @@ -9,24 +12,32 @@ on:
pull_request:
branches:
- main

defaults:
run:
shell: bash -l {0}

jobs:
# pre-job to read nox tests matrix - see https://stackoverflow.com/q/66747359/7262247
list_nox_test_sessions:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Install python 3.9
uses: actions/setup-python@v5.0.0
with:
python-version: 3.7
python-version: 3.9
architecture: x64

- name: Install noxfile requirements
shell: bash -l {0}
run: pip install -r noxfile-requirements.txt

- name: List 'tests' nox sessions
- name: List 'tests' nox sessions and required python versions
id: set-matrix
run: echo "::set-output name=matrix::$(nox -s gha_list -- tests)"
run: echo "::set-output name=matrix::$(nox -s gha_list -- -s tests -v)"

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }} # save nox sessions list to outputs

Expand All @@ -35,45 +46,72 @@ jobs:
strategy:
fail-fast: false
matrix:
# see https://github.com/actions/setup-python/issues/544
# os: [ ubuntu-20.04 ]
os: [ ubuntu-latest ] # , macos-latest, windows-latest]
# all nox sessions: manually > dynamically from previous job
# nox_session: ["tests-2.7(env='pytest2.x')", "tests-3.7(env='pytest-latest')"]
nox_session: ${{ fromJson(needs.list_nox_test_sessions.outputs.matrix) }}

name: ${{ matrix.os }} ${{ matrix.nox_session }} # ${{ matrix.name_suffix }}
name: ${{ matrix.os }} ${{ matrix.nox_session.python }} ${{ matrix.nox_session.session }} # ${{ matrix.name_suffix }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Install python ${{ matrix.nox_session.python }} for tests
uses: MatteoH2O1999/setup-python@v3.0.0 # actions/setup-python@v5.0.0
id: set-py
with:
python-version: ${{ matrix.nox_session.python }}
architecture: x64
allow-build: info
cache-build: true

# Conda install
- name: Install conda v3.7
uses: conda-incubator/setup-miniconda@v2
- name: Install python 3.12 for nox
uses: actions/setup-python@v5.0.0
with:
# auto-update-conda: true
python-version: 3.7
activate-environment: noxenv
- run: conda info
shell: bash -l {0} # so that conda works
- run: conda list
shell: bash -l {0} # so that conda works

# Nox install + run
python-version: 3.12
architecture: x64

- name: pin virtualenv==20.15.1 in old python versions
# pinned to keep compatibility with old versions, see https://github.com/MatteoH2O1999/setup-python/issues/28#issuecomment-1745613621
if: contains(fromJson('["2.7", "3.5", "3.6"]'), matrix.nox_session.python )
run: sed -i "s/virtualenv/virtualenv==20.15.1/g" noxfile-requirements.txt

- name: Install noxfile requirements
shell: bash -l {0} # so that conda works
run: pip install -r noxfile-requirements.txt
- run: conda list
shell: bash -l {0} # so that conda works
- run: nox -s "${{ matrix.nox_session }}"
shell: bash -l {0} # so that conda works

- name: Run nox session ${{ matrix.nox_session.session }}
run: nox -s "${{ matrix.nox_session.session }}" -v

# Share ./docs/reports so that they can be deployed with doc in next job
- name: Share reports with other jobs
# if: matrix.nox_session == '...': not needed, if empty wont be shared
uses: actions/upload-artifact@master
# if: matrix.nox_session == '...': not needed, if empty won't be shared
uses: actions/upload-artifact@v4.3.0
with:
name: reports_dir
path: ./docs/reports

build_doc:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4.1.1

- name: Install python 3.9 for nox
uses: actions/setup-python@v5.0.0
with:
python-version: 3.9
architecture: x64

- name: Install noxfile requirements
run: pip install -r noxfile-requirements.txt

- name: Build the doc including example gallery
run: nox -s docs -- build

publish_release:
needs: run_all_tests
runs-on: ubuntu-latest
Expand All @@ -84,43 +122,37 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

- uses: actions/checkout@v2
- name: Checkout with no depth
uses: actions/checkout@v4.1.1
with:
fetch-depth: 0 # so that gh-deploy works

- name: Install python 3.9 for nox
uses: actions/setup-python@v5.0.0
with:
python-version: 3.9
architecture: x64

# 1) retrieve the reports generated previously
- name: Retrieve reports
uses: actions/download-artifact@master
uses: actions/download-artifact@v4.1.1
with:
name: reports_dir
path: ./docs/reports

# Conda install
- name: Install conda v3.7
uses: conda-incubator/setup-miniconda@v2
with:
# auto-update-conda: true
python-version: 3.7
activate-environment: noxenv
- run: conda info
shell: bash -l {0} # so that conda works
- run: conda list
shell: bash -l {0} # so that conda works

# Nox install
- name: Install noxfile requirements
shell: bash -l {0} # so that conda works
run: pip install -r noxfile-requirements.txt
- run: conda list
shell: bash -l {0} # so that conda works

# 5) Run the flake8 report and badge
- name: Run flake8 analysis and generate corresponding badge
run: nox -s flake8

# -------------- only on Ubuntu + MAIN PUSH (no pull request, no tag) -----------

# 5) Publish the doc and test reports
- name: \[not on TAG\] Publish documentation, tests and coverage reports
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads') # startsWith(matrix.os,'ubuntu')
shell: bash -l {0} # so that conda works
run: nox -s publish

# 6) Publish coverage report
Expand All @@ -135,7 +167,7 @@ jobs:
EOF
- name: \[not on TAG\] Publish coverage report
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads')
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4.0.1
with:
files: ./docs/reports/coverage/coverage.xml

Expand All @@ -144,13 +176,12 @@ jobs:
# 7) Create github release and build the wheel
- name: \[TAG only\] Build wheel and create github release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
shell: bash -l {0} # so that conda works
run: nox -s release -- ${{ secrets.GITHUB_TOKEN }}

# 8) Publish the wheel on PyPi
- name: \[TAG only\] Deploy on PyPi
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: GitHub Actions Version Updater

# Controls when the action will run.
on:
workflow_dispatch:
schedule:
# Automatically run on every first day of the month
- cron: '0 0 1 * *'

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4.1.1
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.WORKFLOW_SECRET }}

- name: Run GitHub Actions Version Updater
uses: saadmk11/github-actions-version-updater@v0.8.1
with:
# [Required] Access token with `workflow` scope.
token: ${{ secrets.WORKFLOW_SECRET }}
16 changes: 16 additions & 0 deletions ci_tools/flake8-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
setuptools_scm>=3,<4
flake8>=3.6,<4
flake8-html>=0.4,<1
flake8-bandit>=2.1.1,<3
bandit<1.7.3 # temporary until this is fixed https://github.com/tylerwince/flake8-bandit/issues/21
flake8-bugbear>=20.1.0,<21.0.0
flake8-docstrings>=1.5,<2
flake8-print>=3.1.1,<4
flake8-tidy-imports>=4.2.1,<5
flake8-copyright==0.2.2 # Internal forked repo to fix an issue, keep specific version
pydocstyle>=5.1.1,<6
pycodestyle>=2.6.0,<3
mccabe>=0.6.1,<1
naming>=0.5.1,<1
pyflakes>=2.2,<3
genbadge[flake8]
112 changes: 0 additions & 112 deletions ci_tools/generate-junit-badge.py

This file was deleted.

Loading

0 comments on commit e6f78e2

Please sign in to comment.