Skip to content

Commit

Permalink
Merge pull request #1357 from snyk/chore/move-danger-to-gh-action
Browse files Browse the repository at this point in the history
Move Danger.js to GitHub Action
  • Loading branch information
JackuB committed Aug 25, 2020
2 parents 812dc4d + 2250e94 commit 2582bda
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 37 deletions.
41 changes: 11 additions & 30 deletions .circleci/config.yml
Expand Up @@ -87,7 +87,7 @@ commands:
command: npm --version

jobs:
smoke-test:
regression-test:
<<: *defaults
docker:
- image: circleci/node:<< parameters.node_version >>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -228,7 +209,7 @@ workflows:
context: nodejs-install
node_version: '12.0.0'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -238,7 +219,7 @@ workflows:
context: nodejs-install
node_version: '14'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -248,7 +229,7 @@ workflows:
context: nodejs-install
node_version: '10.21.0'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -258,7 +239,7 @@ workflows:
context: nodejs-install
node_version: '8.17.0'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -268,7 +249,7 @@ workflows:
context: nodejs-install
node_version: '12.16.2'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -278,7 +259,7 @@ workflows:
context: nodejs-install
node_version: '14'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -288,7 +269,7 @@ workflows:
context: nodejs-install
node_version: '10'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand All @@ -298,7 +279,7 @@ workflows:
context: nodejs-install
node_version: '8'
requires:
- Smoke Test
- Regression Test
filters:
branches:
ignore:
Expand Down
17 changes: 17 additions & 0 deletions .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
File renamed without changes.
3 changes: 3 additions & 0 deletions .github/workflows/smoke-tests.yml
Expand Up @@ -3,6 +3,9 @@ name: Smoke Tests
on:
push:
branches: [feat/smoke-test]
on:
release:
types: [published]
schedule:
- cron: '0 * * * *'

Expand Down
52 changes: 45 additions & 7 deletions 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')) {
Expand All @@ -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.`,
);
}
}

0 comments on commit 2582bda

Please sign in to comment.