-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Speed up npm ci by caching node_modules
#45932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
f4ec7b3
239050c
2eff8c8
38bca97
4014266
65efe55
1c9ca27
e437750
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: 'Setup Node.js and install npm dependencies' | ||
| description: 'Configure Node.js and install npm dependencies while managing all aspects of caching.' | ||
| inputs: | ||
| node-version: | ||
| description: 'Optional. The Node.js version to use. When not specified, the version specified in .nvmrc will be used.' | ||
| required: false | ||
| type: string | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: Use desired version of Node.js | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| node-version: ${{ inputs.node-version }} | ||
| cache: npm | ||
|
|
||
| - name: Get Node.js and npm version | ||
| id: node-version | ||
| run: | | ||
| echo "NODE_VERSION=$(node -v)" >> $GITHUB_OUTPUT | ||
| shell: bash | ||
|
|
||
| - name: Cache node_modules | ||
| id: cache-node_modules | ||
| uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1 | ||
| with: | ||
| path: '**/node_modules' | ||
| key: node_modules-${{ runner.os }}-${{ steps.node-version.outputs.NODE_VERSION }}-${{ hashFiles('package-lock.json') }} | ||
kevin940726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Install npm dependencies | ||
| if: ${{ steps.cache-node_modules.outputs.cache-hit != 'true' }} | ||
| run: npm ci | ||
| shell: bash | ||
kevin940726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Post-install | ||
kevin940726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if: ${{ steps.cache-node_modules.outputs.cache-hit == 'true' }} | ||
| run: | | ||
| npm run postinstall | ||
| npx lerna run postinstall | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the difference between running If so, I'm wondering if we should split into two steps. That would make it more clear which of the two fails should either encounter a problem.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some comments explaining this ❤️ . I don't think we need to split it into two steps though, as they have the same goal. |
||
| shell: bash | ||
kevin940726 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,7 +168,7 @@ jobs: | |
| with: | ||
| ref: ${{ needs.bump-version.outputs.release_branch || github.ref }} | ||
|
|
||
| - name: Use desired version of NodeJS | ||
| - name: Use desired version of Node.js | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
|
|
@@ -326,7 +326,7 @@ jobs: | |
| git config user.name "Gutenberg Repository Automation" | ||
| git config user.email [email protected] | ||
|
|
||
| - name: Setup Node (for CLI) | ||
| - name: Setup Node.js (for CLI) | ||
kevin940726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: 'main/.nvmrc' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,20 +20,17 @@ jobs: | |
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| node: [14] | ||
| node: ['14'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why this is needed. Does this cause a failure in the composite workflow because the type is defined as
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think either works, but everywhere else uses string. Just want to keep it consistent. |
||
| os: [macos-latest, ubuntu-latest, windows-latest] | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
|
|
||
| - name: Use desired version of NodeJS | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| - name: Setup Node.js and install dependencies | ||
| uses: ./.github/setup-node | ||
| with: | ||
| node-version: ${{ matrix.node }} | ||
| cache: npm | ||
|
|
||
| - name: npm install, build, format and lint | ||
| - name: Create block | ||
| shell: bash | ||
| run: | | ||
| npm ci | ||
| bash ./bin/test-create-block.sh | ||
| run: bash ./bin/test-create-block.sh | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,16 +29,11 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
|
|
||
| - name: Use desired version of NodeJS | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: npm | ||
| - name: Setup Node.js and install dependencies | ||
| uses: ./.github/setup-node | ||
|
|
||
| - name: Npm install and build | ||
| run: | | ||
| npm ci | ||
| npm run build | ||
| - name: Npm build | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're running
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's do this in another PR though. |
||
| run: npm run build | ||
|
|
||
| - name: Install WordPress | ||
| run: | | ||
|
|
@@ -78,16 +73,11 @@ jobs: | |
| steps: | ||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||
|
|
||
| - name: Use desired version of NodeJS | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: npm | ||
| - name: Setup Node.js and install dependencies | ||
| uses: ./.github/setup-node | ||
|
|
||
| - name: Npm install and build | ||
| run: | | ||
| npm ci | ||
| npm run build | ||
| - name: Npm build | ||
| run: npm run build | ||
|
|
||
| - name: Install Playwright dependencies | ||
| run: | | ||
|
|
@@ -137,19 +127,14 @@ jobs: | |
| name: flaky-tests-report | ||
| path: flaky-tests | ||
|
|
||
| - name: Use desired version of NodeJS | ||
| - name: Setup Node.js and install dependencies | ||
| if: ${{ steps.download_artifact.outcome == 'success' }} | ||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: '.nvmrc' | ||
| cache: npm | ||
| uses: ./.github/setup-node | ||
|
|
||
| - name: Npm install and build | ||
| - name: Npm build | ||
| if: ${{ steps.download_artifact.outcome == 'success' }} | ||
| # TODO: We don't have to build the entire project, just the action itself. | ||
| run: | | ||
| npm ci | ||
| npm run build:packages | ||
| run: npm run build:packages | ||
|
|
||
| - name: Report flaky tests | ||
| if: ${{ steps.download_artifact.outcome == 'success' }} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,7 @@ jobs: | |
| git config user.name "Gutenberg Repository Automation" | ||
| git config user.email [email protected] | ||
|
|
||
| - name: Setup Node (for CLI) | ||
| - name: Setup Node.js (for CLI) | ||
kevin940726 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||
| with: | ||
| node-version-file: 'main/.nvmrc' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -33,19 +33,16 @@ jobs: | |||||
| steps: | ||||||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||||||
|
|
||||||
| - name: Use desired version of NodeJS | ||||||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||||||
| - name: Setup Node.js and install dependencies | ||||||
| uses: ./.github/setup-node | ||||||
| with: | ||||||
| node-version: ${{ matrix.node }} | ||||||
| cache: npm | ||||||
|
|
||||||
| - name: Npm install and build | ||||||
| - name: Npm build | ||||||
| # It's not necessary to run the full build, since Jest can interpret | ||||||
| # source files with `babel-jest`. Some packages have their own custom | ||||||
| # build tasks, however. These must be run. | ||||||
| run: | | ||||||
| npm ci | ||||||
| npx lerna run build | ||||||
| run: npx lerna run build | ||||||
|
|
||||||
| - name: Running the tests | ||||||
| run: npm run test:unit -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" | ||||||
|
|
@@ -79,11 +76,8 @@ jobs: | |||||
| steps: | ||||||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||||||
|
|
||||||
| - name: Set up Node.js | ||||||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||||||
| with: | ||||||
| node-version-file: '.nvmrc' | ||||||
| cache: npm | ||||||
| - name: Setup Node.js and install dependencies | ||||||
| uses: ./.github/setup-node | ||||||
|
|
||||||
| ## | ||||||
| # This allows Composer dependencies to be installed using a single step. | ||||||
|
|
@@ -116,10 +110,8 @@ jobs: | |||||
| with: | ||||||
| custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") | ||||||
|
|
||||||
| - name: Install npm dependencies | ||||||
| run: | | ||||||
| npm ci | ||||||
| npm run build | ||||||
| - name: Npm build | ||||||
desrosj marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| run: npm run build | ||||||
|
|
||||||
| - name: Docker debug information | ||||||
| run: | | ||||||
|
|
@@ -235,19 +227,14 @@ jobs: | |||||
| steps: | ||||||
| - uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0 | ||||||
|
|
||||||
| - name: Use desired version of NodeJS | ||||||
| uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0 | ||||||
| with: | ||||||
| node-version-file: '.nvmrc' | ||||||
| cache: npm | ||||||
| - name: Setup Node.js and install dependencies | ||||||
| uses: ./.github/setup-node | ||||||
|
|
||||||
| - name: Npm install and build | ||||||
| - name: Npm build | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, this seems to be running the Lerna build script.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Build Lerna" isn't really descriptive either though. I think this should be "Build packages" and just run |
||||||
| # It's not necessary to run the full build, since Jest can interpret | ||||||
| # source files with `babel-jest`. Some packages have their own custom | ||||||
| # build tasks, however. These must be run. | ||||||
| run: | | ||||||
| npm ci | ||||||
| npx lerna run build | ||||||
| run: npx lerna run build | ||||||
|
|
||||||
| - name: Running the tests | ||||||
| run: npm run native test -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache" | ||||||
Uh oh!
There was an error while loading. Please reload this page.