fix: cache build artefacts (#1091)

To speed up the build and make it more reliable, cache the node_modules
folder, dist, etc and re-use on each step.
This commit is contained in:
Alex Potsides 2021-12-29 15:06:58 +01:00 committed by GitHub
parent ef54e0a10e
commit 5043cd5643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 409 additions and 46 deletions

View File

@ -8,17 +8,59 @@ on:
- '**' - '**'
jobs: jobs:
check: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
check:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: npx aegir lint - run: npx aegir lint
- run: npx aegir ts -p check - run: npx aegir ts -p check
- run: npx aegir build
test-auto-relay-example: test-auto-relay-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -27,8 +69,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- auto-relay id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- auto-relay
test-chat-example: test-chat-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -37,8 +96,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- chat id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- chat
test-connection-encryption-example: test-connection-encryption-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -47,8 +123,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- connection-encryption id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- connection-encryption
test-discovery-mechanisms-example: test-discovery-mechanisms-example:
needs: check needs: check
runs-on: macos-latest runs-on: macos-latest
@ -57,8 +150,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- discovery-mechanisms id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- discovery-mechanisms
test-echo-example: test-echo-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -67,8 +177,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- echo id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- echo
test-libp2p-in-the-browser-example: test-libp2p-in-the-browser-example:
needs: check needs: check
runs-on: macos-latest runs-on: macos-latest
@ -77,8 +204,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- libp2p-in-the-browser id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- libp2p-in-the-browser
test-peer-and-content-routing-example: test-peer-and-content-routing-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -87,8 +231,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- peer-and-content-routing id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- peer-and-content-routing
test-pnet-example: test-pnet-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -97,8 +258,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- pnet id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- pnet
test-protocol-and-stream-muxing-example: test-protocol-and-stream-muxing-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -107,8 +285,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- protocol-and-stream-muxing id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- protocol-and-stream-muxing
test-pubsub-example: test-pubsub-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -117,8 +312,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- pubsub id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- pubsub
test-transports-example: test-transports-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -127,8 +339,25 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- transports id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- transports
test-webrtc-direct-example: test-webrtc-direct-example:
needs: check needs: check
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -137,5 +366,22 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install -g @mapbox/node-pre-gyp && npm install - uses: actions/cache@v2
- run: cd examples && npm i && npm run test -- webrtc-direct id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
./examples/node_modules
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
cd examples && npm i
- run: cd examples && npm run test -- webrtc-direct

View File

@ -8,21 +8,65 @@ on:
- '**' - '**'
jobs: jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node: [16]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
check: check:
needs: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: 16 node-version: 16
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npx aegir lint - run: npx aegir lint
- run: npx aegir build
- run: npx aegir dep-check - run: npx aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master - uses: ipfs/aegir/actions/bundle-size@master
name: size name: size
with: with:
github_token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
test-node: test-node:
needs: check needs: check
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
@ -36,7 +80,23 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: ${{ matrix.node }} node-version: ${{ matrix.node }}
- run: npm install - uses: actions/cache@v2
id: cache
if: matrix.os != 'windows-latest'
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npm run test:node -- --cov --bail - run: npm run test:node -- --cov --bail
- uses: codecov/codecov-action@v1 - uses: codecov/codecov-action@v1
test-chrome: test-chrome:
@ -47,7 +107,22 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: lts/* node-version: lts/*
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npm run test:browser -- -t browser -t webworker --bail - run: npm run test:browser -- -t browser -t webworker --bail
test-firefox: test-firefox:
needs: check needs: check
@ -57,7 +132,22 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: lts/* node-version: lts/*
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npm run test:browser -- -t browser -t webworker --bail -- --browser firefox - run: npm run test:browser -- -t browser -t webworker --bail -- --browser firefox
test-ts: test-ts:
needs: check needs: check
@ -67,7 +157,22 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: lts/* node-version: lts/*
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npm run test:ts - run: npm run test:ts
test-interop: test-interop:
needs: check needs: check
@ -77,5 +182,20 @@ jobs:
- uses: actions/setup-node@v2 - uses: actions/setup-node@v2
with: with:
node-version: lts/* node-version: lts/*
- run: npm install - uses: actions/cache@v2
id: cache
env:
CACHE_NAME: cache-node-modules
with:
path: |
~/.cache
~/.npm
./node_modules
./dist
key: ${{ runner.os }}-build-${{ env.CACHE_NAME }}-${{ github.event.pull_request.head.sha }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
npm install
npm run build
- run: npm run test:interop -- --bail -- --exit - run: npm run test:interop -- --bail -- --exit

View File

@ -12,6 +12,7 @@
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.13.10", "@babel/cli": "^7.13.10",
"@babel/core": "^7.13.10", "@babel/core": "^7.13.10",
"@mapbox/node-pre-gyp": "^1.0.8",
"babel-plugin-syntax-async-functions": "^6.13.0", "babel-plugin-syntax-async-functions": "^6.13.0",
"babel-plugin-transform-regenerator": "^6.26.0", "babel-plugin-transform-regenerator": "^6.26.0",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",

View File

@ -155,7 +155,7 @@
"libp2p-floodsub": "^0.28.0", "libp2p-floodsub": "^0.28.0",
"libp2p-gossipsub": "^0.12.1", "libp2p-gossipsub": "^0.12.1",
"libp2p-interfaces-compliance-tests": "^2.0.1", "libp2p-interfaces-compliance-tests": "^2.0.1",
"libp2p-interop": "^0.5.0", "libp2p-interop": "^0.6.0",
"libp2p-kad-dht": "^0.27.1", "libp2p-kad-dht": "^0.27.1",
"libp2p-mdns": "^0.18.0", "libp2p-mdns": "^0.18.0",
"libp2p-mplex": "^0.10.1", "libp2p-mplex": "^0.10.1",

View File

@ -75,11 +75,11 @@ describe('peer-routing', () => {
it('should use the nodes dht', async () => { it('should use the nodes dht', async () => {
sinon.stub(nodes[0]._dht, 'findPeer').callsFake(async function * () { sinon.stub(nodes[0]._dht, 'findPeer').callsFake(async function * () {
yield { yield {
name: 'PEER_RESPONSE', name: 'FINAL_PEER',
closer: [{ peer: {
id: nodes[1].peerId, id: nodes[1].peerId,
multiaddrs: [] multiaddrs: []
}] }
} }
}) })
@ -448,10 +448,8 @@ describe('peer-routing', () => {
sinon.stub(node._dht, 'findPeer').callsFake(async function * () { sinon.stub(node._dht, 'findPeer').callsFake(async function * () {
yield { yield {
name: 'PEER_RESPONSE', name: 'FINAL_PEER',
closer: [ peer: result
result
]
} }
}) })
sinon.stub(delegate, 'findPeer').callsFake(async () => { sinon.stub(delegate, 'findPeer').callsFake(async () => {
@ -477,10 +475,8 @@ describe('peer-routing', () => {
sinon.stub(node._dht, 'findPeer').callsFake(async function * () { sinon.stub(node._dht, 'findPeer').callsFake(async function * () {
yield { yield {
name: 'PEER_RESPONSE', name: 'FINAL_PEER',
closer: [ peer: result
result
]
} }
}) })
sinon.stub(delegate, 'findPeer').callsFake(() => {}) sinon.stub(delegate, 'findPeer').callsFake(() => {})