FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid warning on workflow_call triggers by aeisenberg · Pull Request #2274 · github/codeql-action · GitHub

Avoid warning on workflow_call triggers - #2274

Merged
aeisenberg merged 1 commit into
mainfrom
aeisenberg/no-warn-workflow_call
May 8, 2024
Merged

Avoid warning on workflow_call triggers#2274
aeisenberg merged 1 commit into
mainfrom
aeisenberg/no-warn-workflow_call

Conversation

aeisenberg commented May 6, 2024
edited
Loading

Copy link
Copy Markdown
Contributor

Typically, we warn when there is no push trigger in the workflow file that triggered this run. However, when this action is triggered by a workflow_call event, we assume there is a custom process for triggering the action and we don't want to warn in this case.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

aeisenberg requested a review from a team as a code owner May 6, 2024 22:28
Comment thread src/workflow.ts Fixed
aeisenberg force-pushed the aeisenberg/no-warn-workflow_call branch from 6527f17 to 9a8503f Compare May 6, 2024 22:42
Comment thread src/workflow.ts Outdated
// Avoid warning when there this action was triggered via workflow_call since
// the user has a custom workflow that is calling this action and we assume
// they know what they are doing.
const isWorkflowCall = github.context.eventName === "workflow_call";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not certain this will work. If you're in a callee workflow, we only see the name of the event that started the caller workflow. I think you'll have to use other heuristics to parse the current workflow (which will be the caller) to recognise that it contains a workflow call, or simply doesn't contain a github/codeql-action step (which indicates that step is in the callee).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think Aditya is right, and we want to look for a workflow_call trigger, i.e. workflow_call appearing in the on property (note that this property may be a string or an array).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We just need to look for the presence of the property, IIUC. The value can also be null. Eg, this is legal:

on:
  workflow_call:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

How does on: workflow_call get parsed? I assumed it was a string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is parsed as null:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah...I see you were saying something different. We need to handle the following formats as well:

on: workflow_call

on:
   - workflow_call

aeisenberg force-pushed the aeisenberg/no-warn-workflow_call branch from 9a8503f to 43d7704 Compare May 7, 2024 18:11
Comment thread src/workflow.ts Fixed
aeisenberg force-pushed the aeisenberg/no-warn-workflow_call branch from 43d7704 to ee0b233 Compare May 7, 2024 18:18

Copy link
Copy Markdown
Contributor Author

I implemented the suggested changes, made a refactoring to make things a bit easier to understand, and added a handful of tests to verify.

Typically, we warn when there is no `push` trigger in the
workflow file that triggered this run. However, when this
action is triggered by a `workflow_call` event, we assume
there is a custom process for triggering the action and we
don't want to warn in this case.
aeisenberg force-pushed the aeisenberg/no-warn-workflow_call branch from ee0b233 to ca7f194 Compare May 7, 2024 20:30

henrymercer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice!

Comment thread src/workflow.ts
return doc.on.includes(triggerName);
}

return Object.prototype.hasOwnProperty.call(doc.on, triggerName);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think we can simplify this:

Suggested change
return Object.prototype.hasOwnProperty.call(doc.on, triggerName);
return Object.hasOwn(doc.on, triggerName);

aeisenberg May 8, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice. I didn't know about this function.

It's only available on node 16.9 and later. Are we sure that all supported GHES runners use that version or later?

Also, we need to update our tsconfig, or else we ge tlinter errors. So, I'm going to hold off for now and we can make the tsconfig changes later.

aeisenberg merged commit 7d9b7a1 into main May 8, 2024
aeisenberg deleted the aeisenberg/no-warn-workflow_call branch May 8, 2024 18:43
github-actions Bot mentioned this pull request May 13, 2024
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

4 participants


Back | FazBrowse Home | New Git URL