From 278154fc90a88f42e66fec251c533a5d91447d28 Mon Sep 17 00:00:00 2001 From: Jakub Mikulas Date: Fri, 21 Aug 2020 18:31:32 +0200 Subject: [PATCH 1/4] chore: remove Danger.js from Circle And rename Smoke test to Regression test as it contains more than just smoke --- .circleci/config.yml | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 57565d17a12..fd85ae16ab1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -87,7 +87,7 @@ commands: command: npm --version jobs: - smoke-test: + regression-test: <<: *defaults docker: - image: circleci/node:<< parameters.node_version >> @@ -130,16 +130,6 @@ jobs: unset SNYK_API_KEY shellspec -f d - danger: - <<: *defaults - docker: - - image: circleci/node:<< parameters.node_version >> - steps: - - checkout - - run: - name: Danger Zone - command: npx danger ci --failOnErrors - test-windows: <<: *defaults <<: *windows_defaults @@ -206,19 +196,10 @@ workflows: version: 2 test_and_release: jobs: - - danger: - name: Danger Zone - node_version: '8' - filters: - branches: - ignore: - - master - - smoke-test: - name: Smoke Test + - regression-test: + name: Regression Test context: nodejs-install node_version: '8' - requires: - - Danger Zone filters: branches: ignore: @@ -228,7 +209,7 @@ workflows: context: nodejs-install node_version: '12.0.0' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -238,7 +219,7 @@ workflows: context: nodejs-install node_version: '14' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -248,7 +229,7 @@ workflows: context: nodejs-install node_version: '10.21.0' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -258,7 +239,7 @@ workflows: context: nodejs-install node_version: '8.17.0' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -268,7 +249,7 @@ workflows: context: nodejs-install node_version: '12.16.2' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -278,7 +259,7 @@ workflows: context: nodejs-install node_version: '14' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -288,7 +269,7 @@ workflows: context: nodejs-install node_version: '10' requires: - - Smoke Test + - Regression Test filters: branches: ignore: @@ -298,7 +279,7 @@ workflows: context: nodejs-install node_version: '8' requires: - - Smoke Test + - Regression Test filters: branches: ignore: From 32e143cf56f5992f2710d65eb9f22a27ee796c63 Mon Sep 17 00:00:00 2001 From: Jakub Mikulas Date: Fri, 21 Aug 2020 18:35:23 +0200 Subject: [PATCH 2/4] chore: introduce Danger.js as GitHub Action --- .github/workflows/danger-zone.yml | 17 +++++++++++++++++ .../{release-notes.yaml => release-notes.yml} | 0 2 files changed, 17 insertions(+) create mode 100644 .github/workflows/danger-zone.yml rename .github/workflows/{release-notes.yaml => release-notes.yml} (100%) diff --git a/.github/workflows/danger-zone.yml b/.github/workflows/danger-zone.yml new file mode 100644 index 00000000000..ed453744965 --- /dev/null +++ b/.github/workflows/danger-zone.yml @@ -0,0 +1,17 @@ +name: 'Danger Zone' +on: + pull_request: + branches: [master] + +jobs: + build: + name: Danger JS + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Danger + uses: danger/danger-js@9.1.8 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # https://github.com/danger/danger-js/issues/557#issuecomment-664851950 + DANGER_DISABLE_TRANSPILATION: true diff --git a/.github/workflows/release-notes.yaml b/.github/workflows/release-notes.yml similarity index 100% rename from .github/workflows/release-notes.yaml rename to .github/workflows/release-notes.yml From db9ea14b5421f233cc46330897ec38084425d991 Mon Sep 17 00:00:00 2001 From: Jakub Mikulas Date: Tue, 25 Aug 2020 10:23:49 +0200 Subject: [PATCH 3/4] chore(danger): check Smoke test branch & unmodified tests --- dangerfile.js | 52 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/dangerfile.js b/dangerfile.js index 5845efceea9..4508f947737 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -1,11 +1,15 @@ -const {danger, warn, fail, message} = require('danger'); +const { danger, warn, fail, message } = require('danger'); + +const MAX_COMMIT_MESSAGE_LENGTH = 72; +const SMOKE_TEST_BRANCH = 'feat/smoke-test'; +const SMOKE_TEST_WORKFLOW_FILE_PATH = '.github/workflows/smoke-tests.yml'; if (danger.github && danger.github.pr) { const commitizenRegex = /^(feat|fix|chore|test|docs|perf|refactor|revert)(\(.*\))?:(.+)$/; const ghCommits = danger.github.commits; let willTriggerRelease = false; - for (const {commit} of ghCommits) { - const {message, url} = commit; + for (const { commit } of ghCommits) { + const { message, url } = commit; const firstLine = message.split('\n')[0]; if (message.startsWith('feat') || message.startsWith('fix')) { @@ -14,15 +18,49 @@ if (danger.github && danger.github.pr) { const regexMatch = commitizenRegex.exec(firstLine); if (!regexMatch) { - fail(`Commit ["${firstLine}"](${url}) is not a valid commitizen message. See [Contributing page](https://github.com/snyk/snyk/blob/master/.github/CONTRIBUTING.md#commit-types) with required commit message format.`); + fail( + `Commit ["${firstLine}"](${url}) is not a valid commitizen message. See [Contributing page](https://github.com/snyk/snyk/blob/master/.github/CONTRIBUTING.md#commit-types) with required commit message format.`, + ); } - if (firstLine.length >= 72) { - warn(`Your commit message ["${firstLine}"](${url}) is too long. Keep first line of your commit under 72 characters.`); + if (firstLine.length >= MAX_COMMIT_MESSAGE_LENGTH) { + warn( + `Your commit message ["${firstLine}"](${url}) is too long. Keep first line of your commit under ${MAX_COMMIT_MESSAGE_LENGTH} characters.`, + ); } } if (!willTriggerRelease) { - message('This PR will not trigger a new version. It doesn\'t include any commit message with `feat` or `fix`.'); + message( + "This PR will not trigger a new version. It doesn't include any commit message with `feat` or `fix`.", + ); + } + + // Forgotten tests check + const modifiedTest = danger.git.modified_files.some((f) => + f.startsWith('test/'), + ); + const modifiedSrc = danger.git.modified_files.some((f) => + f.startsWith('src/'), + ); + + if (modifiedSrc && !modifiedTest) { + // TODO: let's be careful about wording here. Maybe including Contributing guidelines and project goals document here + warn( + "You've modified files in src/ directory, but haven't updated anything in test folder. Is there something that could be tested?", + ); + } + + // Smoke test modification check + const modifiedSmokeTest = + danger.git.modified_files.some((f) => f.startsWith('test/smoke/')) || + danger.git.modified_files.includes(SMOKE_TEST_WORKFLOW_FILE_PATH); + + const isOnSmokeTestBranch = danger.github.pr.head.ref === SMOKE_TEST_BRANCH; + + if (modifiedSmokeTest && !isOnSmokeTestBranch) { + message( + `You are modifying something in test/smoke directory, yet you are not on the branch ${SMOKE_TEST_BRANCH}. You can rename your branch to ${SMOKE_TEST_BRANCH} and Smoke tests will trigger for this PR.`, + ); } } From 2250e947ad8632808255e440ee18284d92f48ab7 Mon Sep 17 00:00:00 2001 From: Jakub Mikulas Date: Tue, 25 Aug 2020 10:24:01 +0200 Subject: [PATCH 4/4] chore: trigger smoke test on relases as well --- .github/workflows/smoke-tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 07a40f64cb4..285e2818e32 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -3,6 +3,9 @@ name: Smoke Tests on: push: branches: [feat/smoke-test] +on: + release: + types: [published] schedule: - cron: '0 * * * *'