From de2b79197cf954c7a3dac959dd94fd271bd5c5bf Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 20:44:07 +0000 Subject: [PATCH 1/7] Consistency pass on .github/workflows - Use setup-node with .nvmrc in all workflows - Prefer to use checkout with an explicit ref in all workflows - Minor legibility pass on step names/spacing --- .github/workflows/codeql-analysis.yml | 17 ++++++++++++----- .github/workflows/integration-test.yml | 26 ++++++++++++++++++++------ .github/workflows/test.yml | 16 ++++++++++++++-- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 1a5e26f..c0bda33 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -24,17 +24,24 @@ jobs: language: [ 'javascript' ] steps: - - name: Checkout repository - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Read .nvmrc + id: nvm + run: echo ::set-output name=NVMRC::$(cat .nvmrc) + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ steps.nvm.outputs.NVMRC }} - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: languages: ${{ matrix.language }} - - name: Install dependencies - run: npm ci - - name: Build executable run: npm run package diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 981d97d..677a7c2 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -13,16 +13,30 @@ jobs: integration: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - token: ${{ secrets.GITHUB_TOKEN }} - name: GPR login run: docker login docker.pkg.github.com -u x -p ${{ secrets.GITHUB_TOKEN }} + - name: GRP pull dependabot/dependabot-updater run: docker pull docker.pkg.github.com/dependabot/dependabot-updater:v1 + - name: GRP pull github/dependabot-update-job-proxy run: docker pull docker.pkg.github.com/github/dependabot-update-job-proxy:v1 - - run: npm ci - - name: Run integration test files + + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Read .nvmrc + id: nvm + run: echo ::set-output name=NVMRC::$(cat .nvmrc) + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ steps.nvm.outputs.NVMRC }} + + - name: Install NPM dependencies + run: npm ci + + - name: Run integration tests run: npm run test-integration diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 88da9e2..c7de449 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,20 +12,32 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: Read .nvmrc id: nvm run: echo ::set-output name=NVMRC::$(cat .nvmrc) + - name: Setup Node.js uses: actions/setup-node@v1 with: node-version: ${{ steps.nvm.outputs.NVMRC }} - - run: npm ci - - run: npm run all + + - name: Install NPM dependencies + run: npm ci + + - name: Run tests + run: npm run all + - run: git diff --quiet dist/ test: # make sure the action works on a clean machine without building runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + - uses: ./ with: milliseconds: 1000 From 8ba73ea3abf634a1637da2c81e799d733dd003b3 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 20:57:11 +0000 Subject: [PATCH 2/7] Ensure the build fails on format/lint issues --- .github/workflows/test.yml | 8 +++++++- package.json | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c7de449..2a09a76 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,8 +27,14 @@ jobs: - name: Install NPM dependencies run: npm ci + - name: Check formatting + run: npm run format-check + + - name: Run linter + run: npm run lint-check + - name: Run tests - run: npm run all + run: npm run test - run: git diff --quiet dist/ test: # make sure the action works on a clean machine without building diff --git a/package.json b/package.json index ab013d5..0d7f3b5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "main": "src/main.ts", "scripts": { "format": "prettier --write **/*.ts", + "format-check": "prettier --check **/*.ts", "lint": "eslint --fix **/*.ts", + "lint-check": "eslint **/*.ts", "package": "ncc build -o dist/main src/main.ts --source-map --license licenses.txt && ncc build -o dist/cleanup src/cleanup.ts --source-map --license licenses.txt", "test": "SKIP_INTEGRATION_TESTS=true jest --detectOpenHandles", "test-integration": "jest --detectOpenHandles 'integration'", From 7db94e52afd3326f9534247555e40b10ca318439 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 21:04:55 +0000 Subject: [PATCH 3/7] Check the dist/ folder in a separate workflow --- .github/workflows/check-dist.yml | 45 ++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 12 +-------- 2 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/check-dist.yml diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml new file mode 100644 index 0000000..21e40bf --- /dev/null +++ b/.github/workflows/check-dist.yml @@ -0,0 +1,45 @@ +name: Check dist/ + +on: + pull_request: + push: + branches: + - main + - 'releases/*' + +jobs: + verify-build: # make sure the checked in dist/ folder matches the output of a rebuild + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - name: Read .nvmrc + id: nvm + run: echo ::set-output name=NVMRC::$(cat .nvmrc) + + - name: Setup Node.js + uses: actions/setup-node@v1 + with: + node-version: ${{ steps.nvm.outputs.NVMRC }} + + - name: Install NPM dependencies + run: npm ci + + - name: Rebuild the dist/ directory + run: npm run package + + - name: Compare the expected and actual dist/ directories + run: git diff --quiet dist/ + verify-index-js: # make sure the entrypoint js files run on a clean machine without compiling first + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.sha }} + + - uses: ./ + with: + milliseconds: 1000 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2a09a76..9bd5b09 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: - 'releases/*' jobs: - build: # make sure build/ci work properly + test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -37,13 +37,3 @@ jobs: run: npm run test - run: git diff --quiet dist/ - test: # make sure the action works on a clean machine without building - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - - - uses: ./ - with: - milliseconds: 1000 From aade2a84596e86ac3cb096f0a2d1f9e264de8629 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 21:36:59 +0000 Subject: [PATCH 4/7] Humanise the diff check failures --- .github/workflows/check-dist.yml | 4 ++-- script/check-diff | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100755 script/check-diff diff --git a/.github/workflows/check-dist.yml b/.github/workflows/check-dist.yml index 21e40bf..fdb4d93 100644 --- a/.github/workflows/check-dist.yml +++ b/.github/workflows/check-dist.yml @@ -1,4 +1,4 @@ -name: Check dist/ +name: Check dist on: pull_request: @@ -32,7 +32,7 @@ jobs: run: npm run package - name: Compare the expected and actual dist/ directories - run: git diff --quiet dist/ + run: script/check-diff verify-index-js: # make sure the entrypoint js files run on a clean machine without compiling first runs-on: ubuntu-latest steps: diff --git a/script/check-diff b/script/check-diff new file mode 100755 index 0000000..bc45833 --- /dev/null +++ b/script/check-diff @@ -0,0 +1,9 @@ +#!/bin/bash + +git diff --quiet dist/ +retVal=$? +if [ $retVal -ne 0 ]; then + echo "Detected uncommitted changes after build:" + git --no-pager diff dist/ + exit 1 +fi From 3cf6580c9c1eb57bc6803bcc12d0fb435ffa3a4b Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 21:42:40 +0000 Subject: [PATCH 5/7] Slim down our CodeQL config --- .github/workflows/codeql-analysis.yml | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c0bda33..2fc573d 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,32 +18,15 @@ jobs: contents: read security-events: write - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - steps: - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} - - name: Read .nvmrc - id: nvm - run: echo ::set-output name=NVMRC::$(cat .nvmrc) - - - name: Setup Node.js - uses: actions/setup-node@v1 - with: - node-version: ${{ steps.nvm.outputs.NVMRC }} - - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: - languages: ${{ matrix.language }} - - - name: Build executable - run: npm run package + languages: javascript - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 From a30b27850891dd1f9f9bb7e69020a729ce677975 Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Thu, 10 Feb 2022 21:53:31 +0000 Subject: [PATCH 6/7] Avoid breaking continuity with our existing CodeQL analysis --- .github/workflows/codeql-analysis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 2fc573d..e1e2af3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -18,6 +18,10 @@ jobs: contents: read security-events: write + strategy: + matrix: + language: [ 'javascript' ] + steps: - uses: actions/checkout@v2 with: @@ -26,7 +30,7 @@ jobs: - name: Initialize CodeQL uses: github/codeql-action/init@v1 with: - languages: javascript + languages: ${{ matrix.language }} - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v1 From b1090a38161542fe8592576c5de9173779d4dc9b Mon Sep 17 00:00:00 2001 From: Barry Gordon Date: Fri, 11 Feb 2022 10:48:50 +0000 Subject: [PATCH 7/7] Actually remove the diff check from the test workflow --- .github/workflows/test.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9bd5b09..c4786e4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,5 +35,3 @@ jobs: - name: Run tests run: npm run test - - - run: git diff --quiet dist/