Skip to content

Commit 1e37aad

Browse files
authored
Merge pull request #16 from metabase/branchname-aware-docs-building
2 parents c323603 + 4fe4e65 commit 1e37aad

File tree

6 files changed

+100
-34
lines changed

6 files changed

+100
-34
lines changed

.github/workflows/process_docs_changes.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- uses: actions/checkout@v4
1919

2020
- name: Set current branch name
21-
run: echo "LOCAL_REPO_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_ENV
21+
run: echo "LOCAL_REPO_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> "$GITHUB_ENV"
2222

2323
- name: echo branch name
2424
run: |
@@ -35,7 +35,7 @@ jobs:
3535

3636
- name: Filter non-documented branches
3737
run: |
38-
bb script/check_incoming_branchname.clj $MAIN_REPO_BRANCH
38+
bb script/check_incoming_branchname.clj "$MAIN_REPO_BRANCH"
3939
4040
- name: Install js dependencies
4141
run: yarn install --frozen-lockfile --prefer-offline
@@ -49,10 +49,12 @@ jobs:
4949
run: |
5050
bundle install
5151
52+
- name: Update docs for branchname
53+
run: |
54+
bb script/update_docs_for_branchname.clj "$MAIN_REPO_BRANCH"
55+
5256
- name: Update docs
5357
run: |
54-
# ./script/docs-update
55-
# ./script/docs master --set-version master
5658
./script/docs "$MAIN_REPO_BRANCH" --set-version "$MAIN_REPO_BRANCH"
5759
5860
- name: "Lint the markdown"
@@ -81,21 +83,21 @@ jobs:
8183
# Build the jekyll site:
8284
JEKYLL_ENV=development bundle exec jekyll build --baseurl '' --config _config.docs.yml --trace
8385
84-
- name: "Check all of the links"
86+
- name: Run metabase.com-aware link checks
8587
run: |
8688
script/links || true
8789
echo 'checking reported links...'
88-
echo "htmlproofer spit out a report of length: $(cat htmlproofer.out | wc -l)"
90+
echo "htmlproofer spit out a report of length: $(wc -l < htmlproofer.out)"
8991
bb script/analyze_links.clj --htmlproofer-output htmlproofer.out
9092
91-
- name: Authenticate Git with GITHUB_TOKEN
93+
- name: Setup Git Authenticatation
9294
run: |
9395
git config --global user.name "Metabase Docs bot"
9496
git config --global user.email "metabase-bot@metabase.com"
9597
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/metabase/docs.metabase.github.io.git"
9698
97-
- name: Create the pull request
99+
- name: Update or Create the Pull Request
98100
env:
99101
GH_TOKEN: ${{ secrets.METABASE_AUTOMATION_USER_TOKEN }}
100102
run: |
101-
bb script/update_or_create_pr.clj $MAIN_REPO_BRANCH
103+
bb script/update_or_create_pr.clj "$MAIN_REPO_BRANCH"

_config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ default_social_image: /images/twitter/default.png
1111
redcarpet:
1212
extensions: [no_intra_emphasis, fenced_code_blocks, autolink, tables, with_toc_data]
1313
plugins:
14-
- jekyll-redirect-from
14+
- jekyll-redirect-from
1515
whitelist:
16-
- jekyll-redirect-from
17-
- jekyll_include_plugin
18-
- jekyll_dirname_payload_plugin
16+
- jekyll-redirect-from
17+
- jekyll_include_plugin
18+
- jekyll_dirname_payload_plugin
1919
jekyll_include_plugin:
20-
snippet_prefix: ''
20+
snippet_prefix: ""
2121
sass:
22-
sass_dir: _sass
23-
style: compressed
22+
sass_dir: _sass
23+
style: compressed
2424
permalink: '/blog/:title'
2525
webrick:
26-
headers: {X-Frame-Options: deny, Content-Security-Policy: 'frame-ancestors ''none'''}
26+
headers: {X-Frame-Options: deny, Content-Security-Policy: 'frame-ancestors ''none'''}
2727
java-minimum-version: 21
2828
latest_version: v0.53.8
2929
latest_enterprise: v1.53.8

bb.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{}
1+
{:paths ["script"]
2+
:deps {org.babashka/cli {:mvn/version "0.8.65"}
3+
io.github.paintparty/bling {:mvn/version "0.5.0"}}}

