forked from sagemath/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (148 loc) · 7.01 KB
/
doc-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Publish documentation
on:
workflow_run:
workflows: ["Build documentation"]
types:
- completed
permissions:
statuses: write
checks: write
pull-requests: write
# This workflow runs after doc-build workflow, taking the artifact
# (doc/livedoc) and deploying it to a netlify site.
#
# event (triggered doc-build) URL (of the doc deployed to NETLIFY_SITE)
# --------------------------- ---------------------------------
# on pull request https://doc-pr-12345--NETLIFY_SITE
# on push branch develop https://doc-develop--NETLIFY_SITE
# on push tag https://doc-10-4-beta2--NETLIFY_SITE
# on push tag https://doc-release--NETLIFY_SITE
#
# where NETLIFY_SITE is presently sagemath.netlify.app for repo sagemath/sage.
#
# This workflow runs only if secrets NETLIFY_AUTH_TOKEN and NETLIFY_SITE_ID are set.
jobs:
publish-doc:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
env:
CAN_DEPLOY: ${{ secrets.NETLIFY_AUTH_TOKEN != '' && secrets.NETLIFY_SITE_ID != '' }}
steps:
- name: Get information about workflow origin
uses: potiuk/get-workflow-origin@v1_5
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
if: env.CAN_DEPLOY == 'true'
- name: Download doc
id: download-doc
uses: actions/download-artifact@v4
with:
name: doc
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}
if: steps.source-run-info.outputs.sourceEvent == 'pull_request' || (steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch == 'develop')
- name: Extract doc
run: unzip doc.zip -d doc
if: steps.download-doc.outcome == 'success'
- name: Deploy to Netlify
id: deploy-netlify
uses: netlify/actions/cli@master
with:
args: deploy --dir=doc/doc --message ${NETLIFY_MESSAGE} --alias ${NETLIFY_ALIAS}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_MESSAGE: doc-${{ steps.source-run-info.outputs.pullRequestNumber && format('pr-{0}', steps.source-run-info.outputs.pullRequestNumber) || 'develop' }}
NETLIFY_ALIAS: doc-${{ steps.source-run-info.outputs.pullRequestNumber && format('pr-{0}', steps.source-run-info.outputs.pullRequestNumber) || 'develop' }}
if: steps.download-doc.outcome == 'success'
# Add deployment as status check, PR comment and annotation we could use
# the nwtgck/actions-netlify action for that, except for that it is not
# (yet) working in workflow_run context: https://github.com/nwtgck/actions-netlify/issues/545
- name: Add/Update deployment status PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.source-run-info.outputs.pullRequestNumber }}
header: preview-comment
recreate: false
message: |
[Documentation preview for this PR](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}/html/en) (built with commit ${{ steps.source-run-info.outputs.sourceHeadSha }}; [changes](${{ steps.deploy-netlify.outputs.NETLIFY_URL }}/CHANGES.html)) is ready! :tada:
This preview will update shortly after each push to this PR.
if: steps.download-doc.outcome == 'success'
- name: Update deployment status PR check
uses: myrotvorets/[email protected]
env:
DEPLOY_SUCCESS: Successfully deployed preview.
DEPLOY_FAILURE: Failed to deploy preview.
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status == 'success' && 'success' || 'failure' }}
sha: ${{ github.event.workflow_run.head_sha }}
context: Deploy Documentation
targetUrl: ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}
description: ${{ job.status == 'success' && env.DEPLOY_SUCCESS || env.DEPLOY_FAILURE }}
if: steps.download-doc.outcome == 'success'
- name: Report deployment url
run: |
echo "::notice::The documentation has been deployed - ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}"
if: steps.download-doc.outcome == 'success'
publish-live-doc:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
env:
CAN_DEPLOY: ${{ secrets.NETLIFY_AUTH_TOKEN != '' && secrets.NETLIFY_SITE_ID != '' }}
steps:
- name: Get information about workflow origin
uses: potiuk/get-workflow-origin@v1_5
id: source-run-info
with:
token: ${{ secrets.GITHUB_TOKEN }}
sourceRunId: ${{ github.event.workflow_run.id }}
if: env.CAN_DEPLOY == 'true'
- name: Download live doc
id: download-doc
uses: actions/download-artifact@v4
with:
name: livedoc
github-token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
run-id: ${{ github.event.workflow_run.id }}
# if the doc was built for tag push (targetBranch contains the tag)
if: steps.source-run-info.outputs.sourceEvent == 'push' && steps.source-run-info.outputs.targetBranch != 'develop'
- name: Extract live doc
run: unzip livedoc.zip -d livedoc
if: steps.download-doc.outcome == 'success'
- name: Create _headers file for permissive CORS
run: |
cat <<EOF > livedoc/livedoc/_headers
/*
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: Content-Type
EOF
if: steps.download-doc.outcome == 'success'
- name: Deploy to netlify with doc-TAG alias
id: deploy-netlify
uses: netlify/actions/cli@master
with:
args: deploy --dir=livedoc/livedoc --message ${NETLIFY_MESSAGE} --alias ${NETLIFY_ALIAS}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
NETLIFY_MESSAGE: doc-${{ steps.source-run-info.outputs.targetBranch }}
NETLIFY_ALIAS: doc-${{ steps.source-run-info.outputs.targetBranch }}
if: steps.download-doc.outcome == 'success'
- name: Deploy to netlify with doc-release alias
uses: netlify/actions/cli@master
with:
args: deploy --dir=livedoc/livedoc --message doc-release --alias doc-release
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
if: steps.download-doc.outcome == 'success'
- name: Report deployment url
run: |
echo "::notice::The live documentation has been deployed - ${{ steps.deploy-netlify.outputs.NETLIFY_URL }}"
if: steps.download-doc.outcome == 'success'