Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 88 additions & 25 deletions .github/workflows/update-docs-base-bun.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ run-name: >-
|| format('Manual docs build - v{0}', inputs.major_versions) }}

on:
pull_request: # FIXME: just for testing, remove before merge
paths:
- .github/workflows/update-docs-base-bun.yml
# This triggers the auto docs build every night and uses the hard-coded DOC_VERSIONS
schedule:
- cron: "0 2 * * *"
Expand All @@ -21,6 +24,10 @@ env:
# Every version listed here is pulled in and published by a single nightly build.
DOC_VERSIONS: "63,62"

concurrency:
group: update-docs
cancel-in-progress: true

jobs:
params:
name: Prep params
Expand Down Expand Up @@ -51,14 +58,18 @@ jobs:
needs: params
name: Build docs v${{ needs.params.outputs.versions }}
runs-on: ubuntu-latest
# The docs pull step can retry up to 3x30 minutes on its own, so leave room for
# that plus the astro build and htmlproofer.
# The docs pull step retries and is capped at 90 minutes, so leave room for that
# plus the astro build and htmlproofer.
timeout-minutes: 150
env:
GH_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
DOC_VERSIONS: ${{ needs.params.outputs.versions }}
# Every run gets its own branch, so nothing has to be merged by hand.
BRANCH_NAME: docs-update-${{ github.run_id }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
with:
ref: master

- name: Prepare java
uses: actions/setup-java@v4
Expand Down Expand Up @@ -93,27 +104,31 @@ jobs:
- name: Install js dependencies
run: bun install --frozen-lockfile

- name: Setup Git Authentication
run: |
git config --global user.name "Metabase Docs bot"
git config --global user.email "metabase-bot@metabase.com"
git remote set-url origin "https://x-access-token:${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}@github.com/metabase/docs.metabase.github.io.git"

# observed this failing during sdk docs generation deps downloads, so adding retry logic
# note: a retry re-pulls every version, since the whole loop is the retried unit
- name: Update docs for branchname
uses: nick-fields/retry@v3
with:
timeout_minutes: 30
max_attempts: 3
retry_on: error
shell: bash
command: |
timeout-minutes: 90
run: |
pull_docs() {
for v in ${DOC_VERSIONS//,/ }; do
echo "::group::Pulling docs from release-x.$v.x"
bb script/update_docs_for_branchname.clj --source-branch "release-x.$v.x" --target-branch "release-x.$v.x"
echo "::endgroup::"
done
}
export -f pull_docs

for attempt in 1 2 3; do
echo "Pulling docs (attempt $attempt of 3)"
status=0
# the subshell restores `set -e`, so a failed version aborts the attempt
bash -euo pipefail -c pull_docs || status=$?
if (( status == 0 )); then exit 0; fi
echo "::warning::Attempt $attempt failed (exit $status)"
sleep 10
done
echo "::error::Docs pull failed after 3 attempts"
exit 1

- name: Cleanup cloud docs (move them to latest, remove from all other versions)
run: |
Expand Down Expand Up @@ -164,13 +179,61 @@ jobs:
echo "htmlproofer spit out a report of length: $(wc -l < htmlproofer.out)"
bb script/analyze_links.clj --htmlproofer-output htmlproofer.out --limit 1

- name: Update or Create the Pull Request
run: |
bb script/update_or_create_pr.clj \
--versions "$DOC_VERSIONS" \
--pr-number "$PR_NUMBER" \
--update-dirs "$UPDATE_DIRS"
- name: Push the updated docs
id: diff
run: | # sh
git config --global user.name "Metabase Automation User"
git config --global user.email "metabase-bot@metabase.com"
# The current docs version is also published to _docs/latest
latest="$(sed -n 's/^docs_version: v0\.\([0-9]*\).*/\1/p' _config.yml)"
for v in ${DOC_VERSIONS//,/ }; do
git add "_docs/v0.$v" || echo "::warning::nothing to stage for _docs/v0.$v"
if [[ "$v" == "$latest" ]]; then
git add _docs/latest
fi
done

- name: Merge Updated Docs
run: |
bb script/merge.clj --versions "$DOC_VERSIONS"
if git diff --cached --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "No docs changes to commit."
exit 0
fi

echo "changed=true" >> "$GITHUB_OUTPUT"
git --no-pager diff --cached --stat

git checkout -B "$BRANCH_NAME"
git commit -m "Update docs for v$DOC_VERSIONS"
git push --force origin "$BRANCH_NAME"

- name: Open PR
id: create_pr
if: steps.diff.outputs.changed == 'true'
run: | # sh
{
echo "Automated docs update, pulled from:"
for v in ${DOC_VERSIONS//,/ }; do
echo "- \`release-x.$v.x\`"
done
} > "$RUNNER_TEMP/pr-body.md"

URL=$(gh pr create \
--base master \
--head "$BRANCH_NAME" \
--title "Update docs: v0.${DOC_VERSIONS//,/, v0.}" \
--body-file "$RUNNER_TEMP/pr-body.md")

echo "pr_number=${URL##*/}" >> "$GITHUB_OUTPUT"

- name: Auto approve PR
if: steps.diff.outputs.changed == 'true'
uses: juliangruber/approve-pull-request-action@68fcc9a5a73b5641cadf757cf99d73720dcb05d0 # v2.1.0
with:
github-token: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
number: ${{ steps.create_pr.outputs.pr_number }}

- name: Enable Pull Request Automerge
if: steps.diff.outputs.changed == 'true'
run: gh pr merge --squash --auto "$PR_NUMBER"
env:
PR_NUMBER: ${{ steps.create_pr.outputs.pr_number }}
29 changes: 0 additions & 29 deletions script/_test/all.clj
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,6 @@
(is (integer? docs-version)
(str "Expected config version to be an integer, got: " docs-version))))

(deftest parse-versions-test
(is (= [63 62] (u/parse-versions "63,62")))
(is (= [63 62] (u/parse-versions " 62 , 63 "))
"whitespace is trimmed and versions are sorted newest first")
(is (= [63] (u/parse-versions "63,63")) "duplicates collapse")
(is (= [63] (u/parse-versions "63")))
(is (= [63] (u/parse-versions 63)) "babashka.cli may hand us a number for a single version")
(doseq [bad ["" "," "63,x" "v63" "63,-1" "63,0"]]
(is (thrown? clojure.lang.ExceptionInfo (u/parse-versions bad))
(str "Expected " (pr-str bad) " to be rejected"))))

(deftest versions->head-ref-name-test
(is (= "docs-update-v63-v62" (u/versions->head-ref-name [63 62])))
(is (= "docs-update-v63-v62" (u/versions->head-ref-name [62 63]))
"the branch name depends on the set of versions, not the order they were listed in"))

(deftest versions->artifacts-test
(let [current (u/config-docs-version)
previous (dec current)
artifacts (u/versions->artifacts [current previous])]
(is (= (count artifacts) (count (distinct artifacts)))
(str "Expected no duplicate paths, got: " (pr-str artifacts)))
(is (some #{"_docs/latest"} artifacts)
"the current version also publishes to _docs/latest")
(is (some #{(str "_docs/v0." current)} artifacts))
(is (some #{(str "_docs/v0." previous)} artifacts))
(is (not (some #{"_docs/master"} artifacts))
"master docs are never published")))

(deftest categorize-branchname-test
(doseq [branchname branches
:let [[category release-num] (u/categorize-branchname branchname)]]
Expand Down
183 changes: 0 additions & 183 deletions script/merge.clj

This file was deleted.

Loading
Loading