-
Notifications
You must be signed in to change notification settings - Fork 82
178 lines (164 loc) · 6.63 KB
/
call-release-doc.yaml
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
167
168
169
170
171
172
173
174
175
176
177
178
name: Call Release Doc
on:
workflow_call:
inputs:
ref:
required: true
type: string
# --- call by manual
workflow_dispatch:
inputs:
ref:
description: 'branch, tag, sha'
required: true
default: main
permissions: write-all
env:
MERGE_BRANCH: github_pages
DEV_DOC_DIRECTORY: dev
PR_LABEL: pr/release/robot_update_githubpage
PR_REVIWER: ty-dc
jobs:
release_doc:
runs-on: ubuntu-latest
outputs:
ref: ${{ env.REF }}
publish_docs_to_dev: ${{ env.PUBLISH_DOCS_TO_DEV }}
doc_tag: ${{ env.DOCS_TAG }}
steps:
- name: Get Ref
id: get_ref
run: |
pwd
ls
if ${{ github.event_name == 'workflow_dispatch' }}; then
echo "call by workflow_dispatch"
echo "REF=${{ github.event.inputs.ref }}" >> $GITHUB_ENV
elif ${{ inputs.ref != '' }}; then
echo "call by workflow_call"
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV
else
echo "unexpected event: ${{ github.event_name }}"
exit 1
fi
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ env.REF }}
- name: Set main branch docs to dev (latest)
id: main_docs
if: ${{ env.REF == 'main' }}
run: |
echo "DOCS_TAG=${{ env.REF }}" >> $GITHUB_ENV
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==8.5.11
git config user.email "[email protected]"
git config user.name "robot"
cp ./docs/mkdocs.yml ./
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})"
rm -rf ./site && rm -rf ./mkdocs.yml
git checkout -f ${{ env.MERGE_BRANCH }}
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs
tar -czvf ./site.tar.gz *
ls
echo "push document version ${{ env.DEV_DOC_DIRECTORY }} from branch ${{ env.REF }}."
- name: Extract Version
id: extract
if: ${{ env.REF != 'main' }}
run: |
if ! grep -E "^[[:space:]]*v[0-9]+.[0-9]+.[0-9]+[[:space:]]*$" VERSION &>/dev/null ; then
echo "It is not a release version. docs for the corresponding version will not be generated. The documents will be published to 'dev' ."
cat VERSION
echo "PUBLISH_DOCS_TO_DEV=true" >> $GITHUB_ENV
exit 0
fi
# for example v0.6.1, the build's documentation version is v0.6
docVersion=` cat VERSION | tr -d ' ' | tr -d '\n' | grep -Eo "v[0-9]+\.[0-9]+" `
if [ -n "${docVersion}" ]; then
echo "the version intercepted from the branch is: ${docVersion}"
else
echo "error, failed to get version." && exit 1
fi
git checkout -f ${{ env.MERGE_BRANCH }}
echo "Switch to the branch:${{ env.MERGE_BRANCH }} where the document is located"
ls
if [ -e "${docVersion}" ]; then
echo "doc version:${docVersion} already exists, just update it."
echo "SET_LATEST=false" >> $GITHUB_ENV
else
echo "The doc version:${docVersion} does not exist yet, while generating the doc and set it to latest"
echo "SET_LATEST=true" >> $GITHUB_ENV
fi
echo "the doc version is: ${docVersion}"
echo "DOCS_TAG=${docVersion}" >> $GITHUB_ENV
- name: build doc
id: build_doc
if: ${{ env.REF != 'main' }}
run: |
git checkout ${{ env.REF }}
ls
echo "switch to the release version branch ${{ env.REF }}"
pip install mkdocs==1.5.2 mike==1.1.2 mkdocs-material==8.5.11
git config user.email "[email protected]"
git config user.name "robot"
cp ./docs/mkdocs.yml ./
if ${{ env.PUBLISH_DOCS_TO_DEV == 'true' }} ; then
echo "publish non-release version of documentation to dev:${{ env.DEV_DOC_DIRECTORY }}"
echo "DOCS_TAG=${{ env.DEV_DOC_DIRECTORY }}" >> $GITHUB_ENV
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DEV_DOC_DIRECTORY }} -t "${{ env.DEV_DOC_DIRECTORY }} (${{ env.REF }})"
elif ${{ env.SET_LATEST == 'true' }} ; then
echo "generate doc version:${{ env.DOCS_TAG }} and set to latest."
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} --update-aliases ${{env.DOCS_TAG }} latest
mike set-default -b ${{ env.MERGE_BRANCH }} latest
else
echo "the version:${{ env.DOCS_TAG }} of the doc does not need to be set to the latest."
mike deploy --rebase -b ${{ env.MERGE_BRANCH }} ${{ env.DOCS_TAG }}
fi
rm -rf ./site
rm -rf ./mkdocs.yml
git checkout -f ${{ env.MERGE_BRANCH }}
rm -rf ./charts && rm -rf ./index.yaml && rm -rf ./changelogs
tar -czvf ./site.tar.gz *
ls
echo "Automatic release, offline package ready"
echo "Push a doc version: ${{ env.DOCS_TAG }} from branch: ${{ env.REF }}, update it to latest: ${{ env.SET_LATEST }} "
- name: Upload Artifact
uses: actions/[email protected]
with:
name: website_package_artifact
path: site.tar.gz
retention-days: 0
if-no-files-found: error
create_pr:
name: Create PR
needs: [release_doc]
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ env.MERGE_BRANCH }}
fetch-depth: 0
- name: Download Artifact
uses: actions/[email protected]
with:
name: website_package_artifact
- name: Untar Doc
run: |
tar -xzvf site.tar.gz
rm -f site.tar.gz
# Allow auto-merge on general
- name: Create Pull Request
id: create_pr
uses: peter-evans/[email protected]
with:
title: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}"
commit-message: "robot update website from ${{ needs.release_doc.outputs.ref }} to branch ${{ env.MERGE_BRANCH }} with tag ${{ needs.release_doc.outputs.doc_tag }}"
branch-suffix: timestamp
branch: robot/update_doc
delete-branch: true
base: ${{ env.MERGE_BRANCH }}
signoff: true
token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.PR_LABEL }}
reviewers: ${{ env.PR_REVIWER }}