mathieudutour / github-tag-action

A Github Action to automatically bump and tag master, on merge, with the latest SemVer formatted version. Works on any platform.
https://github.com/marketplace/actions/github-tag
MIT License
640 stars 201 forks source link

feat: support refs through commit_sha input #175

Closed roxchkplusony closed 1 year ago

roxchkplusony commented 1 year ago

Use case

I want to be able to run an action manually and specify the commit I want to tag. By default, I want to provide heads/main in my repository which should map to whatever the head commit is. commit_sha is pretty good as an override when I have a commit, but if I want the branch ref, it won't work. The error I get when I provided main is something like:

❗ ::error::Invalid request.%0A%0AAt least 40 characters are required; only 4 were supplied.

Modifications

Similar to how many git porcelain commands accept any refs, including commit SHAs and branch refs, I wrote a validation method that will check that the commit SHA is valid, and resolve a branch ref to a SHA if it wasn't a valid SHA. This allows plumbing calls like octokit.git.createTag() to work because the object actually refers to a SHA in all these intended cases.

Test

Locally, I wrote a quick and dirty test to call this method with my own repository configuration and access token. main doesn't work, but heads/main works just fine. The test looks something like

await expect(validatedCommitShaInput('heads/main')).resolves..toEqual(commitSha)

Alternatives

One can simply set GITHUB_REF so that it reflects the branch the user wants to be on, and hopefully encapsulates the commit as well.

roxchkplusony commented 1 year ago

@mathieudutour I'm going to close this PR. If you find yourself interested you'll always have the diff.