Skip to content

Commit 35cfd21

Browse files
committed
Deploy docs under /docs prefix in the S3 bucket
- Rename `build` dir to `docs` in the job. - Delete the preview job - instead we can just upload the build dir to CircleCI, where it can easily be browsed (rather than having to download and extract zip file)
1 parent 1d3bbc2 commit 35cfd21

File tree

1 file changed

+3
-154
lines changed

1 file changed

+3
-154
lines changed

.circleci/config.yml

Lines changed: 3 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
version: 2.1
22

3-
parameters:
4-
cleanup_preview_branch:
5-
type: string
6-
default: ""
7-
83
orbs:
94
aws-cli: circleci/[email protected]
105
vale: circleci/[email protected]
@@ -34,25 +29,6 @@ commands:
3429
aws_secret_access_key: ${AWS_SECRET_ACCESS_KEY}
3530
region: ${AWS_REGION}
3631

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-
5632
notify_error:
5733
parameters:
5834
message:
@@ -96,17 +72,10 @@ jobs:
9672
echo "[INFO] Antora build completed."
9773
- store_artifacts:
9874
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/
10575
- persist_to_workspace:
10676
root: .
10777
paths:
10878
- build
109-
- build.zip
11079
- notify_error:
11180
message: "Build job failed for branch ${CIRCLE_BRANCH}"
11281

@@ -130,70 +99,12 @@ jobs:
13099
- notify_error:
131100
message: "Validation job failed for branch ${CIRCLE_BRANCH}"
132101

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-
187102
deploy-production:
188103
executor: go_executor
189104
parameters:
190105
bucket_name:
191106
description: The name of the s3 bucket where static assets are stored.
192107
type: string
193-
build_dir:
194-
default: "build"
195-
description: The path to the docs build directory
196-
type: string
197108
steps:
198109
- checkout
199110
- attach_workspace:
@@ -205,11 +116,10 @@ jobs:
205116
- run:
206117
name: Deploy Production Site to S3
207118
command: |
208-
AWS_S3_BUCKET=<< parameters.bucket_name >>
209-
BUILD_DIRECTORY=<< parameters.build_dir >>
210-
211119
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 >>/" \
213123
--delete
214124
- run:
215125
name: Deploy Redirects to S3
@@ -220,47 +130,6 @@ jobs:
220130
- notify_error:
221131
message: "Production deployment job failed for branch ${CIRCLE_BRANCH}"
222132

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-
264133
workflows:
265134
lint:
266135
unless:
@@ -270,25 +139,11 @@ workflows:
270139
reference_branch: main
271140
base_dir: docs
272141
build_validate_and_deploy:
273-
when:
274-
equal: ["", << pipeline.parameters.cleanup_preview_branch >>]
275142
jobs:
276143
- build:
277144
context: circleci-docs-static
278145
- validate:
279146
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-
]
292147
- deploy-production:
293148
requires: [validate]
294149
filters:
@@ -302,9 +157,3 @@ workflows:
302157
web-ui-datadog,
303158
]
304159
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

Comments
 (0)