@@ -20,6 +20,8 @@ run-name: "Build and Publish (${{ inputs.slicer_repository }}@${{ inputs.slicer_
2020permissions :
2121 # Needed in the publish step to update gh-pages branch
2222 contents : write
23+ # Needed to update the status associated with the Slicer commit
24+ statuses : write
2325
2426jobs :
2527 build-and-publish :
4244 echo "::error ::Invalid skip value 'preview'. Supported values are 'true' or 'false'"
4345 exit 1
4446 fi
47+
48+ if [[ $preview == "false" ]]; then
49+ publish_repository="apidocs.slicer.org"
50+ else
51+ publish_repository="preview.apidocs.slicer.org"
52+ fi
53+ echo "publish_repository [$publish_repository]"
54+
4555 echo "slicer_repository=$slicer_repository" >> $GITHUB_OUTPUT
4656 echo "slicer_ref=$slicer_ref" >> $GITHUB_OUTPUT
4757 echo "preview=$preview" >> $GITHUB_OUTPUT
58+ echo "publish_repository=$publish_repository" >> $GITHUB_OUTPUT
4859 env :
4960 EVENT_NAME : ${{ github.event_name }}
5061
5465 path : Slicer
5566 ref : ${{ steps.collect_inputs.outputs.slicer_ref }}
5667
68+ - name : Slicer Checkout Details
69+ id : slicer-checkout-details
70+ run : |
71+ cd Slicer
72+ sha=$(git rev-parse HEAD)
73+ echo "sha [$sha]"
74+ echo "sha=$sha" >> $GITHUB_OUTPUT
75+
5776 - uses : actions/create-github-app-token@c1a285145b9d317df6ced56c09f525b5c2b6f755 # v1.11.1
5877 id : app-token
5978 with :
6382 repositories : |
6483 apidocs.slicer.org
6584 preview.apidocs.slicer.org
85+ Slicer
86+ Slicer-CI-Testing
87+
88+ - name : Set GitHub status to 'pending'
89+ run : |
90+ gh api \
91+ --method POST \
92+ -H "Accept: application/vnd.github+json" \
93+ /repos/${SLICER_REPO_NAME}/statuses/${SLICER_REPO_REVISION} \
94+ -f state='pending' \
95+ -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
96+ -f description='API documentation is being generated' \
97+ -f context='slicer/apidocs'
98+ env :
99+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
100+ SLICER_REPO_NAME : ${{ steps.collect_inputs.outputs.slicer_repository }}
101+ SLICER_REPO_REVISION : ${{ steps.slicer-checkout-details.outputs.sha }}
66102
67103 - name : Determine if ref is branch or tag
68104 id : determine
@@ -193,7 +229,7 @@ jobs:
193229
194230 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
195231 with :
196- repository : Slicer/${{ toJSON( steps.collect_inputs.outputs.preview) && 'preview.apidocs.slicer.org' || 'apidocs.slicer.org' }}
232+ repository : Slicer/${{ steps.collect_inputs.outputs.publish_repository }}
197233 ref : gh-pages
198234 path : gh-pages
199235 token : ${{ steps.app-token.outputs.token }}
@@ -236,3 +272,43 @@ jobs:
236272 SLICER_REPO_BRANCH : ${{ steps.determine.outputs.slicer_repo_branch }}
237273 SLICER_REPO_TAG : ${{ steps.determine.outputs.slicer_repo_tag }}
238274
275+ - name : Set GitHub status to 'success'
276+ run : |
277+ target_url_path="$SLICER_REPO_BRANCH"
278+ if [[ "$SLICER_REPO_TAG" != "" ]]; then
279+ target_url_path=$(echo "$SLICER_REPO_TAG" | grep -oE '^v[0-9]+\.[0-9]+')
280+ fi
281+ echo "target_url_path [$target_url_path]"
282+ target_url="https://${{ steps.collect_inputs.outputs.publish_repository }}/${target_url_path}"
283+ echo "target_url [$target_url]"
284+ gh api \
285+ --method POST \
286+ -H "Accept: application/vnd.github+json" \
287+ /repos/${SLICER_REPO_NAME}/statuses/${SLICER_REPO_REVISION} \
288+ -f state='success' \
289+ -f target_url="$target_url" \
290+ -f description='API documentation published' \
291+ -f context='slicer/apidocs'
292+ env :
293+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
294+ SLICER_REPO_NAME : ${{ steps.collect_inputs.outputs.slicer_repository }}
295+ SLICER_REPO_REVISION : ${{ steps.slicer-checkout-details.outputs.sha }}
296+ SLICER_REPO_BRANCH : ${{ steps.determine.outputs.slicer_repo_branch }}
297+ SLICER_REPO_TAG : ${{ steps.determine.outputs.slicer_repo_tag }}
298+
299+ - name : Set GitHub status to 'failure'
300+ if : ${{ failure() }}
301+ run : |
302+ gh api \
303+ --method POST \
304+ -H "Accept: application/vnd.github+json" \
305+ /repos/${SLICER_REPO_NAME}/statuses/${SLICER_REPO_REVISION} \
306+ -f state='failure' \
307+ -f target_url='https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' \
308+ -f description='API documentation failed to be generated' \
309+ -f context='slicer/apidocs'
310+ env :
311+ GH_TOKEN : ${{ steps.app-token.outputs.token }}
312+ SLICER_REPO_NAME : ${{ steps.collect_inputs.outputs.slicer_repository }}
313+ SLICER_REPO_REVISION : ${{ steps.slicer-checkout-details.outputs.sha }}
314+
0 commit comments