Skip to content

Commit

Permalink
test-pr-comment-delivery: have an explicit way to avoid triggering runs
Browse files Browse the repository at this point in the history
The main reason why some of the settings are disabled in this script is
so that no state is changed on github.com when debugging a webhook
payload event locally.

However, in some cases the GitForWindowsHelper app needs to query
GitHub's REST API using an access token because some queries cannot be
issued without authorization. For example, for some reason or other
reading workflow runs' logs requires a token (which is different than
what Azure Pipelines does, from which GitHub Actions were derived, so
this is doubly curious).

To help with such debugging scenarios, have a separate way to prevent
specifically triggering workflow runs, which would be the worst thing to
do inadvertently during a debugging session.

By default, the private key and Azure Pipelines trigger token are still
disabled in the script, but now it is at least somewhat safe to comment
out the private key disabling so that above-mentioned queries can be
debugged locally.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Feb 13, 2025
1 parent 92e1d90 commit 64b47fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions GitForWindowsHelper/azure-pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const triggerAzurePipeline = async (context, token, organization, project, build
}

const triggerGitArtifacts = async (context, prNumber) => {
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
throw new Error(`Would have triggered GitArtifacts for PR ${prNumber}`)
}
const githubApiRequest = require('./github-api-request')
const answer = await githubApiRequest(
context,
Expand Down Expand Up @@ -132,6 +135,9 @@ const createRelease = async (
}

const releaseGitArtifacts = async (context, prNumber) => {
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
throw new Error(`Would have triggered release for PR ${prNumber}`)
}
const githubApiRequest = require('./github-api-request')
const answer = await githubApiRequest(
context,
Expand Down
3 changes: 3 additions & 0 deletions GitForWindowsHelper/trigger-workflow-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ const waitForWorkflowRun = async (context, owner, repo, workflow_id, after, toke
}

const triggerWorkflowDispatch = async (context, token, owner, repo, workflow_id, ref, inputs) => {
if ('true' === process.env.DO_NOT_TRIGGER_ANYTHING) {
throw new Error(`Would have triggered workflow ${workflow_id} on ${owner}/${repo} with ref ${ref} and inputs ${JSON.stringify(inputs)}`)
}
const { headers: { date } } = await githubApiRequest(
context,
token,
Expand Down
1 change: 1 addition & 0 deletions test-pr-comment-delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
// avoid accidentally triggering anything
delete process.env.GITHUB_APP_PRIVATE_KEY
delete process.env.AZURE_PIPELINE_TRIGGER_TOKEN
process.env.DO_NOT_TRIGGER_ANYTHING = 'true'

const index = require('./GitForWindowsHelper/index')
console.log(await index(context, req) || context.res)
Expand Down

0 comments on commit 64b47fb

Please sign in to comment.