Skip to content

Commit 22e8b77

Browse files
committed
Add shared node setup
1 parent 603abe4 commit 22e8b77

File tree

4 files changed

+79
-24
lines changed

4 files changed

+79
-24
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Configure Node.js'
2+
description: 'Install Node.js and install Node.js modules or restore cache'
3+
4+
inputs:
5+
node-version:
6+
description: 'NodeJS Version'
7+
default: '18'
8+
lookup-only:
9+
description: 'If true, only checks if cache entry exists and skips download. Does not change save cache behavior'
10+
default: 'false'
11+
12+
runs:
13+
using: 'composite'
14+
steps:
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: ${{ inputs.node-version }}
18+
19+
- name: Restore Node Modules from Cache
20+
id: cache-node-modules
21+
uses: actions/cache@v4
22+
with:
23+
path: |
24+
node_modules
25+
packages/**/node_modules
26+
!node_modules/.cache
27+
key: node-modules-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'package-lock.json', '**/package-lock.json') }}
28+
lookup-only: ${{ inputs.lookup-only }}
29+
30+
- name: Install dependencies
31+
if: steps.cache-node-modules.outputs.cache-hit != 'true'
32+
shell: bash
33+
run: npm ci

.github/workflows/ci.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,33 @@ on:
99
- main
1010

1111
jobs:
12-
build:
12+
check-access:
1313
runs-on: ubuntu-latest
14+
outputs:
15+
has-token-access: ${{ steps.check.outputs.has-token-access }}
1416
steps:
15-
- name: Checkout code
16-
uses: actions/checkout@v3
17+
- id: check
18+
run: |
19+
echo "has-token-access=$(if [[ '${{ github.event.pull_request.head.repo.fork }}' != 'true' && '${{ github.actor }}' != 'dependabot[bot]' ]]; then echo 'true'; else echo 'false'; fi)" >> $GITHUB_OUTPUT
1720
18-
- name: Use Node.js 16
19-
uses: actions/setup-node@v3
21+
install-deps:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- uses: ./.github/actions/configure-nodejs
2026
with:
21-
node-version: 16
27+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
28+
29+
build:
30+
needs:
31+
- install-deps
32+
- check-access
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout code
36+
uses: actions/checkout@v4
2237

23-
- name: Install Modules
24-
run: npm ci
38+
- uses: ./.github/actions/configure-nodejs
2539

2640
- name: Build
2741
run: npm run build

.github/workflows/docs.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ on:
77
workflow_dispatch:
88

99
jobs:
10+
install-deps:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: ./.github/actions/configure-nodejs
15+
with:
16+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
17+
1018
build:
19+
needs:
20+
- install-deps
1121
runs-on: ubuntu-latest
1222
steps:
1323
- name: Checkout code
14-
uses: actions/checkout@v3
15-
16-
- name: Use Node.js 16
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: 16
24+
uses: actions/checkout@v4
2025

21-
- name: Install Modules
22-
run: npm ci
26+
- uses: ./.github/actions/configure-nodejs
2327

2428
- name: Build Docs
2529
run: npm run build:docs

.github/workflows/publish.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ on:
55
types: [published]
66

77
jobs:
8+
install-deps:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: ./.github/actions/configure-nodejs
13+
with:
14+
lookup-only: 'true' # We only want to lookup from the cache - if a hit, this job does nothing
15+
816
build:
17+
needs:
18+
- install-deps
919
runs-on: ubuntu-latest
1020
steps:
1121
- name: Checkout code
12-
uses: actions/checkout@v3
22+
uses: actions/checkout@v4
1323

14-
- name: Use Node.js 16
15-
uses: actions/setup-node@v3
16-
with:
17-
node-version: 16
24+
- uses: ./.github/actions/configure-nodejs
1825

1926
- name: Use the Release Tag Version
2027
run: |
2128
npm version from-git --allow-same-version --no-git-tag-version
2229
23-
- name: Install Modules
24-
run: npm ci
25-
2630
- name: Build
2731
run: npm run build
2832

0 commit comments

Comments
 (0)