Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Cache node_modules between workflows (#6404)
Browse files Browse the repository at this point in the history
* Running actions

* Cache node_modules

* Correct cache-name-prop

* rejig if statements

* cache node_modules everywhere

* Simplify unit test action

* Add checkout action back into other unit test action steps

* Share node_modules and build assets between jobs

* Cache node_modules between jobs

* Fix github error

* Tidy up

* Change wp-env-with-gutenberg to support multiple plugins

* Fix permissions issue

* Remove chmod

* Pass woocommerce.zip as a string

* Revert change to plugins override in unit test workflow

* Revert wp-env-with-gutenberg change

* Revert wp-env-with-gutenberg change

* Revert wp-env-with-gutenberg change

* Refactor check-modified-assets workflow

* Fix missed dependency

* Revert breaking the check-modified-assets.yml
  • Loading branch information
alexflorisca authored May 24, 2022
1 parent 40d27b7 commit 3ea1a3c
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 47 deletions.
39 changes: 31 additions & 8 deletions .github/workflows/check-modified-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,28 @@ jobs:
- uses: actions/checkout@v3
with:
ref: trunk
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install and build
run: |
npm ci --no-optional
npm run build:check-assets

- name: Install Node dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

- name: Build Assets
run: npm run build:check-assets

- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
Expand All @@ -30,15 +43,25 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: npm install
run: |
npm ci --no-optional
npm run build:check-assets

- name: Build Assets
run: npm run build:check-assets

- name: Download assets (trunk)
uses: actions/download-artifact@v3
with:
Expand Down
45 changes: 36 additions & 9 deletions .github/workflows/js-css-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,24 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node dependencies

- name: Install Node Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

JSLintingCheck:
Expand All @@ -28,13 +40,21 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup node version and npm cache

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node dependencies
run: npm ci --no-optional

- name: Save code linting report JSON
run: npm run lint:js:report
# Continue to the next step even if this fails
Expand All @@ -57,12 +77,19 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Setup node version and npm cache
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node dependencies
run: npm ci --no-optional

- name: Lint CSS
run: npm run lint:css
43 changes: 35 additions & 8 deletions .github/workflows/php-js-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Npm install and build
run: |
npm ci --no-optional
FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: Install Node Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

- name: Build Assets
run: FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
Expand Down Expand Up @@ -64,15 +78,28 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Npm install and build
run: |
npm ci --no-optional
FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: Install Node Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

- name: Build Assets
run: FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: blocks.ini setup
run: |
Expand Down
84 changes: 62 additions & 22 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,38 @@ jobs:
name: Setup
steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Npm install and build
run: |
npm ci --no-optional
FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: Install Node Dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci --no-optional

- name: Build Assets
run: FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: Store Build Assets
uses: actions/upload-artifact@v3
with:
name: build-assets
path: build/

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
Expand All @@ -40,8 +58,7 @@ jobs:
tools: composer

- name: Composer install
run: |
composer install
run: composer install

PHPUnitTests:
name: PHP Unit Tests
Expand All @@ -50,23 +67,38 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Npm install #build is not needed
run: |
npm ci --no-optional

- name: Download Build Assets
uses: actions/download-artifact@v3
with:
name: build-assets

- name: blocks.ini setup
run: |
echo 'woocommerce_blocks_phase = 3' > blocks.ini
run: echo 'woocommerce_blocks_phase = 3' > blocks.ini

- name: Setup Environment
run: |
chmod -R 767 ./ #TODO: Might get implemented in wp-env
npm run wp-env start
- name: Run PHPUnit tests
run: npm run test:php

- name: Run PHPUnit tests (WooCommerce Development Version)
run: |
JSON='{"plugins": [".","https://downloads.wordpress.org/plugin/woocommerce.zip"]}'
Expand All @@ -78,23 +110,31 @@ jobs:
name: JS Unit Tests
needs: Setup
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}

- name: Setup node version and npm cache
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Npm install and build
run: |
npm ci --no-optional
FORCE_REDUCED_MOTION=true npm run build:e2e-test

- name: Download Build Assets
uses: actions/download-artifact@v3
with:
name: build-assets

- name: blocks.ini setup
run: |
echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini
run: echo -e 'woocommerce_blocks_phase = 3\nwoocommerce_blocks_env = tests' > blocks.ini

- name: Run JavaScript Unit tests
run: |
npm run test
run: npm run test

0 comments on commit 3ea1a3c

Please sign in to comment.