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