Skip to content

Commit 3959d1e

Browse files
authored
Merge pull request #1804 from equalizedigital/chore/optimize-gha-caching
Optimize GitHub Actions caching and workflow triggers
2 parents 4a9100f + b4f3a6f commit 3959d1e

8 files changed

Lines changed: 66 additions & 43 deletions

File tree

.github/workflows/build-plugin-with-ref.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ jobs:
8181
cache-dependency-path: package-lock.json
8282

8383
- name: Cache node_modules
84+
id: cache-node-modules
8485
uses: actions/cache@v4
8586
with:
8687
path: node_modules
87-
key: node-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
88+
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
8889
restore-keys: |
89-
node-${{ runner.os }}-
90+
${{ runner.os }}-node_modules-
9091
9192
- name: Set up PHP
9293
uses: shivammathur/setup-php@v2
@@ -95,21 +96,21 @@ jobs:
9596
tools: composer
9697
coverage: none
9798

99+
- name: Cache Composer dependencies
100+
uses: actions/cache@v4
101+
with:
102+
path: vendor
103+
key: ${{ runner.os }}-composer-vendor-${{ hashFiles('**/composer.lock') }}
104+
restore-keys: |
105+
${{ runner.os }}-composer-vendor-
106+
98107
- name: Install Composer dependencies
99108
run: |
100-
if [ -f composer.json ]; then composer install --no-dev --prefer-dist --no-progress --no-interaction; else echo "No composer.json"; fi
109+
if [ -f composer.json ]; then composer install --no-dev --prefer-dist --prefer-offline --no-progress --no-interaction; else echo "No composer.json"; fi
101110
102111
- name: Install npm dependencies
103-
run: |
104-
if [ -f package.json ]; then
105-
if [ -d node_modules ]; then
106-
echo "node_modules cache hit, skipping install"
107-
else
108-
npm ci --prefer-offline --no-audit
109-
fi
110-
else
111-
echo "No package.json"
112-
fi
112+
if: steps.cache-node-modules.outputs.cache-hit != 'true' && hashFiles('package.json') != ''
113+
run: npm ci --prefer-offline --no-audit
113114

114115
- name: Extract plugin version and commit hash
115116
id: version

.github/workflows/copilot-setup-steps.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ jobs:
6464
${{ runner.os }}-docker-
6565
6666
- name: Install npm dependencies
67-
run: |
68-
# Skip postinstall scripts to avoid Cypress download issues in CI
69-
npm config set ignore-scripts true
70-
npm install
71-
npm config set ignore-scripts false
67+
run: npm ci --ignore-scripts --prefer-offline --no-audit
7268

7369
- name: Install Composer dependencies
7470
run: |

.github/workflows/cs.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
name: CS
22

33
on:
4-
# Run on all pushes (except to main) and on all pull requests.
4+
# Run on direct pushes to integration branches and on all pull requests.
55
push:
66
branches:
7-
- '*'
7+
- develop
8+
- main
9+
- master
10+
- trunk
811
pull_request:
9-
branches:
10-
- '*'
1112
# Allow manually triggering the workflow.
1213
workflow_dispatch:
1314

.github/workflows/jest-tests.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,18 @@ jobs:
2626
restore-keys: |
2727
${{ runner.os }}-node-
2828
29+
- name: Cache node_modules
30+
id: cache-node-modules
31+
uses: actions/cache@v4
32+
with:
33+
path: node_modules
34+
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
35+
restore-keys: |
36+
${{ runner.os }}-node_modules-
37+
2938
- name: Install dependencies (skipping postinstall)
30-
run: |
31-
npm config set ignore-scripts true
32-
npm install
39+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
40+
run: npm ci --prefer-offline --no-audit --ignore-scripts
3341

3442
- name: Run Jest tests
3543
run: npm run test:jest

.github/workflows/lint-js.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
name: Lint JS
22

33
on:
4-
# Run on pushes to select branches and on all pull requests.
4+
# Run on direct pushes to integration branches and on all pull requests.
55
push:
66
branches:
7-
- main
87
- develop
8+
- main
9+
- master
910
- trunk
10-
- 'feature/**'
11-
- 'release/**'
12-
- 'hotfix/[0-9]+.[0-9]+*'
1311
pull_request:
1412
# Allow manually triggering the workflow.
1513
workflow_dispatch:
@@ -31,15 +29,17 @@ jobs:
3129
uses: actions/checkout@v3
3230

3331
- name: Cache Node.js modules
32+
id: cache-node-modules
3433
uses: actions/cache@v4
3534
with:
3635
path: node_modules
37-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
36+
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
3837
restore-keys: |
39-
${{ runner.os }}-node-
38+
${{ runner.os }}-node_modules-
4039
# The lint stage doesn't run the unit tests or use code style, so no need for PHPUnit, WPCS or phpcompatibility.
4140
- name: 'Install NPM packages'
42-
run: npm install --ignore-scripts
41+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
42+
run: npm ci --prefer-offline --no-audit --ignore-scripts
4343

4444
- name: Get only files changed in this PR
4545
id: changed-files

.github/workflows/lint-php.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
name: Lint PHP
22

33
on:
4-
# Run on pushes to select branches and on all pull requests.
4+
# Run on direct pushes to integration branches and on all pull requests.
55
push:
66
branches:
7-
- master
87
- develop
8+
- main
9+
- master
910
- trunk
10-
- 'feature/**'
11-
- 'release/**'
12-
- 'hotfix/[0-9]+.[0-9]+*'
1311
pull_request:
1412
# Allow manually triggering the workflow.
1513
workflow_dispatch:

.github/workflows/make-pot.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ jobs:
4545
node-version: '20'
4646

4747
- name: Cache Node.js modules
48+
id: cache-node-modules
4849
uses: actions/cache@v4
4950
with:
50-
path: ~/.npm
51-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
51+
path: node_modules
52+
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json') }}
5253
restore-keys: |
53-
${{ runner.os }}-node-
54+
${{ runner.os }}-node_modules-
5455
5556
- name: Install dependencies
56-
run: npm install --ignore-scripts
57+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
58+
run: npm ci --prefer-offline --no-audit --ignore-scripts
5759

5860
- name: Build plugin (dotorg dist)
5961
run: npm run dist:dotorg

.github/workflows/phpunit.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
name: Test
22

33
on:
4-
# Run on pushes to select branches and on all pull requests.
4+
# Run on direct pushes to integration branches and on all pull requests.
55
push:
6+
branches:
7+
- develop
8+
- main
9+
- master
10+
- trunk
611
pull_request:
712
# Allow manually triggering the workflow.
813
workflow_dispatch:
@@ -87,6 +92,18 @@ jobs:
8792
github-token: ${{ secrets.GITHUB_TOKEN }}
8893
env:
8994
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
96+
- name: Cache WordPress test library
97+
if: matrix.wp_version != 'latest'
98+
uses: actions/cache@v4
99+
with:
100+
path: |
101+
/tmp/wordpress-tests-lib
102+
/tmp/wordpress
103+
key: ${{ runner.os }}-wordpress-${{ matrix.wp_version }}-${{ github.run_id }}
104+
restore-keys: |
105+
${{ runner.os }}-wordpress-${{ matrix.wp_version }}-
106+
90107
# Some images won't have svn available. Install it if that's the case.
91108
- name: Install SVN
92109
run: |

0 commit comments

Comments
 (0)