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

fix: Support retrieving the head SHA from workflow_run #549

Closed
wants to merge 1 commit into from

Conversation

polarathene
Copy link

For secure workflow as Github officially advises, a pull_request event should perform a build for untrusted code and then make that available to a workflow_run triggered workflow when secrets are needed. Such as deployment. As the 2nd workflow (workflow_run) is run from the main/production branch (eg master), it will have the wrong context.sha value.

The head commit SHA is available matching that of the pull_request event, using this will allow the action to apply it's features correctly to the intended commit on pull request, not on production branch latest commit.


Note: this is untested. I have not yet developed a Github Action, please test and review first.

AFAIK, assuming I got the context value correct (I am having trouble finding documentation on this), it should work correctly and only apply to workflow_run triggered workflows. I am not sure if it is always desirable to use the head SHA, but for typical pull_request event that would trigger the workflow_run, I believe it makes the most sense.

Alternatively, a user input could take priority which is more flexible?

For secure workflow as Github officially advises, a `pull_request` event should perform a build for untrusted code and then make that available to a `workflow_run` triggered workflow when secrets are needed. Such as deployment. As the 2nd workflow (`workflow_run`) is run from the main/production branch (eg master), it will have the wrong `context.sha` value.

The head commit SHA is available matching that of the pull_request event, using this will allow the action to apply it's features correctly to the intended commit on pull request, not on production branch latest commit.
@polarathene polarathene changed the title feat: Support retrieving the head SHA from workflow_run fix: Support retrieving the head SHA from workflow_run May 12, 2021
@polarathene
Copy link
Author

Should I add two new inputs here?

One for substitute PR number context.issue.number (inputs.targetPR()), and another for this PR getSHA() method?:

function getSHA(): string {
  return inputs.targetSHA() ?? context.payload.pull_request?.head.sha ?? context.sha
}

Open to better naming 😅

@polarathene
Copy link
Author

Closing due age of PR and lack of activity.

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.

1 participant