-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (130 loc) · 5.15 KB
/
Copy pathdeploy.yml
File metadata and controls
145 lines (130 loc) · 5.15 KB
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
name: Publish all books to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
publish_index:
uses: ./.github/workflows/publish_index.yml
setup_array:
runs-on: ubuntu-slim
outputs:
sites: ${{ steps.set_sites.outputs.sites }}
steps:
- name: Writing the book url names into a sharable matrix input
id: set_sites
run: |
{
echo 'sites<<EOF'
cat << 'JSON'
[
"user-guide",
"tutorials",
"quick-help",
"origin-help",
"x-function",
"originc",
"labtalk",
"python",
"externalpython",
"com",
"labview",
"app",
"appdev",
"codebuild",
"orglab",
"license"
]
JSON
echo 'EOF'
} >> "$GITHUB_OUTPUT"
start_array:
name: Start ${{ matrix.site }} deployment
needs: [setup_array, publish_index]
runs-on: ubuntu-slim
environment: deploy
env:
GH_TOKEN: ${{ secrets.PAT_DOC_WORKFLOW }}
strategy:
matrix:
site: ${{ fromJson(needs.setup_array.outputs.sites) }}
steps:
- name: Dispatch deploy.yml and capture the run url
id: dispatch
run: echo "deploy_run_url=$(gh workflow run deploy.yml --repo originlab/${{ matrix.site }})" >> "$GITHUB_ENV"
- name: Save the run id
run: echo "$deploy_run_url" | grep -oE "[0-9]+$" >> run_id.txt
- uses: actions/upload-artifact@v7
with:
name: run_id-${{ matrix.site }}
path: run_id.txt
retention-days: 1
get_result:
name: Watch ${{ matrix.site }} deployment
needs: [setup_array, start_array]
runs-on: ubuntu-slim
environment: deploy_watch
env:
GH_TOKEN: ${{ secrets.PAT_DOC_WORKFLOW }}
strategy:
matrix:
site: ${{ fromJson(needs.setup_array.outputs.sites) }}
steps:
- name: Download run_id-${{ matrix.site }}
uses: actions/download-artifact@v8
with:
name: run_id-${{ matrix.site }}
- name: Set $deploy_run_id
run: echo "deploy_run_id=$(cat run_id.txt)" >> "$GITHUB_ENV"
- name: Delete run_id-${{ matrix.site }}
run: |
gh api /repos/originlab/originlab.github.io/actions/runs/$GITHUB_RUN_ID/artifacts \
-q '.artifacts[] | select(.name == "run_id-${{ matrix.site }}") | .id' \
| xargs -I {} gh api --method DELETE /repos/originlab/originlab.github.io/actions/artifacts/{}
- name: Watch the deployment
run: gh run watch $deploy_run_id -R originlab/${{ matrix.site }} -i 10 --exit-status
- name: Set $build_job_id
run: echo "build_job_id=$(gh run view $deploy_run_id -R originlab/${{ matrix.site }} | grep 'publish_book / convert' | grep -oP '\(ID \K\d+')" >> "$GITHUB_ENV"
- name: Set $optimize_job_id
run: echo "optimize_job_id=$(gh run view $deploy_run_id -R originlab/${{ matrix.site }} | grep 'publish_book / optimize' | grep -oP '\(ID \K\d+')" >> "$GITHUB_ENV"
- name: Summarize the converter run
run: |
echo '# Converter run' >> "$GITHUB_STEP_SUMMARY"
gh run view $deploy_run_id -j $build_job_id -R originlab/${{ matrix.site }} --log \
| awk '/generator\.dll"/ {f=1} /upload-artifact/ {f=0} f' \
| cut -f3- | cut -d' ' -f2- \
| sed -E \
-e 's/\r//g' \
-e 's/\^\[\[[0-9;]*[a-zA-Z]//g' \
-e 's/^##\[group\](.*)/<details><summary>\1<\/summary><pre>/g' \
-e 's/^##\[endgroup\]/<\/pre><\/details>/g' \
-e 's/^##\[warning\](.*)/> [!WARNING]\n> \1/g' \
>> "$GITHUB_STEP_SUMMARY"
- name: Summarize the optimization run
run: |
echo '# Optimization run' >> "$GITHUB_STEP_SUMMARY"
gh run view $deploy_run_id -j $optimize_job_id -R originlab/${{ matrix.site }} --log \
| awk '/find pages\// {f=1} /upload-artifact/ {f=0} f' \
| cut -f3- | cut -d' ' -f2- \
| grep '##[warning]' \
| sed -E \
-e 's/\r//g' \
-e 's/\^\[\[[0-9;]*[a-zA-Z]//g' \
-e 's/^##\[group\](.*)/<details><summary>\1<\/summary><pre>/g' \
-e 's/^##\[endgroup\]/<\/pre><\/details>/g' \
-e 's/^##\[warning\](.*)/> [!WARNING]\n> \1/g' \
>> "$GITHUB_STEP_SUMMARY"
- name: Summarize artifacts
run: |
echo '# Artifacts' >> "$GITHUB_STEP_SUMMARY"
echo '| Name | Size |' >> "$GITHUB_STEP_SUMMARY"
echo '| :--- | ---: |' >> "$GITHUB_STEP_SUMMARY"
gh api /repos/originlab/${{ matrix.site }}/actions/runs/$deploy_run_id/artifacts \
-q '[.artifacts[]] | sort_by(.size_in_bytes) | reverse | .[] |
if .size_in_bytes < 1048576 then
"| \(.name) | \((.size_in_bytes/1024*10|round)/10) KB |"
else
"| \(.name) | \((.size_in_bytes/1024/1024*10|round)/10) MB |"
end' >> "$GITHUB_STEP_SUMMARY"