-
Notifications
You must be signed in to change notification settings - Fork 21
148 lines (135 loc) · 4.35 KB
/
deploy-docs.yml
File metadata and controls
148 lines (135 loc) · 4.35 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
146
147
148
name: Deploy Docs
on:
push:
branches: ["3.x", "2.x", "1.x"]
paths:
- 'docs/**'
- '.github/workflows/deploy-docs.yml'
workflow_dispatch:
inputs:
version:
description: 'Version branch to deploy (e.g., 3.x, 2.x, 1.x)'
required: true
type: choice
options:
- '3.x'
- '2.x'
- '1.x'
# Prevent concurrent deploys to avoid push conflicts
concurrency:
group: deploy-docs
cancel-in-progress: false
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "branch=${{ inputs.version }}" >> $GITHUB_OUTPUT
else
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
fi
- name: Set version config
id: config
run: |
BRANCH="${{ steps.version.outputs.branch }}"
case $BRANCH in
3.x)
echo "dest_folder=." >> $GITHUB_OUTPUT
echo "base_url=/custom-fields/" >> $GITHUB_OUTPUT
echo "is_latest=true" >> $GITHUB_OUTPUT
;;
2.x)
echo "dest_folder=v2" >> $GITHUB_OUTPUT
echo "base_url=/custom-fields/v2/" >> $GITHUB_OUTPUT
echo "is_latest=false" >> $GITHUB_OUTPUT
;;
1.x)
echo "dest_folder=v1" >> $GITHUB_OUTPUT
echo "base_url=/custom-fields/v1/" >> $GITHUB_OUTPUT
echo "is_latest=false" >> $GITHUB_OUTPUT
;;
*)
echo "Unknown branch: $BRANCH"
exit 1
;;
esac
- name: Checkout source branch
uses: actions/checkout@v4
with:
ref: ${{ steps.version.outputs.branch }}
- name: Checkout gh-pages
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: 'docs/package-lock.json'
- name: Install dependencies
working-directory: ./docs
run: npm ci
- name: Build documentation
working-directory: ./docs
run: npm run generate
env:
NUXT_APP_BASE_URL: ${{ steps.config.outputs.base_url }}
NUXT_SITE_URL: https://relaticle.github.io
DOCS_VERSION: ${{ steps.version.outputs.branch }}
- name: Deploy to gh-pages
run: |
DEST="${{ steps.config.outputs.dest_folder }}"
IS_LATEST="${{ steps.config.outputs.is_latest }}"
if [ "$IS_LATEST" == "true" ]; then
echo "Deploying latest version to root..."
cd gh-pages
# List of items to preserve
PRESERVE="v1 v2 versions.json .nojekyll README.md .git"
# Remove everything except preserved items
for item in *; do
if [ -e "$item" ]; then
SKIP=false
for keep in $PRESERVE; do
if [ "$item" == "$keep" ]; then
SKIP=true
break
fi
done
if [ "$SKIP" == "false" ]; then
rm -rf "$item"
fi
fi
done
# Also remove hidden files except .git, .nojekyll
for item in .[!.]*; do
if [ -e "$item" ] && [ "$item" != ".git" ] && [ "$item" != ".nojekyll" ]; then
rm -rf "$item"
fi
done
cd ..
# Copy new build to root
cp -r docs/.output/public/* gh-pages/
else
echo "Deploying to $DEST subfolder..."
rm -rf "gh-pages/$DEST"
cp -r docs/.output/public "gh-pages/$DEST"
fi
- name: Commit and push
working-directory: ./gh-pages
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add -A
if git diff --staged --quiet; then
echo "No changes to deploy"
else
git commit -m "Deploy ${{ steps.version.outputs.branch }} docs"
git push
fi