From fb9f24afd3140062c84f193a9baffbfa29948981 Mon Sep 17 00:00:00 2001 From: orta Date: Thu, 18 Apr 2024 08:39:59 +0100 Subject: [PATCH 1/2] Logs when its not the PR run on GH workflows --- source/ci_source/providers/GitHubActions.ts | 11 +++++++++++ source/commands/ci/runner.ts | 7 +++++++ source/commands/init/add-to-ci.ts | 4 ++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/source/ci_source/providers/GitHubActions.ts b/source/ci_source/providers/GitHubActions.ts index 2c4aa702e..616e43eab 100644 --- a/source/ci_source/providers/GitHubActions.ts +++ b/source/ci_source/providers/GitHubActions.ts @@ -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.") + } +} diff --git a/source/commands/ci/runner.ts b/source/commands/ci/runner.ts index 78c7bda1f..de9c8cf8e 100644 --- a/source/commands/ci/runner.ts +++ b/source/commands/ci/runner.ts @@ -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") @@ -33,6 +34,7 @@ export const runRunner = async (app: SharedCLI, config?: Partial) 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 @@ -42,6 +44,11 @@ export const runRunner = async (app: SharedCLI, config?: Partial) 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 diff --git a/source/commands/init/add-to-ci.ts b/source/commands/init/add-to-ci.ts index 6e60d5d8c..08165a3d6 100644 --- a/source/commands/init/add-to-ci.ts +++ b/source/commands/init/add-to-ci.ts @@ -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:") @@ -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") From 686f4017cf2b2aec1635628328f1b6654f6f3806 Mon Sep 17 00:00:00 2001 From: orta Date: Thu, 18 Apr 2024 08:45:32 +0100 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c5318235..0481cfe86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ ## Main + +- Adds a log when you run on GitHub Actions without being a pull_request - [@orta] +