From 5043cd56435a264e83db4fb8388d33e9a0442fff Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 29 Dec 2021 15:06:58 +0100 Subject: [PATCH] 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. --- .github/workflows/examples.yml | 300 ++++++++++++++++++++++--- .github/workflows/main.yml | 134 ++++++++++- examples/webrtc-direct/package.json | 1 + package.json | 2 +- test/peer-routing/peer-routing.node.js | 18 +- 5 files changed, 409 insertions(+), 46 deletions(-) diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml index 36173f4f..0e46e951 100644 --- a/.github/workflows/examples.yml +++ b/.github/workflows/examples.yml @@ -8,17 +8,59 @@ on: - '**' jobs: - check: + build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: 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 ts -p check - - run: npx aegir build test-auto-relay-example: needs: check runs-on: ubuntu-latest @@ -27,8 +69,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- auto-relay + - 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: cd examples && npm run test -- auto-relay test-chat-example: needs: check runs-on: ubuntu-latest @@ -37,8 +96,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- chat + - 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: cd examples && npm run test -- chat test-connection-encryption-example: needs: check runs-on: ubuntu-latest @@ -47,8 +123,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- connection-encryption + - 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: cd examples && npm run test -- connection-encryption test-discovery-mechanisms-example: needs: check runs-on: macos-latest @@ -57,8 +150,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- discovery-mechanisms + - 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: cd examples && npm run test -- discovery-mechanisms test-echo-example: needs: check runs-on: ubuntu-latest @@ -67,8 +177,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- echo + - 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: cd examples && npm run test -- echo test-libp2p-in-the-browser-example: needs: check runs-on: macos-latest @@ -77,8 +204,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- libp2p-in-the-browser + - 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: cd examples && npm run test -- libp2p-in-the-browser test-peer-and-content-routing-example: needs: check runs-on: ubuntu-latest @@ -87,8 +231,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- peer-and-content-routing + - 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: cd examples && npm run test -- peer-and-content-routing test-pnet-example: needs: check runs-on: ubuntu-latest @@ -97,8 +258,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- pnet + - 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: cd examples && npm run test -- pnet test-protocol-and-stream-muxing-example: needs: check runs-on: ubuntu-latest @@ -107,8 +285,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- protocol-and-stream-muxing + - 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: cd examples && npm run test -- protocol-and-stream-muxing test-pubsub-example: needs: check runs-on: ubuntu-latest @@ -117,8 +312,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- pubsub + - 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: cd examples && npm run test -- pubsub test-transports-example: needs: check runs-on: ubuntu-latest @@ -127,8 +339,25 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install - - run: cd examples && npm i && npm run test -- transports + - 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: cd examples && npm run test -- transports test-webrtc-direct-example: needs: check runs-on: ubuntu-latest @@ -137,5 +366,22 @@ jobs: - uses: actions/setup-node@v2 with: node-version: 16 - - run: npm install -g @mapbox/node-pre-gyp && npm install - - run: cd examples && npm i && npm run test -- webrtc-direct \ No newline at end of file + - 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: cd examples && npm run test -- webrtc-direct diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f4ffb7e2..e92a69b7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,21 +8,65 @@ on: - '**' 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: + needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: 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 build - run: npx aegir dep-check - uses: ipfs/aegir/actions/bundle-size@master name: size with: github_token: ${{ secrets.GITHUB_TOKEN }} + test-node: needs: check runs-on: ${{ matrix.os }} @@ -36,7 +80,23 @@ jobs: - uses: actions/setup-node@v2 with: 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 - uses: codecov/codecov-action@v1 test-chrome: @@ -47,7 +107,22 @@ jobs: - uses: actions/setup-node@v2 with: 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 test-firefox: needs: check @@ -57,7 +132,22 @@ jobs: - uses: actions/setup-node@v2 with: 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 test-ts: needs: check @@ -67,7 +157,22 @@ jobs: - uses: actions/setup-node@v2 with: 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 test-interop: needs: check @@ -77,5 +182,20 @@ jobs: - uses: actions/setup-node@v2 with: 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 diff --git a/examples/webrtc-direct/package.json b/examples/webrtc-direct/package.json index 0b912d1e..a77ab6fa 100644 --- a/examples/webrtc-direct/package.json +++ b/examples/webrtc-direct/package.json @@ -12,6 +12,7 @@ "devDependencies": { "@babel/cli": "^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-transform-regenerator": "^6.26.0", "babel-polyfill": "^6.26.0", diff --git a/package.json b/package.json index ce0ff5a2..ef014f71 100644 --- a/package.json +++ b/package.json @@ -155,7 +155,7 @@ "libp2p-floodsub": "^0.28.0", "libp2p-gossipsub": "^0.12.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-mdns": "^0.18.0", "libp2p-mplex": "^0.10.1", diff --git a/test/peer-routing/peer-routing.node.js b/test/peer-routing/peer-routing.node.js index f7835898..4c008a1c 100644 --- a/test/peer-routing/peer-routing.node.js +++ b/test/peer-routing/peer-routing.node.js @@ -75,11 +75,11 @@ describe('peer-routing', () => { it('should use the nodes dht', async () => { sinon.stub(nodes[0]._dht, 'findPeer').callsFake(async function * () { yield { - name: 'PEER_RESPONSE', - closer: [{ + name: 'FINAL_PEER', + peer: { id: nodes[1].peerId, multiaddrs: [] - }] + } } }) @@ -448,10 +448,8 @@ describe('peer-routing', () => { sinon.stub(node._dht, 'findPeer').callsFake(async function * () { yield { - name: 'PEER_RESPONSE', - closer: [ - result - ] + name: 'FINAL_PEER', + peer: result } }) sinon.stub(delegate, 'findPeer').callsFake(async () => { @@ -477,10 +475,8 @@ describe('peer-routing', () => { sinon.stub(node._dht, 'findPeer').callsFake(async function * () { yield { - name: 'PEER_RESPONSE', - closer: [ - result - ] + name: 'FINAL_PEER', + peer: result } }) sinon.stub(delegate, 'findPeer').callsFake(() => {})