From 886a9ddaa43a36ab4459d93bc1188865a83292bf Mon Sep 17 00:00:00 2001 From: Jonathan Desrosiers Date: Thu, 29 Oct 2020 01:20:42 +0000 Subject: [PATCH] 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 --- .github/workflows/coding-standards.yml | 4 ++-- .github/workflows/end-to-end-tests.yml | 4 ++-- .github/workflows/javascript-tests.yml | 4 ++-- .github/workflows/phpunit-tests.yml | 12 +++++++----- .github/workflows/verify-npm-on-windows.yml | 4 ++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index dac4fb643c..c6249f97de 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -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 diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index aa83092d84..9fe6f0b800 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -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 diff --git a/.github/workflows/javascript-tests.yml b/.github/workflows/javascript-tests.yml index aae2476e57..1508d564aa 100644 --- a/.github/workflows/javascript-tests.yml +++ b/.github/workflows/javascript-tests.yml @@ -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 diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 16ef65deae..f37c93b5a7 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -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 diff --git a/.github/workflows/verify-npm-on-windows.yml b/.github/workflows/verify-npm-on-windows.yml index e01915a61f..c5d8e383ea 100644 --- a/.github/workflows/verify-npm-on-windows.yml +++ b/.github/workflows/verify-npm-on-windows.yml @@ -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