Skip to content

Commit 6124ade

Browse files
committed
Preview: support preview/{branch}.yml
as alternative to adding the config to antora.yml. This my mitigate the issue of crufty branch config accumulating in the antora.yml over time.
1 parent 3e6ca08 commit 6124ade

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

lib/preview.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,20 @@ module.exports.register = function () {
6767
.find(fs.existsSync)
6868
|| url)
6969

70-
const antoraYmlPath = path.resolve(
70+
const basePath = path.resolve(
7171
mapLocalUrl(args.repo, 'UNEXPECTED'),
72-
args.startPath || source.start_path || '',
73-
'antora.yml')
72+
args.startPath || source.start_path || '')
73+
const antoraYmlPath = `${basePath}/antora.yml`
7474
console.log(antoraYmlPath)
7575

76-
const antoraYml = yaml.parse(
77-
fs.readFileSync(antoraYmlPath).toString())
76+
const readYaml = (path) =>
77+
fs.existsSync(path) && yaml.parse(fs.readFileSync(path).toString())
78+
79+
const antoraYml = readYaml(antoraYmlPath)
7880

7981
const previewConfig =
82+
readYaml(`${basePath}/preview/${args.branch}.yml`) ||
83+
readYaml(`${basePath}/preview/HEAD.yml`) ||
8084
antoraYml.ext?.preview?.[args.branch] ||
8185
antoraYml.ext?.preview?.HEAD || {}
8286

scripts/preview

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -159,45 +159,44 @@ if [ -n "$REMOTE" ]; then
159159
assert "$(git status -s -uno)" '' 'You have uncommitted changes.'
160160
assert "$(git push --dry-run 2>&1)" 'Everything up-to-date' 'You have unpushed changes.'
161161

162-
gh workflow run --repo couchbase/docs-infra preview-deploy.yml \
162+
WORKFLOW=preview-deploy.yml
163+
UUID=$(uuidgen)
164+
165+
gh workflow run --repo couchbase/docs-infra $WORKFLOW \
163166
--field preview_repo=${PREVIEW_REPO} \
164167
--field preview_branch=${PREVIEW_BRANCH} \
165168
--field preview_start_path=${PREVIEW_START_PATH} \
166169
--field preview_override=${PREVIEW_OVERRIDE} \
170+
--field uuid=${UUID} \
167171
> /dev/null
168172

169-
echo Requested the build at Github
173+
echo Requested the build at Github with UUID $UUID
170174
echo see https://github.com/couchbase/docs-infra/actions/workflows/preview-deploy.yml
171175
echo
172176
echo Visit 'https://preview.docs-test.couchbase.com/builds.html' to see all completed builds
173177
echo
174178

175-
for i in {1..10}
176-
do
177-
echo "Polling github..."
178-
sleep 7 # try to avoid showing an earlier run
179-
if RUN=$(
180-
gh run list --repo=couchbase/docs-infra \
181-
--workflow=preview-deploy.yml \
182-
--created $(date '+%Y-%m-%d') \
183-
--limit 3 \
184-
--json url,displayTitle,createdAt \
185-
--template $TEMPLATE \
186-
'read -r -d '' TEMPLATE <<EOT
187-
{{range .}}
188-
{{.url}}
189-
{{ .displayTitle}}
190-
{{ (timeago .createdAt)}}
191-
{{end}}' \
192-
| grep --context=1 "/${PREVIEW_REPO}-${PREVIEW_BRANCH}/" \
193-
| head -n 1 ); then
194-
# https://github.com/couchbase/docs-infra/actions/runs/14029636191
195-
echo "Opening $RUN in browser"
196-
open $RUN
179+
180+
for i in {1..10}; do
181+
echo Polling github...
182+
URL=$(gh run list \
183+
--repo couchbase/docs-infra \
184+
-w $WORKFLOW \
185+
--json displayTitle,url,databaseId \
186+
| jq -r \
187+
--arg UUID $UUID \
188+
'.[] | select(.displayTitle | test($UUID))| .url' )
189+
if [ -n "$URL" ]; then
190+
echo Opening $URL in your web browser
191+
# or could `gh run watch $databaseId`
192+
open $URL
197193
exit 0
198194
fi
199-
done
200195

196+
sleep 3
197+
done
198+
echo Timed out. Check Github actions
199+
exit 1
201200

202201
else
203202
export PREVIEW_GITHUB_REMOTE=$(git remote get-url origin 2>/dev/null)

0 commit comments

Comments
 (0)