Skip to content

Commit

Permalink
Use the composite workflow to restore node modules (#357)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntharo authored Apr 25, 2024
1 parent 60ae540 commit 5bd0540
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
name: "Install Modules"
description: "Install Node.js modules or restore cache"
name: "Configure Node.js"
description: "Install Node.js and install Node.js modules or restore cache"

inputs:
node-version:
description: "NodeJS Version"
required: true
github-pat:
description: "github.com PAT"
required: true
default: "18"
lookup-only:
description: "If true, only checks if cache entry exists and skips download. Does not change save cache behavior"
required: false
default: false
default: "false"

runs:
using: "composite"
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
token: ${{ inputs.github-pat }}

- name: Restore Node Modules from Cache
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
apps/**/node_modules
packages/**/node_modules
tests/**/node_modules
!node_modules/.cache
key: node-modules-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('yarn.lock') }}
key: node-modules-${{ inputs.node-version }}-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}
lookup-only: ${{ inputs.lookup-only }}

- name: Install Yarn
shell: bash
run: |
if ! command -v yarn &> /dev/null
then
npm install -g yarn
fi
# - name: Install Yarn
# shell: bash
# run: |
# if ! command -v yarn &> /dev/null
# then
# npm install -g yarn
# fi

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
Expand Down
68 changes: 4 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,7 @@ jobs:
echo "PR_SUFFIX=" >> $GITHUB_ENV
fi
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}

- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- uses: ./.github/actions/configure-nodejs

# We do this here so the `build-jsii` modules are installed too
# and become part of the cache - if we don't then
Expand Down Expand Up @@ -119,19 +103,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}
- uses: ./.github/actions/configure-nodejs

- name: Cache TypeScript Build Output
id: cache-typescript-build
Expand Down Expand Up @@ -198,23 +170,7 @@ jobs:
echo 'PREFIX_U=' >> $GITHUB_ENV
fi
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18.16.1

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}

- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- uses: ./.github/actions/configure-nodejs

# - name: Cache TypeScript Build Output
# id: cache-typescript-build
Expand Down Expand Up @@ -626,23 +582,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18

- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}

- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- uses: ./.github/actions/configure-nodejs

- name: Modify microapps-cdk tsconfig.json
run: |
Expand Down
32 changes: 2 additions & 30 deletions .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,7 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- uses: ./.github/actions/configure-nodejs
- name: Build All TypeScript
run: yarn build
- name: Run Node Tests
Expand Down Expand Up @@ -123,24 +109,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node.js 18
uses: actions/setup-node@v4
with:
node-version: 18
- uses: ./.github/actions/configure-nodejs
- name: Check for new commits
id: git_remote
run: echo latest_commit="$(git ls-remote origin -h ${{ github.ref }} | cut -f1)" >> $GITHUB_OUTPUT
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}
- name: Optionally Install Node Modules
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: Build Publish TypeScript
run: yarn build:publish
- name: Run Lint
Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,7 @@ jobs:
run: |-
git config user.name "github-actions"
git config user.email "github-actions@github.com"
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18
- name: Cache Node Modules
id: cache-node-modules
uses: actions/cache@v4
with:
path: |
node_modules
packages/**/node_modules
key: node-modules-${{ hashFiles('package.json', 'yarn.lock', '**/yarn.lock') }}
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- uses: ./.github/actions/configure-nodejs
- name: Build All TypeScript
run: yarn build
- name: Run Node Tests
Expand Down

0 comments on commit 5bd0540

Please sign in to comment.