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

Logs when its not the PR run on GH workflows #1439

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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