Skip to content

Commit 531998d

Browse files
authored
Merge pull request #260 from circleci/fix-docs-deploy-prefix
Fix docs deploy prefix
2 parents 472cdc3 + 35cfd21 commit 531998d

File tree

2 files changed

+13
-158
lines changed

2 files changed

+13
-158
lines changed

.circleci/config.yml

Lines changed: 4 additions & 156 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:
@@ -94,20 +70,12 @@ jobs:
9470
echo "[INFO] Starting Antora build..."
9571
npm run build:docs
9672
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/
10373
- store_artifacts:
104-
path: build.zip
105-
destination: preview-site.zip
74+
path: build
10675
- persist_to_workspace:
10776
root: .
10877
paths:
10978
- build
110-
- build.zip
11179
- notify_error:
11280
message: "Build job failed for branch ${CIRCLE_BRANCH}"
11381

@@ -131,70 +99,12 @@ jobs:
13199
- notify_error:
132100
message: "Validation job failed for branch ${CIRCLE_BRANCH}"
133101

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-
188102
deploy-production:
189103
executor: go_executor
190104
parameters:
191105
bucket_name:
192106
description: The name of the s3 bucket where static assets are stored.
193107
type: string
194-
build_dir:
195-
default: "build"
196-
description: The path to the docs build directory
197-
type: string
198108
steps:
199109
- checkout
200110
- attach_workspace:
@@ -206,11 +116,10 @@ jobs:
206116
- run:
207117
name: Deploy Production Site to S3
208118
command: |
209-
AWS_S3_BUCKET=<< parameters.bucket_name >>
210-
BUILD_DIRECTORY=<< parameters.build_dir >>
211-
212119
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 >>/" \
214123
--delete
215124
- run:
216125
name: Deploy Redirects to S3
@@ -221,47 +130,6 @@ jobs:
221130
- notify_error:
222131
message: "Production deployment job failed for branch ${CIRCLE_BRANCH}"
223132

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-
265133
workflows:
266134
lint:
267135
unless:
@@ -271,25 +139,11 @@ workflows:
271139
reference_branch: main
272140
base_dir: docs
273141
build_validate_and_deploy:
274-
when:
275-
equal: ["", << pipeline.parameters.cleanup_preview_branch >>]
276142
jobs:
277143
- build:
278144
context: circleci-docs-static
279145
- validate:
280146
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-
]
293147
- deploy-production:
294148
requires: [validate]
295149
filters:
@@ -303,9 +157,3 @@ workflows:
303157
web-ui-datadog,
304158
]
305159
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

cmd/validate-redirects/main.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"flag"
67
"fmt"
78
"io"
@@ -33,6 +34,8 @@ type options struct {
3334
BaseURL string
3435
}
3536

37+
var errFailures = errors.New("failed validation")
38+
3639
func main() {
3740
ctx := context.Background()
3841

@@ -54,9 +57,13 @@ func main() {
5457
}
5558

5659
err := run(ctx, opts)
57-
if err != nil {
60+
switch {
61+
case errors.Is(err, errFailures):
62+
os.Exit(1)
63+
case err != nil:
5864
slog.Error("Unexpected error", "error", err)
5965
os.Exit(1)
66+
default:
6067
}
6168
}
6269

@@ -98,7 +105,7 @@ func run(ctx context.Context, opts options) error {
98105
for _, fail := range failures {
99106
slog.Warn(" " + fail)
100107
}
101-
return nil
108+
return errFailures
102109
}
103110

104111
slog.Info("Success")

0 commit comments

Comments
 (0)