-
Notifications
You must be signed in to change notification settings - Fork 10
149 lines (124 loc) · 5.02 KB
/
deploy-docs.yml
File metadata and controls
149 lines (124 loc) · 5.02 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
149
name: Deploy Documentation
on:
push:
branches: [main]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: pages
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: 10.17.1
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- name: Setup Pages
uses: actions/configure-pages@v5
- name: Install dependencies
run: pnpm install
- name: Build packages
run: pnpm -r run build
- name: Download UX Studio artifacts
run: |
curl -fsSL https://sfcc-uxstudio.s3.amazonaws.com/uxstudio-4.5.tar.gz -o /tmp/uxstudio-4.5.tar.gz
curl -fsSL https://sfcc-uxstudio.s3.amazonaws.com/uxstudio-4.6.tar.gz -o /tmp/uxstudio-4.6.tar.gz
mkdir -p docs/public/uxstudio
tar -xzf /tmp/uxstudio-4.5.tar.gz -C docs/public/uxstudio
tar -xzf /tmp/uxstudio-4.6.tar.gz -C docs/public/uxstudio
- name: Get latest release tag
id: release
run: |
# Find the highest-versioned package tag and docs tag (by semver, not
# creation date) so that maintenance patches on older minors never
# cause stable docs to regress to an older codebase.
pick_highest() {
node -e "
const lines = require('fs').readFileSync('/dev/stdin','utf8').trim().split('\n').filter(Boolean);
const parsed = lines.map(tag => {
const ver = tag.split('@').pop();
const [major, minor, patch] = ver.split('.').map(Number);
return { tag, major, minor, patch };
}).filter(t => !isNaN(t.major));
parsed.sort((a, b) => b.major - a.major || b.minor - a.minor || b.patch - a.patch);
if (parsed.length) console.log(parsed[0].tag);
"
}
PKG_TAG=$(git tag --list '@salesforce/*' | pick_highest)
DOCS_TAG=$(git tag --list 'docs@*' | pick_highest)
# Pick whichever tag has the higher semver version
LATEST_TAG=""
if [[ -n "$PKG_TAG" && -n "$DOCS_TAG" ]]; then
WINNER=$(node -e "
const a = '${PKG_TAG}'.split('@').pop().split('.').map(Number);
const b = '${DOCS_TAG}'.split('@').pop().split('.').map(Number);
const cmp = a[0]-b[0] || a[1]-b[1] || a[2]-b[2];
console.log(cmp >= 0 ? '${PKG_TAG}' : '${DOCS_TAG}');
")
LATEST_TAG="$WINNER"
elif [[ -n "$PKG_TAG" ]]; then
LATEST_TAG="$PKG_TAG"
elif [[ -n "$DOCS_TAG" ]]; then
LATEST_TAG="$DOCS_TAG"
fi
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
echo "exists=$([[ -n $LATEST_TAG ]] && echo true || echo false)" >> $GITHUB_OUTPUT
- name: Build dev documentation
run: |
IS_DEV_BUILD=true pnpm run docs:build
mv docs/.vitepress/dist docs/.vitepress/dist-dev
- name: Build stable documentation from release tag
if: steps.release.outputs.exists == 'true'
run: |
# Save config from main (has version dropdown and dynamic base path)
cp docs/.vitepress/config.mts /tmp/config.mts
# Remove S3-extracted uxstudio files before checkout to avoid conflicts
# (older tags still have these files tracked in git)
rm -rf docs/public/uxstudio
# Checkout release tag
git checkout ${{ steps.release.outputs.tag }}
# Ensure UX Studio artifacts are present (older tags have them in git,
# future tags won't — always extract from S3 to be safe)
rm -rf docs/public/uxstudio
mkdir -p docs/public/uxstudio
tar -xzf /tmp/uxstudio-4.5.tar.gz -C docs/public/uxstudio
tar -xzf /tmp/uxstudio-4.6.tar.gz -C docs/public/uxstudio
# Restore config from main (has version dropdown and dynamic base path)
cp /tmp/config.mts docs/.vitepress/config.mts
# Build at release tag with main's config (no IS_DEV_BUILD = stable at root)
pnpm install --frozen-lockfile
pnpm -r run build
pnpm run docs:build
# Combine: stable at root, dev in /dev/
mv docs/.vitepress/dist-dev docs/.vitepress/dist/dev
- name: Use dev as root when no release exists
if: steps.release.outputs.exists != 'true'
run: mv docs/.vitepress/dist-dev docs/.vitepress/dist
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vitepress/dist
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
needs: build
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4