-
Notifications
You must be signed in to change notification settings - Fork 41
Fix comment and manual dispatch triggered build jobs #723
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
base: main
Are you sure you want to change the base?
Conversation
# Orbs are reusable packages of CircleCI configuration that you may share across projects. | ||
# See: https://circleci.com/docs/2.1/orb-intro/ | ||
orbs: | ||
python: circleci/python@3.0.0 | ||
|
||
# parameterize the make target used for build, passed in from build_trigger.yml action |
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.
With the change to use https://github.com/CircleCI-Public/trigger-circleci-pipeline-action we will be triggering a workflow (below) and then passing the make target as a job parameter, rather than pipeline parameter. So here we remove this.
when: | ||
not: << pipeline.parameters.GHA_Meta >> |
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.
This change is needed to prevent double-triggers. We want the normal workflow to trigger on push/commit/PR status only, not when the comment/trigger is used.
jobs: | ||
- build-docs | ||
# triggered by comment to PR with make target | ||
triggered-by-issue-comment: |
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.
So now for the triggered job, we use a new workflow that checks the GHA_Meta pipeline parameter and kicks off our build-docs job with the right job parameter.
workflow_call: | ||
inputs: | ||
make_target: | ||
description: "Enter make target: html html-noplot docs slimfast slimgallery" | ||
type: string | ||
default: 'slimfast' | ||
default: "slimfast" | ||
pr_ref: |
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.
Add another input parameter so that we can pass the PR detail from the triggering job.
@@ -33,6 +37,7 @@ jobs: | |||
with: | |||
# Check out to '/home/runner/work/docs/docs/docs' | |||
path: docs | |||
ref: ${{ inputs.pr_ref || github.ref }} |
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.
Here make sure to be able to use the branch info passed in from the triggering job or just the regular dispatch.
@@ -70,7 +75,7 @@ jobs: | |||
GOOGLE_CALENDAR_API_KEY: ${{ secrets.GOOGLE_CALENDAR_API_KEY }} | |||
PIP_CONSTRAINT: ${{ github.workspace }}/napari/resources/constraints/constraints_py3.10_docs.txt | |||
with: | |||
run: make -C docs ${{ github.event_name == 'pull_request' && 'slimfast' || inputs.make_target }} | |||
run: make -C docs ${{ inputs.make_target || 'slimfast' }} |
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.
Make sure the trigger works for both PR triggers and manual dispatch (both use inputs.make_target)
target: ${{ steps.determine-make-target.outputs.target }} | ||
pr_ref: ${{ steps.get-pr-info.outputs.pr_ref }} | ||
pr_sha: ${{ steps.get-pr-info.outputs.pr_sha }} |
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.
These are the 3 key things we need to know about the trigger:
- what make target
- pr details, so we can get the right stuff to build and then report back to the right status.
GHA_Meta: ${{ needs.determine-make-target.outputs.target }} | ||
target-branch: ${{ needs.determine-make-target.outputs.pr_ref || github.ref_name }} |
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.
Here we pass in the make target from the earlier job and then ensure that status reporting works by also passing in the branch information. If a manual dispatch is used, it will also work (GitHub.ref_name).
uses: ./.github/workflows/build_docs.yml | ||
with: | ||
make_target: ${{ needs.determine-make-target.outputs.target }} | ||
pr_ref: ${{ needs.determine-make-target.outputs.pr_ref || github.ref_name }} |
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.
Again, this is the branch info we need to build the right stuff.
sha: ${{ needs.determine-make-target.outputs.pr_sha }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
status: ${{ needs.trigger-artifact-build.result }} | ||
context: "Docs Artifact Build: ${{ needs.determine-make-target.outputs.target }}" | ||
description: ${{ needs.trigger-artifact-build.result == 'success' && 'Documentation built successfully' || 'Documentation build failed' }} | ||
targetUrl: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
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.
Here's the reporting. We have the right PR info, so then we collect the pass/fail status and the make target so we can put that in the PR status.
@psobolewskiPhD |
@napari-bot make slimfast |
My comment above did trigger an action, but does not add the eyes at the time I expected, which would be at the start of the action. |
Ah, not quite fully hooked up correctly yet: |
@TimMonko this repo (napari/docs) is using the actions from the default branch (main), so your comment is using the not-correct original implementation. (it was these branch complications that led my original attempt astray, as can be seen by the needed changes) |
Somehow I didn't put it all together reading your (excellent) PR description. Thank you for the clarification! Thanks! |
If you click to this run, on the left you can click |
That can work if the action is triggered by PR push for example. But in this case, the triggers are not from the branch of the PR, but from an outside context (comment, label, etc.), which lives in the default branch of the repo. |
Thank you for the extra clarification! Really helping me to learn. The very reason workflow ran from main was why I was concerned, but I now realize how this 'outside context' makes this the issue, and why it is a challenge to troubleshoot this type of CI. |
References and relevant issues
Currently, comments are not properly triggering jobs.
The primary issue is that comment triggers are from the main branch context and not PR context.
For circleCI it's even harder, because if you checkout the PR and then run CircleCI it will still internal checkout the wrong branch.
Also reporting back to the PR was also not working.
I did some googling and sorted out a pathway using CircleCI-Public/trigger-circleci-pipeline-action
-- not sure how I missed it before?
Also consulted Claude a bit.
Description
I ended up re-doing the whole action, so I gave it a new name. I think the diff would be atrocious, so this is easier.
The main change here are as follows. First for the Circle part:
We get the target-branch from the "PR details" step of the first job
determine-make-target
Importantly, this also sets us up for a followup PR to check for a label and run full build. With this implementation that will be trivial by comparison.
Now for the artifact build:
Fun part:
I made the PR branch my main branch in my fork and then opened a PR vs that, which you can find here:
psobolewskiPhD#90
You can see that things came together and work!
Feel free to try a comment!