-
Notifications
You must be signed in to change notification settings - Fork 11
168 lines (139 loc) · 4.49 KB
/
build-deploy-docs.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
167
168
name: Site versioned build & deploy
on:
push:
branches: [develop]
workflow_dispatch:
permissions:
contents: read
deployments: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
env:
DistDir: dist
BuildDir: build
RepoUrl: ${{github.server_url}}/${{github.repository}}.git
SITE_BASE: ${{ vars.SITE_BASE }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Restore cached Docs
id: dist-cache
uses: actions/cache/restore@v4
with:
path: ${{ env.DistDir }}
key: ${{ env.DistDir }}-${{ hashFiles('deploy-versions.json') }}
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: build versions.json
run: jq -rc '. + input' "src/.vuepress/versions.json" deploy-versions.json > versions.json;
- if: ${{ steps.dist-cache.outputs.cache-hit != 'true' }}
name: Pull versions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
for row in $(jq -rc '.[] | @base64' deploy-versions.json); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
key=$(echo $(_jq '.key'));
tag=$(echo $(_jq '.tag'));
git clone --depth 1 -b "$tag" $RepoUrl "$BuildDir/$key"
cp versions.json "$BuildDir/$key/src/.vuepress/versions.json";
done
- if: ${{ steps.dist-cache.outputs.cache-hit != 'true' }}
name: Build versions
env:
NODE_OPTIONS: "--max_old_space_size=4096"
run: |
wrkdir=$(pwd);
for row in $(jq -rc '.[] | @base64' deploy-versions.json); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
key=$(echo $(_jq '.key'));
export DIST_DIR="$wrkdir/$DistDir";
export SITE_VERSION_KEY="$key";
mkdir -p "$DIST_DIR";
cd "$BuildDir/$key";
pnpm install && pnpm build;
cd $wrkdir;
done
- name: Build VuePress site
env:
NODE_OPTIONS: "--max_old_space_size=4096"
SITE_VERSION_KEY: next
run: |
cp versions.json "src/.vuepress/versions.json";
export DIST_DIR="$(pwd)/$DistDir";
pnpm build
- if: ${{ steps.dist-cache.outputs.cache-hit != 'true' }}
name: Save Docs
uses: actions/cache/save@v4
with:
path: ${{ env.DistDir }}
key: ${{ env.DistDir }}-${{ hashFiles('deploy-versions.json') }}
- name: Upload cloudflare-pages artifact
if: github.repository_owner == 'aklivity'
uses: actions/upload-artifact@v4
with:
name: cloudflare-pages
path: ${{ env.DistDir }}
- name: Upload github-pages artifact
if: github.repository_owner != 'aklivity'
uses: actions/upload-pages-artifact@v3
with:
path: ${{ env.DistDir }}/zilla-docs
deployCloudflarePages:
if: github.repository_owner == 'aklivity'
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
deployments: write
environment:
name: cloudflare-pages
url: ${{ steps.cloudflare-deployment.outputs.url }}
steps:
- name: Download cloudflare-pages artifact
uses: actions/download-artifact@v4
with:
name: cloudflare-pages
path: ${{ env.DistDir }}
- name: Move cloudflare files to root
run: mv ${{ env.DistDir }}/${{ env.SITE_BASE }}/next/cloudflare/* ${{ env.DistDir }}
- name: Publish to Cloudflare Pages
id: cloudflare-deployment
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: 65fb75109b09718cddae9ab7c68e2e3c
projectName: zilla-docs
directory: ${{ env.DistDir }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
deployGithubPages:
if: github.repository_owner != 'aklivity'
runs-on: ubuntu-latest
needs: build
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.github-deployment.outputs.page_url }}next
steps:
- name: Deploy to GitHub Pages
id: github-deployment
uses: actions/deploy-pages@v4