Repository navigation
120 lines (118 loc) · 4.97 KB
/
Copy pathpre-commit_common.yml
File metadata and controls
120 lines (118 loc) · 4.97 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Parameterised pre-commit
on:
workflow_call:
inputs:
platform:
required: true
type: string
description: The platform (ubuntu-latest, ubuntu-24.04, ...)
matrix:
required: true
type: string
description: The JSONified representation of the matrix. It should contain "python-versions"
jobs:
pre-commit:
runs-on: ${{ inputs.platform }}
strategy:
matrix: ${{ fromJSON(inputs.matrix) }}
name: Pre-commit python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 100
- uses: actions/setup-python@v7
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements.txt
mypy-requirements.txt
dev-requirements.txt
architecture: x64
- name: 'Install pypy pre-conditions'
if: matrix.python-version == 'pypy3.10' || matrix.python-version == 'pypy3.11' || matrix.python-version == 'pypy3.12'
run: |
sudo apt update
sudo apt install -y libxml2-dev libxslt-dev zlib1g-dev
- name: 'Install requirements (standard or constraints ${{ matrix.python-version }})'
id: install_reqs
run: |
pip install --upgrade pip wheel
constraints_file="constraints/constraints-${{ matrix.python-version }}.txt"
regen_constraints=
if [ -f "$constraints_file" ] ; then
at="$(git --no-pager log -p -1 "--format=tformat:%at" --no-patch -- "$constraints_file")"
dat="$(git --no-pager log -p -1 "--format=tformat:%at" --no-patch -- "requirements.txt")"
if [ "$at" -lt "$dat" ] ; then
regen_constraints=true
fi
else
regen_constraints=true
fi
if [ -n "$regen_constraints" ] ; then
pip install -r requirements.txt
pip freeze > "$constraints_file"
grep -vF git+ "$constraints_file" > "$constraints_file"-relaxed
else
grep -vF git+ "$constraints_file" > "$constraints_file"-relaxed
pip install -r requirements.txt -c "$constraints_file"-relaxed
fi
echo "constraints_file_relaxed=${constraints_file}-relaxed" >> "$GITHUB_OUTPUT"
- name: 'Install development requirements'
run: |
pip install -r dev-requirements.txt -r mypy-requirements.txt -c ${{ steps.install_reqs.outputs.constraints_file_relaxed }}
- name: MyPy cache
uses: actions/cache@v6
with:
path: '.mypy_cache/[0-9]*'
key: mypy-${{ matrix.python-version }}
- name: 'pre-commit'
uses: pre-commit/action@v3.0.1
# if: ${{ matrix.python-version != '3.6' }}
with:
extra_args: --all -c .pre-commit-config.yaml
# - name: 'pre-commit (custom Python ${{ matrix.python-version }})'
# uses: pre-commit/action@v3.0.0
# if: ${{ matrix.python-version == '3.6' }}
# with:
# extra_args: --all -c .pre-commit-config-gh-${{ matrix.python-version }}.yaml
- name: Get cached transitive dependencies licences report
id: cache-pilosus-output-restore
uses: actions/cache/restore@v6
with:
path: |
pilosus-report.md
key: pilosus-report-${{ matrix.python-version }}_${{ hashFiles(steps.install_reqs.outputs.constraints_file_relaxed) }}
- name: Get transitive dependencies licences
id: license_check_print_report
if: steps.cache-pilosus-output-restore.outputs.cache-hit != 'true'
uses: pilosus/action-pip-license-checker@v3.1.0
with:
requirements: constraints/constraints-${{ matrix.python-version }}.txt
- name: Write licences report to file
if: steps.cache-pilosus-output-restore.outputs.cache-hit != 'true'
run: |
echo "${{ steps.license_check_print_report.outputs.report }}" > pilosus-report.md
- name: Preserve licences report
if: steps.cache-pilosus-output-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: |
pilosus-report.md
key: pilosus-report-${{ matrix.python-version }}_${{ hashFiles(steps.install_reqs.outputs.constraints_file_relaxed) }}
- name: Check transitive dependencies licences
id: license_check_report
if: steps.cache-pilosus-output-restore.outputs.cache-hit != 'true'
uses: pilosus/action-pip-license-checker@v3.1.0
with:
requirements: constraints/constraints-${{ matrix.python-version }}.txt
fail: 'StrongCopyleft'
exclude: '(?i)^(pylint|dulwich|docutils).*'
- name: Print licences report
if: ${{ always() }}
run: cat pilosus-report.md
- uses: actions/upload-artifact@v7
with:
name: pre-commit-${{ matrix.python-version }}
retention-days: 2
path: constraints/constraints-${{ matrix.python-version }}.txt