forked from cjolowicz/cookiecutter-hypermodern-python
-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (105 loc) · 4.24 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Tests
on:
push:
branches:
- main
- master
pull_request:
jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- { python-version: "3.12", os: ubuntu-latest }
- { python-version: "3.12", os: windows-latest }
- { python-version: "3.12", os: macos-latest }
- { python-version: "3.11", os: ubuntu-latest }
- { python-version: "3.10", os: ubuntu-latest }
name: Python ${{ matrix.python-version }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
path: ssb-pypitemplate
- uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install tools using pip
working-directory: ${{ github.workspace }}/ssb-pypitemplate
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pipx install --pip-args=--constraint=${{ github.workspace }}/ssb-pypitemplate/.github/workflows/constraints.txt cookiecutter
pipx install --pip-args=--constraint=${{ github.workspace }}/ssb-pypitemplate/.github/workflows/constraints.txt nox
pipx inject --pip-args=--constraint=${{ github.workspace }}/ssb-pypitemplate/.github/workflows/constraints.txt nox nox-poetry
pipx install --pip-args=--constraint=${{ github.workspace }}/ssb-pypitemplate/.github/workflows/constraints.txt poetry
- name: Generate project using Cookiecutter
run: |
cookiecutter --no-input ssb-pypitemplate project_name=ssb-library
- name: Create poetry.lock file
run: poetry update --lock
working-directory: ssb-library
- name: Create git repository
if: matrix.os != 'windows-latest'
run: |
git init
git config --local user.name "GitHub Action"
git config --local user.email "[email protected]"
git add .
git commit --message="Initial import"
working-directory: ssb-library
- name: Create git repository (Windows)
if: matrix.os == 'windows-latest'
run: |
git init
git config --local user.name "GitHub Action"
git config --local user.email "[email protected]"
# https://github.com/cookiecutter/cookiecutter/issues/405
$ErrorActionPreference = "Continue"
git add .
$ErrorActionPreference = "Stop"
git add --renormalize .
git commit --message="Initial import"
working-directory: ssb-library
- name: Compute cache key for pre-commit
if: matrix.os != 'windows-latest'
id: cache_key
shell: python
run: |
import hashlib
import subprocess
import sys
python = "py{}.{}".format(*sys.version_info[:2])
payload = sys.version.encode() + sys.executable.encode()
digest = hashlib.sha256(payload).hexdigest()
result = "${{ runner.os }}-{}-{}-pre-commit".format(python, digest[:8])
cmd = f'echo "result={result}" >> $GITHUB_OUTPUT'
subprocess.run(cmd, shell=True)
- uses: actions/cache@v4
if: matrix.os != 'windows-latest'
with:
path: ~/.cache/pre-commit
key: ${{ steps.cache_key.outputs.result }}-${{ hashFiles('ssb-library/.pre-commit-config.yaml') }}
restore-keys: |
${{ steps.cache_key.outputs.result }}-
- name: Run test suite using Nox
run: nox --force-color --python=${{ matrix.python-version }}
working-directory: ssb-library
- name: Install dependencies using Poetry
run: poetry install --ansi
working-directory: ssb-library
doc:
name: Build documentation & check links
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/[email protected]
with:
python-version: "3.12"
- run: |
pip install --constraint=${{ github.workspace }}/.github/workflows/constraints.txt pip
pip install --constraint=${{ github.workspace }}/.github/workflows/constraints.txt nox
- name: Build documentation
run: nox --force-color --session=docs
- name: Check links
run: nox --force-color --session=linkcheck