From 0242e0519455f9e841afe6ee77bcf14fe1704dfd Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 13 Jan 2021 13:31:16 +0100 Subject: [PATCH 1/3] Updated versions of used actions --- .github/workflows/lint.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index dd7aeb28..31004478 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,10 +5,9 @@ on: [push] jobs: lint-js: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 with: node-version: "11.x" - name: Install dependencies @@ -18,10 +17,9 @@ jobs: lint-sol: runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 with: node-version: "11.x" - name: Install dependencies From 80fa4f677daf95d775611b76750f187ab5e21a86 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 13 Jan 2021 13:31:33 +0100 Subject: [PATCH 2/3] Separated `npm ci` execution to a shared job We want just one `npm ci` job to happen so other jobs can use resolved `node_modules` folder. --- .github/workflows/lint.yml | 83 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 31004478..75e2d4b0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,26 +3,101 @@ name: Run linters on: [push] jobs: + # Setup that results will be used by other jobs. + install: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: "12.x" + + ## Cache `node_nodules` directory so it can be used by other jobs. + # Get exact Node version. It will be included in cache's key as there can + # be differences between resolved dependencies depending on Node version. + - name: Get Node version + id: node-version + run: echo "::set-output name=version::$(node --version)" + # Cache `node_modules` directory for specific OS, Node version and `package-lock.json` + # files hash. The cache will be used by subsequent jobs execution. + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: node-modules + with: + path: node_modules + key: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.node-version.outputs.version }}-${{ hashFiles('**/package-lock.json') }} + # Install dependencies. It won't use currently cached `node_modules` directory + # but do a clean installation. Resolved directory will be cached afterwards. + - name: Install dependencies + run: npm ci + lint-js: + needs: install runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: "11.x" + node-version: "12.x" + + ## Restore `node_nodules` from cache initialized in `install` job. + # Get exact Node version. + - name: Get Node version + id: node-version + run: echo "::set-output name=version::$(node --version)" + # Restore cache for specific OS, Node version and `package-lock.json` files hash. + # It is expected that the cache will always be found as it was initialized + # in `install` job executed as a requirement of this job. + - name: Restore cached node modules + id: node-cache + uses: actions/cache@v2 + env: + cache-name: node-modules + with: + path: node_modules + key: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.node-version.outputs.version }}-${{ hashFiles('**/package-lock.json') }} + # As a fallback to not found cached node_modules directory execute `npm ci` + # to install dependencies. It's not expected to happen, but better be safe + # than sorry. - name: Install dependencies - run: npm install + if: steps.node-cache.outputs.cache-hit != 'true' + run: npm ci + - name: Run JS linter run: npm run lint:js lint-sol: + needs: install runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: - node-version: "11.x" + node-version: "12.x" + + ## Restore `node_nodules` from cache initialized in `install` job. + # Get exact Node version. + - name: Get Node version + id: node-version + run: echo "::set-output name=version::$(node --version)" + # Restore cache for specific OS, Node version and `package-lock.json` files hash. + # It is expected that the cache will always be found as it was initialized + # in `install` job executed as a requirement of this job. + - name: Restore cached node modules + id: node-cache + uses: actions/cache@v2 + env: + cache-name: node-modules + with: + path: node_modules + key: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.node-version.outputs.version }}-${{ hashFiles('**/package-lock.json') }} + # As a fallback to not found cached node_modules directory execute `npm ci` + # to install dependencies. It's not expected to happen, but better be safe + # than sorry. - name: Install dependencies - run: npm install + if: steps.node-cache.outputs.cache-hit != 'true' + run: npm ci + - name: Run Solidity linter run: npm run lint:sol From 0b4c9ddb5b36ff8e2c1b9aff02e5739ae164c83e Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski Date: Wed, 13 Jan 2021 14:04:13 +0100 Subject: [PATCH 3/3] Combine all node CI jobs happening on push Moved node tests execution to one workflow so it is faster. We execute just one `npm ci` to install dependencies and then use resolved `node_modules` in all jobs. --- .github/workflows/{lint.yml => node.yml} | 42 +++++++++++++++++++++++- .github/workflows/solidity-test.yml | 22 ------------- 2 files changed, 41 insertions(+), 23 deletions(-) rename .github/workflows/{lint.yml => node.yml} (73%) delete mode 100644 .github/workflows/solidity-test.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/node.yml similarity index 73% rename from .github/workflows/lint.yml rename to .github/workflows/node.yml index 75e2d4b0..e16b0c65 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/node.yml @@ -1,4 +1,4 @@ -name: Run linters +name: Node.js CI on: [push] @@ -101,3 +101,43 @@ jobs: - name: Run Solidity linter run: npm run lint:sol + + run-tests: + needs: install + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: "12.x" + + ## Restore `node_nodules` from cache initialized in `install` job. + # Get exact Node version. + - name: Get Node version + id: node-version + run: echo "::set-output name=version::$(node --version)" + # Restore cache for specific OS, Node version and `package-lock.json` files hash. + # It is expected that the cache will always be found as it was initialized + # in `install` job executed as a requirement of this job. + - name: Restore cached node modules + id: node-cache + uses: actions/cache@v2 + env: + cache-name: node-modules + with: + path: node_modules + key: ${{ runner.os }}-${{ env.cache-name }}-${{ steps.node-version.outputs.version }}-${{ hashFiles('**/package-lock.json') }} + # As a fallback to not found cached node_modules directory execute `npm ci` + # to install dependencies. It's not expected to happen, but better be safe + # than sorry. + - name: Install dependencies + if: steps.node-cache.outputs.cache-hit != 'true' + run: npm ci + + - name: Run tests + # Runs ganache in background + run: | + npm run buidler-vm & + npm test + env: + CI: true diff --git a/.github/workflows/solidity-test.yml b/.github/workflows/solidity-test.yml deleted file mode 100644 index 4c865d50..00000000 --- a/.github/workflows/solidity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Test Solidity - -on: [push] - -jobs: - run-tests: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: "11.x" - - name: Install dependencies - run: npm install - - name: Run tests - # Runs ganache in background - run: | - npm run buidler-vm & - npm test - env: - CI: true