Skip to content

Commit 552d866

Browse files
committed
🔧 Add a reusable CI workflow with linters
1 parent 73a54a8 commit 552d866

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ on:
1414
- cron: 1 0 * * * # Run daily at 0:01 UTC
1515

1616
jobs:
17+
lint:
18+
uses: ./.github/workflows/reusable-linters.yml
19+
1720
tests:
1821
if: >- # https://twitter.com/webKnjaZ/status/1308803017001652225
1922
github.event_name != 'create' ||
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
3+
name: 🚨linters
4+
5+
on: # yamllint disable-line rule:truthy
6+
workflow_call:
7+
8+
jobs:
9+
linters:
10+
name: >-
11+
${{ matrix.toxenv }}
12+
runs-on: ${{ matrix.os }}
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version:
17+
- 3.8
18+
os:
19+
- ubuntu-latest
20+
toxenv:
21+
- lint
22+
- build-dists
23+
24+
env:
25+
PY_COLORS: 1
26+
TOX_PARALLEL_NO_SPINNER: 1
27+
TOXENV: ${{ matrix.toxenv }}
28+
29+
steps:
30+
- uses: actions/checkout@v3
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: >-
36+
Calculate Python interpreter version hash value
37+
for use in the cache key
38+
id: calc_cache_key_py
39+
run: |
40+
from hashlib import sha512
41+
from os import environ
42+
from pathlib import Path
43+
from sys import version
44+
45+
FILE_APPEND_MODE = 'a'
46+
47+
hash = sha512(version.encode()).hexdigest()
48+
49+
with Path(environ['GITHUB_OUTPUT']).open(
50+
mode=FILE_APPEND_MODE,
51+
) as outputs_file:
52+
print(f'py_hash_key={hash}', file=outputs_file)
53+
shell: python
54+
- name: Set up pip cache
55+
uses: actions/cache@v3
56+
with:
57+
path: ~/.cache/pip
58+
key: >-
59+
${{ runner.os }}-pip-${{
60+
steps.calc_cache_key_py.outputs.py_hash_key }}-${{
61+
hashFiles('setup.cfg') }}-${{
62+
hashFiles('tox.ini') }}-${{
63+
hashFiles('pyproject.toml') }}-${{
64+
hashFiles('.pre-commit-config.yaml') }}
65+
restore-keys: |
66+
${{ runner.os }}-pip-${{
67+
steps.calc_cache_key_py.outputs.py_hash_key
68+
}}-
69+
${{ runner.os }}-pip-
70+
${{ runner.os }}-
71+
- name: Set up pre-commit cache
72+
uses: actions/cache@v3
73+
with:
74+
path: ~/.cache/pre-commit
75+
key: >-
76+
${{ runner.os }}-pre-commit-${{
77+
steps.calc_cache_key_py.outputs.py_hash_key }}-${{
78+
hashFiles('setup.cfg') }}-${{
79+
hashFiles('tox.ini') }}-${{
80+
hashFiles('pyproject.toml') }}-${{
81+
hashFiles('.pre-commit-config.yaml') }}
82+
- name: Install tox
83+
run: |
84+
python -m pip install --upgrade tox
85+
- name: Log installed dists
86+
run: |
87+
python -m pip freeze --all
88+
- name: Initialize tox envs
89+
run: |
90+
python -m tox --parallel auto --parallel-live --notest
91+
- name: Initialize pre-commit envs if needed
92+
run: >-
93+
test -d .tox/lint
94+
&& .tox/lint/bin/python -m pre_commit install-hooks
95+
|| :
96+
- name: Test with tox
97+
run: |
98+
python -m tox --parallel auto --parallel-live
99+
100+
...

0 commit comments

Comments
 (0)