-
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?
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
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,34 @@ | |
# Check for more details: https://circleci.com/docs/2.1/configuration-reference | ||
version: 2.1 | ||
|
||
# these are required by https://github.com/CircleCI-Public/trigger-circleci-pipeline-action | ||
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: # job level setting of make target | ||
make_target: | ||
type: string | ||
default: slimfast | ||
steps: | ||
- checkout: | ||
path: docs | ||
|
@@ -47,7 +60,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: | ||
|
@@ -57,6 +70,21 @@ jobs: | |
paths: | ||
- docs/docs/_build/html/ | ||
workflows: | ||
# default trigger on push, don't double up with actions | ||
build-docs: | ||
when: | ||
not: << pipeline.parameters.GHA_Meta >> | ||
Comment on lines
+75
to
+76
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 | ||
# 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 commentThe 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. |
||
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. |
||
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. |
||
|
||
- 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,119 @@ | ||
name: Trigger target build of docs | ||
# this workflow is triggered by a comment on a PR or manually via workflow_dispatch | ||
# It allows you to specify a make target for building the docs for a branch/PR | ||
# When triggered by a comment, it will run on the PR branch and report status on the PR | ||
# # This is a one-time-run, it does not run on every push to the PR branch | ||
|
||
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
+27
to
+29
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
+92
to
+93
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
+114
to
+119
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.