Skip to content

Commit 12a0033

Browse files
authored
ci: optimize workflow with caching and concurrency (#459)
1 parent 7ed521d commit 12a0033

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

.github/workflows/ci.yml

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
812

913
permissions:
1014
contents: read
@@ -17,67 +21,63 @@ jobs:
1721
matrix:
1822
os: [ubuntu-latest, macos-latest, windows-latest]
1923
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
20-
2124
include:
2225
- os: ubuntu-latest
2326
python-version: "3.13"
2427
coverage: true
2528

2629
steps:
27-
- name: Harden the runner (Audit all outbound calls)
28-
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
29-
with:
30-
egress-policy: audit
31-
32-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
30+
- name: Harden the runner (Audit all outbound calls)
31+
uses: step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
32+
with:
33+
egress-policy: audit
3334

34-
- name: Set up Python
35-
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
36-
with:
37-
python-version: ${{ matrix.python-version }}
35+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3836

39-
- name: Locate pip cache
40-
id: pip-cache
41-
shell: bash
42-
run: echo "dir=$(python -m pip cache dir)" >> "$GITHUB_OUTPUT"
37+
- name: Set up Python
38+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
39+
with:
40+
python-version: ${{ matrix.python-version }}
41+
cache: 'pip'
4342

44-
- name: Cache pip
45-
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
46-
with:
47-
path: ${{ steps.pip-cache.outputs.dir }}
48-
key: ${{ runner.os }}-pip-${{ hashFiles('pyproject.toml') }}
49-
restore-keys: ${{ runner.os }}-pip-
43+
- name: Install dependencies
44+
run: |
45+
python -m pip install --upgrade pip
46+
python -m pip install ".[dev,server]"
5047
51-
- name: Install dependencies
52-
run: |
53-
python -m pip install --upgrade pip
54-
python -m pip install ".[dev,server]"
48+
- name: Cache pytest results
49+
uses: actions/cache@v4
50+
with:
51+
path: .pytest_cache
52+
key: ${{ runner.os }}-pytest-${{ matrix.python-version }}-${{ hashFiles('**/pytest.ini') }}
53+
restore-keys: |
54+
${{ runner.os }}-pytest-${{ matrix.python-version }}-
5555
56-
- name: Run tests
57-
if: ${{ matrix.coverage != true }}
58-
run: pytest
56+
- name: Run tests
57+
if: ${{ matrix.coverage != true }}
58+
run: pytest
5959

60-
- name: Run tests and collect coverage
61-
if: ${{ matrix.coverage == true }}
62-
run: |
63-
pytest \
64-
--cov=gitingest \
65-
--cov=server \
66-
--cov-branch \
67-
--cov-report=xml \
68-
--cov-report=term
60+
- name: Run tests and collect coverage
61+
if: ${{ matrix.coverage == true }}
62+
run: |
63+
pytest \
64+
--cov=gitingest \
65+
--cov=server \
66+
--cov-branch \
67+
--cov-report=xml \
68+
--cov-report=term
6969
70-
- name: Upload coverage to Codecov
71-
if: ${{ matrix.coverage == true }}
72-
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
73-
with:
74-
token: ${{ secrets.CODECOV_TOKEN }}
75-
files: coverage.xml
76-
flags: ${{ matrix.os }}-py${{ matrix.python-version }}
77-
name: codecov-${{ matrix.os }}-${{ matrix.python-version }}
78-
fail_ci_if_error: true
79-
verbose: true
70+
- name: Upload coverage to Codecov
71+
if: ${{ matrix.coverage == true }}
72+
uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
73+
with:
74+
token: ${{ secrets.CODECOV_TOKEN }}
75+
files: coverage.xml
76+
flags: ${{ matrix.os }}-py${{ matrix.python-version }}
77+
name: codecov-${{ matrix.os }}-${{ matrix.python-version }}
78+
fail_ci_if_error: true
79+
verbose: true
8080

81-
- name: Run pre-commit hooks
82-
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
83-
if: ${{ matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest' }}
81+
- name: Run pre-commit hooks
82+
uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1
83+
if: ${{ matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest' }}

0 commit comments

Comments
 (0)