1
1
version : 2.1
2
2
3
- parameters :
4
- cleanup_preview_branch :
5
- type : string
6
- default : " "
7
-
8
3
orbs :
9
4
aws-cli :
circleci/[email protected]
10
5
@@ -34,25 +29,6 @@ commands:
34
29
aws_secret_access_key : ${AWS_SECRET_ACCESS_KEY}
35
30
region : ${AWS_REGION}
36
31
37
- sanitize-branch :
38
- steps :
39
- - run :
40
- name : Sanitize Branch Name
41
- command : |
42
- if [ -n "<< pipeline.parameters.cleanup_preview_branch >>" ]; then
43
- BRANCH_TO_USE="<< pipeline.parameters.cleanup_preview_branch >>"
44
- echo "[INFO] Using provided branch param: ${BRANCH_TO_USE}"
45
- else
46
- BRANCH_TO_USE="${CIRCLE_BRANCH}"
47
- echo "[INFO] Using current branch: ${BRANCH_TO_USE}"
48
- fi
49
-
50
- # Replace forward-slashes and spaces with double underscore
51
- SANITIZED_BRANCH=$(echo "${BRANCH_TO_USE}" | tr '/ ' '__')
52
- echo "[INFO] Sanitized branch: ${SANITIZED_BRANCH}"
53
- echo "export SANITIZED_BRANCH=${SANITIZED_BRANCH}" >> $BASH_ENV
54
- source $BASH_ENV
55
-
56
32
notify_error :
57
33
parameters :
58
34
message :
@@ -94,20 +70,12 @@ jobs:
94
70
echo "[INFO] Starting Antora build..."
95
71
npm run build:docs
96
72
echo "[INFO] Antora build completed."
97
- - run :
98
- name : Create ZIP Archive of Build
99
- command : |
100
- set -e
101
- echo "[INFO] Creating zip archive of build directory..."
102
- zip -r build.zip build/
103
73
- store_artifacts :
104
- path : build.zip
105
- destination : preview-site.zip
74
+ path : build
106
75
- persist_to_workspace :
107
76
root : .
108
77
paths :
109
78
- build
110
- - build.zip
111
79
- notify_error :
112
80
message : " Build job failed for branch ${CIRCLE_BRANCH}"
113
81
@@ -131,70 +99,12 @@ jobs:
131
99
- notify_error :
132
100
message : " Validation job failed for branch ${CIRCLE_BRANCH}"
133
101
134
- deploy-preview :
135
- executor : node_executor
136
- steps :
137
- - attach_workspace :
138
- at : .
139
- - sanitize-branch
140
- - run :
141
- name : Install GitHub CLI
142
- command : |
143
- set -e
144
- echo "[INFO] Installing GitHub CLI..."
145
- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
146
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
147
- sudo apt update
148
- sudo apt install gh
149
- - run :
150
- name : Upload Preview ZIP to GitHub Release and Comment
151
- command : |
152
- set -e
153
-
154
- if [[ -n "${CIRCLE_PULL_REQUEST}" ]]; then
155
- PR_NUMBER=$(echo "$CIRCLE_PULL_REQUEST" | sed 's|.*/pull/||')
156
- REPO_PATH="circleci/circleci-docs-static"
157
- TAG="pr-${SANITIZED_BRANCH}"
158
-
159
- echo "[INFO] Creating release for PR #${PR_NUMBER} - branch ${SANITIZED_BRANCH} in ${REPO_PATH}"
160
-
161
- # Check if release already exists (if re-run)
162
- if gh release view "${TAG}" -R "${REPO_PATH}" > /dev/null 2>&1; then
163
- echo "[INFO] Release already exists. Replacing..."
164
- gh release delete "${TAG}" -R "${REPO_PATH}" --yes
165
- fi
166
-
167
- # Create new release and upload ZIP
168
- gh release create "${TAG}" build.zip \
169
- --repo "${REPO_PATH}" \
170
- --title "Preview for PR #${PR_NUMBER}" \
171
- --notes "ZIP artifact for documentation preview." \
172
- --prerelease
173
-
174
- DOWNLOAD_URL="https://github.com/${REPO_PATH}/releases/tag/${TAG}/build.zip"
175
-
176
- # Comment on the PR with release link
177
- gh pr comment "${PR_NUMBER}" -R "${REPO_PATH}" -b "## Preview Documentation
178
-
179
- 📦 ZIP preview available here: [Preview Build Assets](${DOWNLOAD_URL})
180
-
181
- Build: ${CIRCLE_BUILD_NUM} | Commit: ${CIRCLE_SHA1}"
182
- else
183
- echo "[INFO] Not a PR build, skipping preview release."
184
- fi
185
- - notify_error :
186
- message : " Deploy preview job failed for branch ${CIRCLE_BRANCH}"
187
-
188
102
deploy-production :
189
103
executor : go_executor
190
104
parameters :
191
105
bucket_name :
192
106
description : The name of the s3 bucket where static assets are stored.
193
107
type : string
194
- build_dir :
195
- default : " build"
196
- description : The path to the docs build directory
197
- type : string
198
108
steps :
199
109
- checkout
200
110
- attach_workspace :
@@ -206,11 +116,10 @@ jobs:
206
116
- run :
207
117
name : Deploy Production Site to S3
208
118
command : |
209
- AWS_S3_BUCKET=<< parameters.bucket_name >>
210
- BUILD_DIRECTORY=<< parameters.build_dir >>
211
-
212
119
echo "[INFO] Deploying production site..."
213
- aws s3 sync "$BUILD_DIRECTORY" "s3://$AWS_S3_BUCKET/" \
120
+ dir=$(mktemp -d)
121
+ mv build "${dir}/docs"
122
+ aws s3 sync "${dir}" "s3://<< parameters.bucket_name >>/" \
214
123
--delete
215
124
- run :
216
125
name : Deploy Redirects to S3
@@ -221,47 +130,6 @@ jobs:
221
130
- notify_error :
222
131
message : " Production deployment job failed for branch ${CIRCLE_BRANCH}"
223
132
224
- cleanup-preview :
225
- executor : node_executor
226
- steps :
227
- - sanitize-branch
228
- - run :
229
- name : Install GitHub CLI
230
- command : |
231
- set -e
232
- echo "[INFO] Installing GitHub CLI..."
233
- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
234
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
235
- sudo apt update
236
- sudo apt install gh
237
- - run :
238
- name : Delete GitHub Release and Tag
239
- command : |
240
- set -e
241
- BRANCH="<< pipeline.parameters.cleanup_preview_branch >>"
242
- REPO_PATH="circleci/circleci-docs-static"
243
-
244
- # Extract TAG
245
- TAG="pr-${SANITIZED_BRANCH}"
246
-
247
- echo "[INFO] Cleaning up GitHub Release for ${TAG} in ${REPO_PATH}"
248
-
249
- # Delete the release if it exists
250
- if gh release view "${TAG}" -R "${REPO_PATH}" > /dev/null 2>&1; then
251
- gh release delete "${TAG}" -R "${REPO_PATH}" --yes
252
- echo "[INFO] Release '${TAG}' deleted."
253
- else
254
- echo "[WARN] Release '${TAG}' not found."
255
- fi
256
-
257
- # Delete the tag if it exists
258
- if gh api -X GET "repos/${REPO_PATH}/git/refs/tags/${TAG}" > /dev/null 2>&1; then
259
- gh tag delete "${TAG}" -R "${REPO_PATH}" --yes
260
- echo "[INFO] Tag '${TAG}' deleted."
261
- else
262
- echo "[WARN] Tag '${TAG}' not found."
263
- fi
264
-
265
133
workflows :
266
134
lint :
267
135
unless :
@@ -271,25 +139,11 @@ workflows:
271
139
reference_branch : main
272
140
base_dir : docs
273
141
build_validate_and_deploy :
274
- when :
275
- equal : ["", << pipeline.parameters.cleanup_preview_branch >>]
276
142
jobs :
277
143
- build :
278
144
context : circleci-docs-static
279
145
- validate :
280
146
requires : [build]
281
- - deploy-preview :
282
- requires : [validate]
283
- filters :
284
- branches :
285
- ignore : main
286
- context :
287
- [
288
- circleci-docs-static,
289
- docs-platform-assets,
290
- web-ui-npm,
291
- web-ui-datadog,
292
- ]
293
147
- deploy-production :
294
148
requires : [validate]
295
149
filters :
@@ -303,9 +157,3 @@ workflows:
303
157
web-ui-datadog,
304
158
]
305
159
bucket_name : " circleci-docs-platform-assets"
306
- build_dir : " build"
307
- cleanup_preview :
308
- when : pipeline.parameters.cleanup_preview_branch != ""
309
- jobs :
310
- - cleanup-preview :
311
- context : circleci-docs-static
0 commit comments