Skip to content

Commit

Permalink
Use composite action to set up node
Browse files Browse the repository at this point in the history
  • Loading branch information
eason9487 committed Oct 7, 2021
1 parent 9137422 commit 148dd5f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 77 deletions.
39 changes: 39 additions & 0 deletions .github/actions/prepare-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Prepare Node
description: Load npm cache, install Node dependencies

inputs:
install-deps:
description: Whether to run `npm ci`. Set "maybe" to install deps if cache is missing. "yes" by default.
default: "yes"

ignore-scripts:
description: Whether to run `npm ci` with --ignore-scripts. "yes" by default.
default: "yes"

runs:
using: composite
steps:
# Log debug information
- shell: sh -e {0}

This comment has been minimized.

Copy link
@tomalec

tomalec Oct 7, 2021

Member


Why do we need this shell entry? We didn't have it few commits before

This comment has been minimized.

Copy link
@eason9487

eason9487 Oct 8, 2021

Author Member

Composite action is a kind of custom action and it follows the metadata syntax. The shell is required if run is set.

https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runsstepsshell

run: |
node --version
npm --version
# Get npm cache directory
- uses: actions/cache@v2
id: npm-cache
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
# Install node dependencies
- shell: sh -e {0}
# Update npm cache directory if package-lock has changed
run: |
if [ "${{ inputs.install-deps }}" = "yes" ] || [ "${{ steps.npm-cache.outputs.cache-hit }}" != "true" ]; then
npm ci `if [ "${{ inputs.ignore-scripts }}" = "yes" ]; then printf %s "--ignore-scripts"; fi`
else
echo "Skip npm ci"
fi
43 changes: 7 additions & 36 deletions .github/workflows/js-css-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,10 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
node --version
npm --version
- name: Get npm cache directory
id: npm-cache
uses: actions/cache@v2
- name: Prepare node
uses: ./.github/actions/prepare-node
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Update npm cache directory # if package-lock has changed
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts
install-deps: "maybe"

JSLintingCheck:
name: Lint JavaScript
Expand All @@ -41,16 +28,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node dependencies
run: npm ci --ignore-scripts
- name: Prepare node
uses: ./.github/actions/prepare-node

- name: Save code linting report JSON
run: npm run lint:js -- --quiet --output-file eslint_report.json --format json
Expand All @@ -77,16 +56,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node dependencies
run: npm ci --ignore-scripts
- name: Prepare node
uses: ./.github/actions/prepare-node

- name: Lint CSS
run: npm run lint:css
17 changes: 2 additions & 15 deletions .github/workflows/js-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Log debug information
run: |
node --version
npm --version
- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Node dependencies
run: npm ci --ignore-scripts
- name: Prepare node
uses: ./.github/actions/prepare-node

- name: Run JavaScript unit tests
run: npm run test-unit
35 changes: 9 additions & 26 deletions .github/workflows/php-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,15 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Prepare node
uses: ./.github/actions/prepare-node
with:
install-deps: "maybe"

- name: Log debug information
run: |
node --version
npm --version
composer --version
- name: Get npm cache directory
id: npm-cache
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Update npm cache directory # if package-lock has changed
if: steps.npm-cache.outputs.cache-hit != 'true'
run: npm ci --ignore-scripts

- name: Get Composer cache directory
id: composer-cache-config
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand Down Expand Up @@ -67,13 +57,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v2

- name: Get npm cache directory
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Prepare node
uses: ./.github/actions/prepare-node

- name: Get Composer cache directory
id: composer-cache-config
Expand Down Expand Up @@ -104,10 +89,8 @@ jobs:
- name: Install Composer dependencies
run: composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction

- name: Install Node dependencies and build
run: |
npm ci
npm run dev
- name: Build client bundles
run: npm run dev

- name: Install WP tests
shell: bash
Expand Down

0 comments on commit 148dd5f

Please sign in to comment.