-
Notifications
You must be signed in to change notification settings - Fork 44
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
Changes from all commits
7613011
7fc7aeb
d7a0e35
eb6f374
e9beb41
86f1bb2
c1ba8a9
4ab5f0a
29c189d
fe56735
dc0aeff
f678790
fa8a42b
1892c50
721624a
0593e38
45a0a46
2ed78de
0374d48
8ff250a
5d6f2cf
d1ac3fd
b19180f
3c9093e
a4af8ac
8d98811
d0c6bb7
5613492
8f43c20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,21 +6,40 @@ | |
# Check for more details: https://circleci.com/docs/2.1/configuration-reference | ||
version: 2.1 | ||
|
||
# in addition to the default circleCI triggering, we have a GitHub Action: | ||
# .github/triggered_target_build.yml | ||
# This Action has a job that uses CircleCI-Public/trigger-circleci-pipeline-action. | ||
# This allows triggering a CircleCI pipeline from any event on GitHub with GitHub Actions. | ||
# Right now we are using comments on PRs to trigger the workflow "triggered-by-pr-comment" | ||
# See: https://github.com/CircleCI-Public/trigger-circleci-pipeline-action/blob/main/README.md | ||
parameters: | ||
GHA_Actor: | ||
type: string | ||
default: "" | ||
GHA_Action: | ||
type: string | ||
default: "" | ||
GHA_Event: | ||
type: string | ||
default: "" | ||
GHA_Meta: | ||
type: string | ||
default: "" | ||
|
||
# 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/[email protected] | ||
|
||
# parameterize the make target used for build, passed in from build_trigger.yml action | ||
parameters: | ||
make_target: | ||
type: string | ||
default: "slimfast" | ||
|
||
jobs: | ||
build-docs: | ||
docker: | ||
- image: cimg/python:3.10.17 | ||
parameters: | ||
# Set make target for the job | ||
make_target: | ||
type: string | ||
default: slimfast | ||
steps: | ||
- checkout: | ||
path: docs | ||
|
@@ -47,7 +66,7 @@ jobs: | |
command: | | ||
. .venv/bin/activate | ||
cd docs | ||
xvfb-run --auto-servernum make << pipeline.parameters.make_target >> | ||
xvfb-run --auto-servernum make << parameters.make_target >> | ||
environment: | ||
PIP_CONSTRAINT: ../napari/resources/constraints/constraints_py3.10_docs.txt | ||
- store_artifacts: | ||
|
@@ -58,5 +77,24 @@ jobs: | |
- docs/docs/_build/html/ | ||
workflows: | ||
build-docs: | ||
# this workflow is triggered automatically by default | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I see what is confusing now. This wording is fine now. I do think that we should add to the top of this file the following:
|
||
# so we want to prevent it from triggering when triggering | ||
# via CircleCI-Public/trigger-circleci-pipeline-action | ||
# which always passes the GHA_Meta parameter | ||
# this prevents double triggers | ||
when: | ||
not: << pipeline.parameters.GHA_Meta >> | ||
Comment on lines
+85
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
# Run this workflow when a PR comment triggers a docs build for `make` target | ||
triggered-by-pr-comment: | ||
when: | ||
or: | ||
- equal: ["slimfast", << pipeline.parameters.GHA_Meta >>] | ||
- equal: ["slimgallery", << pipeline.parameters.GHA_Meta >>] | ||
- equal: ["docs", << pipeline.parameters.GHA_Meta >>] | ||
- equal: ["html", << pipeline.parameters.GHA_Meta >>] | ||
- equal: ["html-noplot", << pipeline.parameters.GHA_Meta >>] | ||
jobs: | ||
- build-docs: | ||
make_target: << pipeline.parameters.GHA_Meta >> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,23 @@ name: Build PR Docs | |
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- main | ||
workflow_dispatch: | ||
inputs: | ||
make_target: | ||
description: "Enter make target: html html-noplot docs slimfast slimgallery" | ||
type: string | ||
default: 'slimfast' | ||
default: "slimfast" | ||
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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. um, good question. let me try to look that up again. I think it's correct, but it's been a while since I looked at this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so this is analogous to the |
||
description: "PR branch reference" | ||
type: string | ||
required: false | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
|
@@ -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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adding branch to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If i recall There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as noted in the other spot, |
||
|
||
- name: Clone main repo | ||
uses: actions/checkout@v4 | ||
|
@@ -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 commentThe 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) |
||
# skipping setup stops the action from running the default (tiling) window manager | ||
# the window manager is not necessary for docs builds at this time and it was causing | ||
# problems with screenshots (https://github.com/napari/docs/issues/285) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
name: Trigger target build of docs | ||
# This workflow can be started either by commenting on a pull request or by using workflow_dispatch manually. | ||
# You can specify a `make` target to build the documentation for a specific branch or pull request. | ||
# If started by a comment, the workflow runs on the PR branch and updates the PR status. | ||
# Note: This workflow runs only once per trigger and does not execute on every push to the PR branch. | ||
# This workflow triggers both the CircleCI doc build, using CircleCI-Public/trigger-circleci-pipeline-action. | ||
# as well as an artifact build using the reusable workflow: .github/build_docs.yml | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
workflow_dispatch: | ||
inputs: | ||
make_target: | ||
description: "Enter make target: html html-noplot docs slimfast slimgallery" | ||
type: string | ||
default: "slimfast" | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
statuses: write | ||
|
||
jobs: | ||
determine-make-target: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
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 }} | ||
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
if: | | ||
(github.event_name == 'issue_comment' && | ||
github.event.issue.pull_request != '' && | ||
contains(github.event.comment.body, '@napari-bot make')) || | ||
github.event_name == 'workflow_dispatch' | ||
steps: | ||
- name: Add eyes reaction | ||
# If triggered by comment, show that workflow has started | ||
if: github.event_name == 'issue_comment' | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
await github.rest.reactions.createForIssueComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: context.payload.comment.id, | ||
content: 'eyes' | ||
}); | ||
|
||
- name: Determine make target from comment or input | ||
id: determine-make-target | ||
env: | ||
COMMENT_BODY: ${{ github.event.comment.body }} | ||
run: | | ||
ALLOWED_TARGETS="html html-noplot docs slimfast slimgallery" | ||
|
||
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
TARGET="${{ github.event.inputs.make_target }}" | ||
else | ||
TARGET=$(echo "$COMMENT_BODY" | grep -oP '(?<=@napari-bot make\s)\w+' || echo "slimfast") | ||
fi | ||
|
||
if ! echo "$ALLOWED_TARGETS" | grep -qw "$TARGET"; then | ||
echo "::error::Invalid target '$TARGET'. Allowed: $ALLOWED_TARGETS" | ||
exit 1 | ||
fi | ||
|
||
echo "target=$TARGET" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Get PR details | ||
# issue_comment is run from the main branch context so | ||
# extract PR number and branch name from issue_comment event | ||
if: github.event_name == 'issue_comment' | ||
id: get-pr-info | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const pr = await github.rest.pulls.get({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
pull_number: context.issue.number | ||
}); | ||
core.setOutput('pr_ref', pr.data.head.ref); | ||
core.setOutput('pr_sha', pr.data.head.sha); | ||
|
||
trigger-circleci: | ||
needs: determine-make-target | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Run CircleCI pipeline | ||
uses: CircleCI-Public/[email protected] | ||
with: | ||
GHA_Meta: ${{ needs.determine-make-target.outputs.target }} | ||
target-branch: ${{ needs.determine-make-target.outputs.pr_ref || github.ref_name }} | ||
Comment on lines
+94
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
env: | ||
CCI_TOKEN: ${{ secrets.CIRCLECI_TOKEN }} | ||
|
||
trigger-artifact-build: | ||
needs: determine-make-target | ||
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 commentThe 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. |
||
|
||
report-artifact-status: | ||
# reusable workflows can't be a step in a job | ||
# so to get the status of the artifact build, we need a separate job | ||
needs: [determine-make-target, trigger-artifact-build] | ||
runs-on: ubuntu-latest | ||
if: always() && github.event_name == 'issue_comment' && needs.trigger-artifact-build.result != 'skipped' | ||
steps: | ||
- name: Set build job status | ||
uses: myrotvorets/set-commit-status-action@master | ||
with: | ||
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 }} | ||
Comment on lines
+116
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
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.