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

Add optional commit SHA in config. #93

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jefchien
Copy link

Description

Allows the user to pass in a commit SHA to use instead of relying on the payload or head commit. The main use-case of this is for workflow dispatch runs where the SHA is provided through an input.

This change should be valid based on https://docs.github.com/en/rest/reference/commits#get-a-commit.

@jefchien jefchien force-pushed the add-optional-commit-sha branch from 4ab55a4 to 35c0db2 Compare December 17, 2021 21:25
@@ -235,7 +235,11 @@ async function getCommitFromGitHubAPIRequest(githubToken: string): Promise<Commi
};
}

async function getCommit(githubToken?: string): Promise<Commit> {
async function getCommit(githubToken?: string, commitSha?: string): Promise<Commit> {
if (commitSha && githubToken) {

Choose a reason for hiding this comment

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

Should this line be placed after the line 253-261 ? Mostly I can't see any reason to let this success faster though.

Copy link
Author

Choose a reason for hiding this comment

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

Well, if you've provided the commit SHA, then your intention is for the action to use it. I don't see why it should even attempt to use the other options.

Copy link

@khanhntd khanhntd left a comment

Choose a reason for hiding this comment

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

LGTM.

@ktrz
Copy link
Member

ktrz commented Dec 21, 2021

Hi @jefchien

Thank you for your contribution! Could you please explain to me a bit more why would we want to provide the SHA as an input rather than just using the one provided via pull request or fall back to the current commit's sha?

@jefchien
Copy link
Author

Hi @ktrz,

So, in my use case, the workflow where the action is used can be triggered by a workflow dispatch where the SHA is provided as an input. This allows us to run the benchmarking after successful CI workflow runs or on selected commits. The issue I've found is that the github.context.ref used in the fall back is the workflow commit SHA rather than the one actually used in the benchmarking. If there's another way to access the workflow dispatch inputs, it might be a better solution. This PR provides an optional field that will supersede any of the other attempts.

@NathanielRN
Copy link
Contributor

@jefchien

Is running the workflow_dispatch job event an automated process? Instead of providing the commit_sha as input, would you be able to push a branch or tag and run the workflow from there instead?

That way you can make the branch point to the commit you want, and run the workflow from that branch, so that the commit is correct and you don't need to provide the commit_sha as input.

It might be more tricky if your invocation of the workflow_dispatch job is automated (because you'd need a GitHub account to publish it from I guess) so that's why I ask.

@jefchien
Copy link
Author

jefchien commented Jan 6, 2022

@NathanielRN

Running the workflow_dispatch is a manual process, but the same workflow is also triggered by a repository_dispatch from a different workflow. That's an interesting workaround. I suppose I could use a GitHub action like https://github.com/marketplace/actions/create-branch to create the branch as part of the workflow and then checkout that branch in the job used to run this action. Actually, that probably won't work since the GitHub context is based on the workflow run.

@khanhntd
Copy link

khanhntd commented Feb 1, 2023

Hi @ktrz , any feedback though?

@ktrz
Copy link
Member

ktrz commented Feb 2, 2023

I'll get back to this during the weekend as I have a pretty busy week

Copy link
Member

@ktrz ktrz left a comment

Choose a reason for hiding this comment

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

The PR looks good. Just need some merge conflicts resolved. And please also include a test specific for your use-case

@@ -885,6 +886,7 @@ describe('writeBenchmark()', function () {
externalDataJsonPath: undefined,
maxItemsInChart: null,
failThreshold: 2.0,
commitSha: 'dummy sha',
Copy link
Member

Choose a reason for hiding this comment

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

I think we should add specific tests for the use-case where we set the explicit commitSha rather than just adding this param here.

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