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

Release tags are created on pull requests despite having set a release_branch #150

Open
mikael-andersson91 opened this issue Nov 5, 2022 · 6 comments

Comments

@mikael-andersson91
Copy link

Hi,
I am attempting to use this action as part of a workflow that is triggered both on push and pull_request events on for my main branch with the following inputs:

steps:
  - uses: actions/checkout@v3
  
  - name: Bump version and push tag
    id: tag_version
    uses: mathieudutour/github-tag-action@v6.1
    with:
      github_token: ${{ secrets.GITHUB_TOKEN }}
      release_branches: main

The issue here comes when I run the workflow on pull requests a release tag is always created, despite having specified main as my only release branch. My understanding of the input documentation copied below is that pull requests would generate a version number with the commit hash as a suffix and not generate a tag, while push on release branch would generate a release tag. Have I misunderstood something with the implementation here?

release_branches (optional) - Comma separated list of branches (JavaScript regular expression accepted) that will generate the release tags. Other branches and pull-requests generate versions postfixed with the commit hash and do not generate any repository tag. Examples: master or .* or release.,hotfix.,master... (default: master,main).

Example job triggering a release on pull request:
https://github.com/mikael-andersson91/try-tag-actions/actions/runs/3396811156/jobs/5648291822

And in-case viewing the workflow run isn't available for you, here's the log from a pull request run where a release tag was created:
image

@mikael-andersson91
Copy link
Author

mikael-andersson91 commented Nov 9, 2022

export function isPr(ref: string) {
return ref.includes('refs/pull/');
}

My understanding of this function is that it is supposed to check for pull request events. This would only check for pulls though?

Edit: Nevermind, might have misunderstood that as well.
https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@orkenstein
Copy link

@mikael-andersson91 so did you manage to generate prerelease tags? I struggle with branches like feature/*

@orkenstein
Copy link

@mathieudutour Mathie, thanks you very much for this wonderful aciton!
What should we do to avoid tag creation on PR?

@mathieudutour
Copy link
Owner

Just don't run the action on PRs?

@mikael-andersson91
Copy link
Author

mikael-andersson91 commented May 16, 2023

If that is your solution the README of the repository is misleading on the functionality of the action. I can accept it not being intended to be used for that functionality, but then it shouldn't say this in the README regarding the release_branches argument:
release_branches (optional) - Comma separated list of branches (JavaScript regular expression accepted) that will generate the release tags. Other branches and pull-requests generate versions postfixed with the commit hash and do not generate any repository tag. Examples: master or .* or release.,hotfix.,master... (default: master,main).

Edit:
Running the action on a PR would in most cases mean one does not run it on the master,main branches. At least not when working according to GitHub Flow and having branch protection on those branches

Edit 2: As noted in the issue, when running the action on pull requests tags are created with the next release tag, not a version tag with the commit hash postfix as noted in the README

StevenMaude added a commit to opensafely-core/ehrql that referenced this issue May 17, 2023
We only want to consider tagging the main branch and pull requests.

In principle, this workflow should only be triggered by pushes to main
(because this is configured by `on`), but this is an extra safeguard
should that change.

Recent versions of github-tag-action have slightly confusing behaviour around tagging PRs:

mathieudutour/github-tag-action#150

Confusingly, as that issue mentions, there is an option that specifies
release branches with a *supposed* behaviour:

> **release_branches** (*optional*) - Comma separated list of branches
> (JavaScript regular expression accepted) that will generate the release
> tags. Other branches and pull-requests generate versions postfixed with
> the commit hash and do not generate any repository tag. Examples:
> `master` or `.*` or `release.*,hotfix.*,master`... (default:
> `master,main`).

However, when we tried upgrading to github-tag-action v6.1 before, it was tagging
pull requests, I believe.
@orkenstein
Copy link

Just don't run the action on PRs?

This is definitely an option, but requires a bit more struggle. It would be awesome not to tag on PR as mentioned in README

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

No branches or pull requests

3 participants