script/check_incoming_branchname.clj

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,12 @@
11
(ns check-incoming-branchname
2-
(:require [clojure.string :as str]))
2+
(:require
3+
[util :as u]
4+
[clojure.string :as str]))
35

46
(defn usage []
57
(println "Usage: script/check_incoming_branchname.clj branchname")
68
(System/exit 1))
79

8-
(def release-regex #"release-x\.(\d+)\.x")
9-
10-
(defn extract-release-num [release-branchname]
11-
(let [[_ num] (re-matches release-regex release-branchname)]
12-
num))
13-
14-
(defn categorize-branchname [branchname]
15-
(cond
16-
(= branchname "master") [:master]
17-
(re-matches release-regex branchname) [:release (extract-release-num branchname)]
18-
(or
19-
(= branchname "doc-update-detection")
20-
(str/starts-with? branchname "docs-workflow-test-")) [:test branchname]))
21-
2210
(defn -main
2311
"This is called from the `process_docs_changes.yml` workflow. It checks that
2412
the branchname is either `master` or a release branch. If not, it exits with
@@ -27,7 +15,7 @@
2715
[& args]
2816
(let [branchname (or (first args) (usage))
2917
_ (println "Checking branchname:" branchname)
30-
[category release-num] (categorize-branchname branchname)]
18+
[category release-num] (u/categorize-branchname branchname)]
3119
(case category
3220
:master (println "Master branch detected.")
3321
:release (println "Release branch detected. Release number: " release-num)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
(ns update-docs-for-branchname
2+
(:require
3+
[babashka.process :as p]
4+
[bling.core :refer [bling callout]]
5+
[clj-yaml.core :as yaml]
6+
[util :as u]))
7+
8+
;; TODO: add test that docs_version is always parsable
9+
10+
(defn config-docs-version
11+
"Get the latest docs version number from the _config.yml file."
12+
[]
13+
(let [[_ version-num] (re-matches #"v0.(\d+)" (:docs_version (yaml/parse-string (slurp "_config.yml"))))]
14+
(Integer/parseInt version-num)))
15+
16+
(defn update? [config-docs-version release-num]
17+
(cond
18+
(> release-num config-docs-version)
19+
(do
20+
(callout {:type :warning
21+
:label "Newer version detected"}
22+
(format "Release number from branch (%s) is newer than docs_version from config.yml (%s).\nContinuing build."
23+
release-num
24+
config-docs-version))
25+
false)
26+
27+
(= release-num config-docs-version)
28+
true
29+
30+
:else false))
31+
32+
(defn usage []
33+
(println "Usage: script/update_docs_for_branchname.clj branchname")
34+
(System/exit 1))
35+
36+
(defn -main [& args]
37+
(let [branchname (first args)
38+
dry-run? (contains? (set args) "--dry-run")
39+
_ (when (nil? branchname)
40+
(println (callout {:type :error} (bling [:red "No branchname provided."])))
41+
(usage))
42+
[category release-num] (u/categorize-branchname branchname)
43+
command (case category
44+
:master "./script/docs master --set-version master"
45+
:release (format "./script/docs release-x.%s.x --set-version v0.%s %s"
46+
release-num
47+
release-num
48+
(if (update? (config-docs-version) release-num)
49+
"--update"
50+
""))
51+
:test (format "./script/docs %s --set-version %s" branchname branchname)
52+
(do (println "Unpublishable branchname: " branchname)
53+
(System/exit 1)))]
54+
(callout {:type :info :label "Command To Run"} (bling [:green command]))
55+
(when-not dry-run? (p/shell command))))
56+
57+
(when (= *file* (System/getProperty "babashka.file"))
58+
(apply -main *command-line-args*))

script/util.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(ns util
2+
(:require [clojure.string :as str]))
3+
4+
(def release-regex #"release-x\.(\d+)\.x")
5+
6+
(defn- extract-release-num [release-branchname]
7+
(let [[_ num] (re-matches release-regex release-branchname)]
8+
(Integer/parseInt num)))
9+
10+
(defn categorize-branchname [branchname]
11+
(cond
12+
(= branchname "master") [:master]
13+
(re-matches release-regex branchname) [:release (extract-release-num branchname)]
14+
(or
15+
(= branchname "doc-update-detection")
16+
(str/starts-with? branchname "docs-workflow-test-")) [:test branchname]))

0 commit comments

Comments
 (0)