From ead81f0a3d82517a04ef904dfc28e2e8b1799ded Mon Sep 17 00:00:00 2001 From: Oscar Busk Date: Tue, 3 Mar 2020 22:42:10 +0100 Subject: [PATCH] Improve Github Actions (#7) * ci: Stop setting CI branch * ci: try to see if there is any branch reference in env * ci: fix env logging * ci: actually fix bundlewatch branchname * ci: Update name of bundlewatch step and build job * ci: clean up CI with naming steps somewhat * ci: cleanup yaml a bit by setting CI: true in all jobs instead of in steps * ci: Improve caching of npm * ci: make naming of build job the same as test job --- .github/workflows/nodejs.yml | 154 +++++++++++++++++++++-------------- 1 file changed, 93 insertions(+), 61 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 9709529..c881aaf 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -6,59 +6,72 @@ jobs: lint: runs-on: ubuntu-latest timeout-minutes: 5 + env: + CI: true steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Use Node.js 13x uses: actions/setup-node@v1 with: node-version: 13.x - - name: Cache node modules + - name: Get cache dir, Node Version and NPM Version + id: node-config + run: | + echo "::set-output name=nodev::$(node -v)" + echo "::set-output name=npmv::$(npm -v)" + echo "::set-output name=dir::$(npm config get cache)" + - name: Cache npm cache uses: actions/cache@v1 - env: - node-version: 13.x with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache- - - run: npm ci - env: - CI: true - - run: npm run lint - env: - CI: true + path: ${{ steps.node-config.outputs.dir }} + key: ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}- + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}- + ${{ runner.os }}- + - name: Install + run: npm ci + - name: Check Linting + run: npm run lint test: runs-on: ubuntu-latest timeout-minutes: 5 + env: + CI: true strategy: matrix: node-version: [10.16.x, 10.x, 12.x] steps: - - uses: actions/checkout@v2 + - name: Checkout + uses: actions/checkout@v2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} - - name: Cache node modules + - name: Get cache dir, Node Version and NPM Version + id: node-config + run: | + echo "::set-output name=nodev::$(node -v)" + echo "::set-output name=npmv::$(npm -v)" + echo "::set-output name=dir::$(npm config get cache)" + - name: Cache npm cache uses: actions/cache@v1 - env: - node-version: ${{ matrix.node-version }} with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache- - - run: npm ci - env: - CI: true - - run: npm run build - env: - CI: true - - run: npm test - env: - CI: true + path: ${{ steps.node-config.outputs.dir }} + key: ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}- + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}- + ${{ runner.os }}- + - name: Install + run: npm ci + - name: Run Tests + run: npm run test-coverage test-with-codecov: name: test (13.x) [With codecov] @@ -66,36 +79,42 @@ jobs: timeout-minutes: 5 steps: - - uses: actions/checkout@v2 - - name: Use Node.js 13x + - name: Checkout + uses: actions/checkout@v2 + - name: Use Node.js 13.x uses: actions/setup-node@v1 with: node-version: 13.x - - name: Cache node modules + - name: Get cache dir, Node Version and NPM Version + id: node-config + run: | + echo "::set-output name=nodev::$(node -v)" + echo "::set-output name=npmv::$(npm -v)" + echo "::set-output name=dir::$(npm config get cache)" + - name: Cache npm cache uses: actions/cache@v1 - env: - node-version: 13.x with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache- - - run: npm ci - env: - CI: true - - run: npm run build - env: - CI: true - - run: npm run test-coverage - env: - CI: true + path: ${{ steps.node-config.outputs.dir }} + key: ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}- + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}- + ${{ runner.os }}- + - name: Install + run: npm ci + - name: Run Tests + run: npm run test-coverage - name: Codecov uses: codecov/codecov-action@v1 with: token: ${{ secrets.CODECOV_TOKEN }} - bundlesize: + build-with-bundlewatch: + name: build (13.x) [With bundlewatch] runs-on: ubuntu-latest timeout-minutes: 5 + env: + CI: true steps: - uses: actions/checkout@v2 @@ -103,24 +122,37 @@ jobs: uses: actions/setup-node@v1 with: node-version: 13.x - - name: Cache node modules + - name: Get cache dir, Node Version and NPM Version + id: node-config + run: | + echo "::set-output name=nodev::$(node -v)" + echo "::set-output name=npmv::$(npm -v)" + echo "::set-output name=dir::$(npm config get cache)" + - name: Cache npm cache uses: actions/cache@v1 - env: - node-version: 13.x with: - path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS - key: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache-${{ hashFiles('**/package-lock.json') }} - restore-keys: ${{ runner.os }}-node-${{ env.node-version }}-npm-cache- - - run: npm ci - env: - CI: true - - run: npm run build - env: - CI: true - - run: npm run bundlewatch + path: ${{ steps.node-config.outputs.dir }} + key: ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}-npm-${{ steps.node-config.outputs.npmv }}- + ${{ runner.os }}-node-${{ steps.node-config.outputs.nodev }}- + ${{ runner.os }}- + - name: Install + run: npm ci + - name: Build + run: npm run build + # TODO: remove after https://github.com/bundlewatch/bundlewatch/pull/66 is merged and released + # https://stackoverflow.com/a/58035262 + - name: Extract the branch name + shell: bash + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" + id: extract_branch + - name: Check and Report Bundlesize + run: npm run bundlewatch env: BUNDLEWATCH_GITHUB_TOKEN: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} + # TODO: remove after https://github.com/bundlewatch/bundlewatch/pull/66 is merged and released CI_REPO_OWNER: "oBusk" CI_REPO_NAME: "read-bigint" CI_COMMIT_SHA: ${{ github.sha }} - CI_BRANCH: ${{ github.ref }} + CI_BRANCH: ${{ steps.extract_branch.outputs.branch }}