Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Danger #6637

Merged
merged 10 commits into from Jul 29, 2022
Merged

Danger #6637

merged 10 commits into from Jul 29, 2022

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Jul 25, 2022

This PR add Danger to the project. Please refer to the documentation included in this PR (rendered) for more detail about the tool itself.

Other changes:
quality.xml has been updated, because all commands that generate XML report must be run before Danger can use them to generate PR comments.

Once merged, the list of required GitHub action will have to be updated on GitHub.

Check with main dangerfile

Example of comment made by this check:

image

Check with lint

Examples of comments (first error from ktlint, second error from Detekt):

image

And comment example from lint:

image

@bmarty bmarty force-pushed the feature/bma/danger branch 7 times, most recently from f268050 to 135df78 Compare July 27, 2022 13:14
@element-hq element-hq deleted a comment from github-actions bot Jul 27, 2022
@element-hq element-hq deleted a comment from github-actions bot Jul 27, 2022
if: always()
id: ktlint-results
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary anymore, since Danger will post comments for each detected ktlint issue

@bmarty
Copy link
Member Author

bmarty commented Jul 28, 2022

For commit b0e019e

It was because we had this comment:

image

I do not know why this lint warning was reported, and not the 600+ other lint warnings.

@bmarty bmarty force-pushed the feature/bma/danger branch 2 times, most recently from f86cc57 to 73b8460 Compare July 28, 2022 09:51
path: |
*/build/reports/ktlint/ktlint*/ktlint*.txt
- name: Handle Results
*/build/reports/**/*.*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bmarty bmarty marked this pull request as ready for review July 28, 2022 14:24
Copy link
Contributor

@michaelkaye michaelkaye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it does the right things; I'm just a little concerned that https://github.com/vector-im/element-android/runs/7558101014?check_suite_focus=true#step:5:10 means we don't have the right accounts set up on it.

Found no issues or messages from Danger. Removing any existing messages on GitHub.
Could not add a commit status, the GitHub token for Danger does not have access rights.
If the build fails, then danger will use a failing exit code.

After merge would be good to see how 3rd party contributors see the requests - if they don't have the secret they might miss out on the danger report.

@sonarcloud
Copy link

sonarcloud bot commented Jul 29, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

steps:
- uses: actions/checkout@v3
- run: |
npm install --save-dev @babel/plugin-transform-flow-strip-types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is @babel/plugin-transform-flow-strip-types mandatory to run danger? I'm wondering if there's a local package.json/babel config we should apply this to as well 🤔

Copy link
Member Author

@bmarty bmarty Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, without this line, I got an error, see https://github.com/vector-im/element-android/runs/7524822865 :

Run danger/danger-js@9.1.6
/usr/bin/docker run --name cd98fa901ef5630854d6b946f9faf39f02a4d_20631b --label 4cd98f --workdir /github/workspace --rm -e GITHUB_TOKEN -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/element-android/element-android":"/github/workspace" 4cd98f:a901ef5630854d6b946f9faf39f02a4d
Error:  { Error: Cannot find module '@babel/plugin-transform-flow-strip-types' from '/github/workspace'
    at Function.module.exports [as sync] (/usr/src/danger/node_modules/resolve/lib/sync.js:40:15)
    at resolveStandardizedName (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:101:31)
    at resolvePlugin (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:54:10)
    at loadPlugin (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:62:20)
    at createDescriptor (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:154:9)
    at items.map (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:109:50)
    at Array.map (<anonymous>)
    at createDescriptors (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:109:29)
    at createPluginDescriptors (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:105:10)
    at alias (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:63:49) code: 'MODULE_NOT_FOUND' }

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this is more https://github.com/vector-im/element-android/runs/7526127685 :

Run danger/danger-js@11.1.1
/usr/bin/docker run --name cd98fbc3b34cafe1d46bbabf9cc41d533b8f8_c74665 --label 4cd98f --workdir /github/workspace --rm -e GITHUB_TOKEN -e HOME -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF -e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL -e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME -e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE -e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY -e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV -e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH -e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP -e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN -e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true -v "/var/run/docker.sock":"/var/run/docker.sock" -v "/home/runner/work/_temp/_github_home":"/github/home" -v "/home/runner/work/_temp/_github_workflow":"/github/workflow" -v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" -v "/home/runner/work/element-android/element-android":"/github/workspace" 4cd98f:bc3b34cafe1d46bbabf9cc41d533b8f8
Error:  Error: Cannot find module '@babel/plugin-transform-flow-strip-types'
Require stack:
- /usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js
- /usr/src/danger/node_modules/@babel/core/lib/config/files/index.js
- /usr/src/danger/node_modules/@babel/core/lib/index.js
- /usr/src/danger/distribution/runner/runners/utils/transpiler.js
- /usr/src/danger/distribution/runner/runners/inline.js
- /usr/src/danger/distribution/commands/danger-runner.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at resolve (internal/modules/cjs/helpers.js:107:19)
    at resolveStandardizedName (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:111:7)
    at resolvePlugin (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:55:10)
    at loadPlugin (/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js:63:20)
    at loadPlugin.next (<anonymous>)
    at createDescriptor (/usr/src/danger/node_modules/@babel/core/lib/config/config-descriptors.js:187:16)
    at createDescriptor.next (<anonymous>)
    at evaluateSync (/usr/src/danger/node_modules/gensync/index.js:251:28)
    at /usr/src/danger/node_modules/gensync/index.js:31:34 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/src/danger/node_modules/@babel/core/lib/config/files/plugins.js',
    '/usr/src/danger/node_modules/@babel/core/lib/config/files/index.js',
    '/usr/src/danger/node_modules/@babel/core/lib/index.js',
    '/usr/src/danger/distribution/runner/runners/utils/transpiler.js',
    '/usr/src/danger/distribution/runner/runners/inline.js',
    '/usr/src/danger/distribution/commands/danger-runner.js'
  ]
}

To run danger locally, install it and run:

```shell
bundle exec danger pr <PR_URL> --dangerfile=./tools/danger/dangerfile.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth mentioning that there's 2 implementations of danger, JS and Ruby, it looks like we're using the JS version in the github action but the Ruby version locally, this could introduce differences~

yarn danger pr <PR URL>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for the heads up. I'll keep that in mind for the future 👍

Copy link
Contributor

@ouchadam ouchadam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! no blockers from me 💯

@bmarty
Copy link
Member Author

bmarty commented Jul 29, 2022

Thanks for the review, let's merge the PR and see what we will get on other PRs!

@bmarty bmarty merged commit 59f00cd into develop Jul 29, 2022
@bmarty bmarty deleted the feature/bma/danger branch July 29, 2022 10:55
@bmarty bmarty mentioned this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants