Skip to content

Commit

Permalink
Merge pull request #1439 from danger/logs_not_pr
Browse files Browse the repository at this point in the history
Logs when its not the PR run on GH workflows
  • Loading branch information
orta committed Apr 18, 2024
2 parents 05705c1 + 686f401 commit faa3d5d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,9 @@
## Main

<!-- Your comment below this -->

- Adds a log when you run on GitHub Actions without being a pull_request - [@orta]

<!-- Your comment above this -->


Expand Down
11 changes: 11 additions & 0 deletions source/ci_source/providers/GitHubActions.ts
Expand Up @@ -271,3 +271,14 @@ export class GitHubActions implements CISource {
// return process.env.BUILD_URL
// }
}

export const githubActionsWorkflowWarningCheck = () => {
const eventName = process.env.GITHUB_EVENT_NAME
const isPR = eventName === "pull_request"
if (!isPR) {
console.log(
"Note: Running Danger on with generalised GitHub Actions support, this does not include `danger.github.pr`."
)
console.log(" If you expected a PR run, change your workflow's 'on' to be pull_request.")
}
}
7 changes: 7 additions & 0 deletions source/commands/ci/runner.ts
Expand Up @@ -13,6 +13,7 @@ import dangerRunToRunnerCLI from "../utils/dangerRunToRunnerCLI"
import { CISource } from "../../ci_source/ci_source"
import { readFileSync } from "fs"
import { join } from "path"
import { githubActionsWorkflowWarningCheck } from "../../ci_source/providers/GitHubActions"

const d = debug("process_runner")

Expand All @@ -33,6 +34,7 @@ export const runRunner = async (app: SharedCLI, config?: Partial<RunnerConfig>)

const configSource = config && config.source
const source = configSource || (await getRuntimeCISource(app))
d(`Got a CI: ${source?.name}`)

// This does not set a failing exit code, because it's also likely
// danger is running on a CI run on the merge of a PR, and not just
Expand All @@ -42,6 +44,11 @@ export const runRunner = async (app: SharedCLI, config?: Partial<RunnerConfig>)
console.log("Skipping Danger due to this run not executing on a PR.")
}

// Extra logging for GitHub Actions
if (source && source.isPR && source.name === "GitHub Actions") {
githubActionsWorkflowWarningCheck()
}

// The optimal path when on a PR
if (source && source.isPR) {
const configPlatform = config && config.platform
Expand Down
4 changes: 2 additions & 2 deletions source/commands/init/add-to-ci.ts
Expand Up @@ -7,7 +7,7 @@ export const githubActions = async (ui: InitUI, state: InitState) => {
ui.say("So, you don't need to create a bot account.")
ui.pause(0.5)

ui.say("You will want to add a new step in an existing workflow yaml file.")
ui.say("You will want to add a new step in an existing workflow yaml file which uses `on: pull_request`.")
ui.pause(0.2)

ui.say("The step should look like this:")
Expand Down Expand Up @@ -38,7 +38,7 @@ export const githubActions = async (ui: InitUI, state: InitState) => {
ui.say("This would make Danger very spammy on a Pull Request.")

ui.pause(0.1)
ui.say("To get started, add a new step in an existing workflow file.")
ui.say("To get started, add a new step in an existing workflow file which uses `on: pull_request`.")
ui.say("The step should look like this:")
ui.say("")
ui.say("```yaml")
Expand Down

0 comments on commit faa3d5d

Please sign in to comment.