Build/Test Tools: Use `install-changed` to install NPM dependencies in GitHub Action workflows.

The `install-changed` package records a hash of the `package.json` file locally in a text file and only runs `npm install` when there are changes to account for. 

This builds on [47497], which only hashes the `package.json` file after a Grunt task is called. By using `npx install-changed` within the workflow files, the package is hashed before the first Grunt task is run.

Props ocean90.
See #50401, #49594.

git-svn-id: https://develop.svn.wordpress.org/trunk@49369 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonathan Desrosiers 2020-10-29 01:20:42 +00:00
parent df716454a3
commit 886a9ddaa4
5 changed files with 15 additions and 13 deletions

View File

@ -79,7 +79,7 @@ jobs:
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `.nvmrc` file to support older branches)
# - Sets up caching for NPM.
# - Logs updated debug information.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Run the WordPress JSHint checks.
# - todo: Configure Slack notifications for failing tests.
jshint:
@ -120,7 +120,7 @@ jobs:
node --version
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Run JSHint
run: npm run grunt jshint

View File

@ -22,7 +22,7 @@ jobs:
# - Logs debug information about the runner container.
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `.nvmrc` file to support older branches)
# - Sets up caching for NPM.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
# - Starts the WordPress Docker container.
# - Logs general debug information.
@ -77,7 +77,7 @@ jobs:
${{ runner.os }}-npm-
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build

View File

@ -17,7 +17,7 @@ jobs:
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `.nvmrc` file to support older branches)
# - Sets up caching for NPM.
# - Logs updated debug information.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Run the WordPress QUnit tests.
# - todo: Configure Slack notifications for failing tests.
test-js:
@ -62,7 +62,7 @@ jobs:
node --version
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Run QUnit tests
run: npm run grunt qunit:compiled

View File

@ -28,7 +28,7 @@ jobs:
# - Logs debug information about the runner container.
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `.nvmrc` file to support older branches)
# - Sets up caching for NPM.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
# - Creates a ZIP file of compiled WordPress
# - Uploads ZIP file as an artifact.
@ -51,6 +51,8 @@ jobs:
- name: Log debug information
run: |
echo "$GITHUB_REF"
echo "$GITHUB_EVENT_NAME"
npm --version
node --version
curl --version
@ -77,7 +79,7 @@ jobs:
${{ runner.os }}-npm-
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build
@ -86,7 +88,7 @@ jobs:
uses: thedoctor0/zip-release@0.4.1
with:
filename: built-wp-${{ github.sha }}.zip
exclusions: '/*node_modules/*'
exclusions: '*.git* /*node_modules/* packagehash.txt'
- name: Upload build artifact
uses: actions/upload-artifact@v2
@ -104,7 +106,7 @@ jobs:
# - Unzips the artifact.
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `nvmrc` file to support older branches)
# - Sets up caching for NPM.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Configures caching for Composer.
# _ Installs Composer dependencies (if desired)
# - Logs Docker debug information (about both the Docker installation within the runner)
@ -172,7 +174,7 @@ jobs:
${{ runner.os }}-npm-
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Get composer cache directory
id: composer-cache

View File

@ -19,7 +19,7 @@ jobs:
# - Logs debug information about the runner container.
# - Installs NodeJS 12 (todo: install the version of NPM specified in the `.nvmrc` file to support older branches)
# - Sets up caching for NPM.
# _ Installs NPM dependencies.
# _ Installs NPM dependencies using install-changed to hash the `package.json` file.
# - Builds WordPress to run from the `build` directory.
test-npm:
name: Tests NPM on Windows
@ -62,7 +62,7 @@ jobs:
${{ runner.os }}-npm-
- name: Install Dependencies
run: npm ci
run: npx install-changed --install-command="npm ci"
- name: Build WordPress
run: npm run build