Skip to content

Commit

Permalink
refactor: use cached node_modules across workflows (#1941)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeSchwert authored Jun 25, 2024
1 parent f4d7312 commit 1782970
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 50 deletions.
32 changes: 13 additions & 19 deletions .github/workflows/build-lint-typecheck-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ jobs:
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Install dependencies
run: yarn install --immutable

- name: Cache node_modules
# this step will also try to cache the node_modules at the end of the workflow run
- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Check Single Package Version Policy
run: yarn syncpack:check
Expand Down Expand Up @@ -67,8 +70,7 @@ jobs:
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
Expand All @@ -77,7 +79,6 @@ jobs:
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: ${{ runner.os }}-build-

- name: Build passport sample app
run: yarn workspace @imtbl/passport-sdk-sample-app build
Expand All @@ -101,8 +102,7 @@ jobs:
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
Expand All @@ -111,7 +111,6 @@ jobs:
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: ${{ runner.os }}-build-

- name: Typecheck
run: yarn typecheck
Expand All @@ -137,8 +136,7 @@ jobs:
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Restore cached build artifacts
uses: actions/cache@v4
Expand All @@ -147,7 +145,6 @@ jobs:
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: ${{ runner.os }}-build-

- name: Test
run: yarn test
Expand Down Expand Up @@ -188,8 +185,7 @@ jobs:
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Get reviewing teams
id: reviewer-teams
Expand All @@ -203,7 +199,6 @@ jobs:
./sdk
./packages
key: ${{ runner.os }}-build-${{ github.sha }}
restore-keys: ${{ runner.os }}-build-

- name: Checkout-widgets cypress tests
if: ${{ contains(steps.reviewer-teams.outputs.teams, 'Wallets') && !contains(github.event.pull_request.title, 'SKIP-CY') }}
Expand Down Expand Up @@ -243,8 +238,7 @@ jobs:
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-node-modules-
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Lint
run: yarn lint
20 changes: 10 additions & 10 deletions .github/workflows/build-sdk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ jobs:
- name: Install dependencies
run: yarn install --immutable

- name: Cache build artifacts
- name: Cache node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Build
run: yarn build
# - name: Build
# run: yarn build

- name: Cache build artifacts
uses: actions/cache@v2
with:
path: |
./sdk
./packages
key: ${{ runner.os }}-build-cache-${{ github.sha }}
# - name: Cache build artifacts
# uses: actions/cache@v4
# with:
# path: |
# ./sdk
# ./packages
# key: ${{ runner.os }}-build-cache-${{ github.sha }}
2 changes: 1 addition & 1 deletion .github/workflows/detect-node-version-change.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Get Node engine version from package.json
id: get_package_json_node_engine_version
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/functional-tests-imx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ jobs:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: 'yarn'

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
node-version-file: .nvmrc
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install root dependencies
run: npm install -g yarn && yarn install --immutable
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Build SDK
run: yarn build
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/functional-tests-zkevm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ jobs:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: 'yarn'

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install root dependencies
run: npm install -g yarn && yarn install --immutable
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Build SDK
run: yarn build
Expand Down
18 changes: 15 additions & 3 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ jobs:
container:
image: mcr.microsoft.com/playwright:v1.40.0-jammy
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: samples/apps/ts-immutable-sample/.nvmrc
cache: 'yarn'

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install root dependencies
run: npm install -g yarn && yarn install --immutable
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Build SDK
run: yarn build
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/publish-docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ jobs:
GITHUB_USER: ${{ github.actor }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Checkout Docs Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: immutable/docs
token: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }}
Expand All @@ -44,7 +44,7 @@ jobs:
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "yarn"
Expand All @@ -55,7 +55,15 @@ jobs:
jq '.version = "${{ env.VERSION }}"' ./package.json > "$tmp" && mv "$tmp" ./package.json
shell: bash

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Build
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/publish-major-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
run: failure("Public releases should be only done from main branch, current branch ${{ github.ref }}")

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand All @@ -83,7 +83,7 @@ jobs:
run: git fetch --tags

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "yarn"
Expand All @@ -100,7 +100,15 @@ jobs:
./.github/scripts/version-up.sh --${{ github.event.inputs.release_type }} --$upgrade_type --apply $revision_upgrade
shell: bash

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Lint
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
run: failure("Public releases should be only done from main branch, current branch ${{ github.ref }}")

- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.TS_IMMUTABLE_SDK_GITHUB_TOKEN }}
Expand All @@ -67,7 +67,7 @@ jobs:
run: git fetch --tags

- name: Setup Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: "yarn"
Expand All @@ -87,7 +87,15 @@ jobs:
./.github/scripts/version-up.sh --${{ env.RELEASE_TYPE }} $upgrade_type --apply $revision_upgrade
shell: bash

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Lint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/secret-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
name: gitleaks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gitleaks/[email protected]
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/smokes-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ jobs:
NODE_OPTIONS: --max-old-space-size=14366
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
registry-url: https://registry.npmjs.org/
cache: "yarn"

- name: Restore cached node_modules
id: restore-cache-node_modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-build-cache-deps-${{ hashFiles('yarn.lock') }}

- name: Install root dependencies
if: steps.restore-cache-node_modules.outputs.cache-hit != 'true'
run: yarn install --immutable

- name: Build
Expand Down

0 comments on commit 1782970

Please sign in to comment.