-
Notifications
You must be signed in to change notification settings - Fork 43
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: trigger pipeline for non main branches #11
fix: trigger pipeline for non main branches #11
Conversation
.DS_Store | ||
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding this for webstorm users
@@ -23,7 +23,7 @@ jobs: | |||
steps: | |||
- name: <customize name> | |||
id: <customize id> | |||
uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0 | |||
uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I copy pasted this I realised I wasn't on the latest version of the action. You may also want to maintain a v1
tag and update that on every release.
@@ -18,13 +18,13 @@ info(`Org: ${repoOrg}`); | |||
info(`Repo: ${repoName}`); | |||
const ref = context.ref; | |||
|
|||
const branch = () => { | |||
const getBranch = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed these so the intent is a bit clearer. I think if you were doing if (getTag) {
it would have been more obvious there was a bug here
if (tag) { | ||
Object.assign(parameters, { GHA_Tag: tag() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GHA_Tag
and GHA_Branch
were not documented in the readme and if they were set would have caused the circle build to fail as they wouldn't have been defined on the circle config. It doesn't make sense to pass them as parameters as they can be determined from within any job inside of circleci so I just removed them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct! I was trying to figure out why this code would be here (my fault obviously), and I think I found the broken train of thought. I think the original intent may have been to append "branch" and "tag" to the body.
You are correct we would not need either of those parameters, which led me to question why I put them there. I think the intent was the ensure the pipeline was triggered on a branch or tag, and it appears that is likely not working now.
https://circleci.com/docs/api/v2/#operation/triggerPipeline
Payload sample:
{
"branch": "feature/design-new-api",
"tag": "v3.1.4159",
"parameters": {
"deploy_prod": true
}
}
Rather than remove them I think we might want to make a few adjustments to ensure the branch/tag key are added to the body so that the pipeline is triggered at the right reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure! That's what we're now doing here (and was the main source of the bug):
trigger-circleci-pipeline-action/index.js
Lines 57 to 61 in d0dabb5
if (tag) { | |
Object.assign(body, { tag }); | |
} else { | |
Object.assign(body, { branch }); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on how we check the ref
field it looks like it's not possible to have both a tag AND a branch so I think it's correct to only pass one or the other
trigger-circleci-pipeline-action/index.js
Line 22 in d0dabb5
if (ref.startsWith("refs/heads/")) { |
trigger-circleci-pipeline-action/index.js
Line 28 in d0dabb5
if (ref.startsWith("refs/tags/")) { |
@@ -51,16 +51,24 @@ const body = { | |||
parameters: parameters, | |||
}; | |||
|
|||
const tag = getTag(); | |||
const branch = getBranch(); | |||
|
|||
if (tag) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously this was always truthy as we were referencing the function rather than its return value.
@@ -24,11 +24,10 @@ | |||
"dependencies": { | |||
"@actions/core": "^1.6.0", | |||
"@actions/github": "^5.0.0", | |||
"axios": "^0.24.0", | |||
"install": "^0.13.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these 2 were added as accidental dependencies
}, | ||
"devDependencies": { | ||
"@vercel/ncc": "^0.33.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added ncc as a dev dependency so things just work out the box without having to install it globally
Looks like this #12 or? |
I think we're running into the same problem here, where the action always triggers the main branch's pipeline, this PR fixes it so it only triggers the circle pipeline for the branch or tag that triggered the github action |
@KyleTryon any update on if we can get this merged soon? 😄 |
Apologies for the delay @mattlewis92. I reviewed the code, rebuilt it to verify and as there were no changes, immediately tagged your change. 🙇 thank you |
Awesome, thank you so much!! 🙌 |
Currently, GitHub references the default/main branch instead of the branch the PR was created from for all I'm trying to create a comment trigger so if I type something like There are a few complaints regarding this here: actions/checkout#331 (comment) Is there any way to make |
It may be preferable to set a v1 link and keep that updated to point to the latest release. Also mentioned in PR CircleCI-Public#11: CircleCI-Public#11 (comment)
Same problem here with @milosivanovic . Experiencing the same problem myself and have left a comment here actions/checkout#331 trying to see if there exists a solution. It seems like CircleCI is not picking up the branch correctly, is there an example of passing the branch as a parameter? |
* support events that don't have a payload For example, 'on: schedule' does not have a payload[1], which results in an error when attempting to use this action: TypeError: Cannot read property 'url' of undefined This commit updates the code to use the `repo` attribute instead of parsing out the repo org/name from the repo URL. 1. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule * prepare build ``` npm run lint && npm run format && npm run build ``` Added this as a separate commit, as I don't know anything about npm packages, and it's not clear if all of the package list changes are desirable. * README: unify version It may be preferable to set a v1 link and keep that updated to point to the latest release. Also mentioned in PR #11: #11 (comment)
* support events that don't have a payload For example, 'on: schedule' does not have a payload[1], which results in an error when attempting to use this action: TypeError: Cannot read property 'url' of undefined This commit updates the code to use the `repo` attribute instead of parsing out the repo org/name from the repo URL. 1. https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule * prepare build ``` npm run lint && npm run format && npm run build ``` Added this as a separate commit, as I don't know anything about npm packages, and it's not clear if all of the package list changes are desirable. * README: unify version It may be preferable to set a v1 link and keep that updated to point to the latest release. Also mentioned in PR CircleCI-Public#11: CircleCI-Public#11 (comment)
Hey there! I decided to give this action a go based on this blog post but I found that it kept trying to trigger the pipeline on the main branch rather than the branch which triggered the job. After a bit of digging I found the issue was that the tag and branch aren't being passed correctly to the circleci pipeline according to the docs
Also included several other fixes to make contributing easier (done as separate commits for a cleaner git history)