Skip to content

Commit a0da3b1

Browse files
bashirpartoviBashir Partovi
andauthored
FIX fixing pre-commit windows job to use cache (microsoft#976)
Co-authored-by: Bashir Partovi <bpartovi@microsoft.com>
1 parent 36fb2d3 commit a0da3b1

1 file changed

Lines changed: 57 additions & 12 deletions

File tree

.github/workflows/build_and_test.yml

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
name: build_and_test
44

5+
env:
6+
PRE_COMMIT_PYTHON_VERSION: '3.11'
7+
58
on:
69
push:
710
branches:
@@ -19,14 +22,8 @@ concurrency:
1922
cancel-in-progress: true
2023

2124
jobs:
22-
# Pre-commit job runs only once on Ubuntu
23-
pre-commit:
24-
strategy:
25-
fail-fast: false
26-
matrix:
27-
os: [ubuntu-latest, windows-latest]
28-
python-version: ["3.11"]
29-
runs-on: ${{ matrix.os }}
25+
pre-commit-linux:
26+
runs-on: ubuntu-latest
3027

3128
env:
3229
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip
@@ -36,15 +33,14 @@ jobs:
3633

3734
- uses: actions/setup-python@v3
3835
with:
39-
python-version: ${{ matrix.python-version }}
40-
36+
python-version: ${{ env.PRE_COMMIT_PYTHON_VERSION }}
4137
- name: Cache pip packages
4238
uses: actions/cache@v3
4339
with:
4440
path: ${{ env.PIP_CACHE_DIR }}
45-
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml') }}
41+
key: ${{ runner.os }}-pip-${{ env.PRE_COMMIT_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
4642
restore-keys: |
47-
${{ runner.os }}-pip-${{ matrix.python-version }}-
43+
${{ runner.os }}-pip-${{ env.PRE_COMMIT_PYTHON_VERSION }}-
4844
${{ runner.os }}-pip-
4945
5046
- name: Cache pre-commit environments
@@ -72,6 +68,55 @@ jobs:
7268
run: |
7369
pre-commit run --all-files
7470
71+
pre-commit-windows:
72+
runs-on: windows-latest
73+
env:
74+
PIP_CACHE_DIR: ${{ github.workspace }}\.cache\pip
75+
defaults:
76+
run:
77+
shell: pwsh
78+
steps:
79+
- uses: actions/checkout@v3
80+
81+
- uses: actions/setup-python@v3
82+
with:
83+
python-version: ${{ env.PRE_COMMIT_PYTHON_VERSION }}
84+
85+
- name: Cache pip packages
86+
uses: actions/cache@v3
87+
with:
88+
path: ${{ env.PIP_CACHE_DIR }}
89+
key: ${{ runner.os }}-pip-${{ env.PRE_COMMIT_PYTHON_VERSION }}-${{ hashFiles('pyproject.toml') }}
90+
restore-keys: |
91+
${{ runner.os }}-pip-${{ env.PRE_COMMIT_PYTHON_VERSION }}-
92+
${{ runner.os }}-pip-
93+
94+
- name: Cache pre-commit environments
95+
uses: actions/cache@v3
96+
with:
97+
path: ~/.cache/pre-commit
98+
key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}
99+
restore-keys: |
100+
pre-commit-${{ runner.os }}-
101+
102+
- name: Upgrade pip and setuptools
103+
run: python -m pip install --upgrade pip setuptools packaging
104+
105+
- name: Install dev extras
106+
run: |
107+
pip install --cache-dir "$env:PIP_CACHE_DIR" '.[dev,all]'
108+
109+
- name: Run pre-commit incrementally (on PR)
110+
if: github.event_name == 'pull_request'
111+
run: |
112+
git fetch origin main
113+
pre-commit run --from-ref origin/main --to-ref HEAD
114+
115+
- name: Run pre-commit fully (on main)
116+
if: github.ref == 'refs/heads/main'
117+
run: |
118+
pre-commit run --all-files
119+
75120
# Main job runs only if pre-commit succeeded
76121
main-job:
77122
strategy:

0 commit comments

Comments
 (0)