Skip to content

Commit 0e2ad18

Browse files
authored
[CI] Update release process instructions, add build-ID helpers and more (#2351)
1 parent 53cfee7 commit 0e2ad18

File tree

9 files changed

+95
-41
lines changed

9 files changed

+95
-41
lines changed

.vscode/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"anchorize",
77
"Docsy",
88
"errorf",
9+
"htmltest",
910
"hugo",
1011
"isset",
1112
"nvmrc",
13+
"refcache",
1214
"relref",
1315
"scrollspy",
1416
"shortcode",

CONTRIBUTING.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,33 @@ repo.
5555
- `version` key in [docsy.dev/hugo.yaml]
5656
4. Run `npm run ci:prepare` to ensure that vendor assets and [go.mod]
5757
dependencies are up-to-date.
58-
5. **Submit a PR with your changes**, using a title like "Release v0.X.Y
58+
5. Run `npm test` to ensure that all checks pass and the build is successful.
59+
This command runs `npm run fix`. Note if there are any file changes, and if
60+
the version ID is still correct and has no build ID (which is usually added
61+
by `fix:version`).
62+
6. **Submit a PR with your changes**, using a title like "Release v0.X.Y
5963
preparation".
60-
6. **Test the PR** branch from selected sites, and push any required
64+
7. **Test the PR** branch from selected sites, and push any required
6165
adjustments.
6266
- If the test site uses Docsy as a Git submodule:
63-
```console
64-
$ cd themes/docs
65-
$ git fetch
66-
$ git switch -t repo/branch-name # e.g. chalin/chalin-im-0.9.1-2024-02-16
67+
```sh
68+
cd themes/docs
69+
git fetch
70+
git switch -t REPO/BRANCH-NAME # e.g. chalin/chalin-m25-0.13.0-dev-alpha
6771
```
68-
7. **Get PR approved and merged**.
69-
8. **Pull in `main`** to get the last PR.
70-
9. **Ensure** that you're:
72+
8. **Get PR approved and merged**.
73+
9. **Pull in `main`** to get the last PR.
74+
10. **Ensure** that you're:
7175
- On the default branch, `main`
7276
- At the commit that you want to tag as v0.X.Y
73-
10. **Create tags** for v0.X.Y:
77+
11. **Create tags** for v0.X.Y:
7478
7579
```sh
7680
REL=v0.X.Y
7781
git tag $REL
7882
```
7983
80-
11. **Push the new tags** to the main remote (`origin` or `upstream` depending
84+
12. **Push the new tags** to the main remote (`origin` or `upstream` depending
8185
on your setup) as well as any secondary remotes, if any:
8286
8387
```console
@@ -86,7 +90,7 @@ repo.
8690
* [new tag] v0.X.Y -> v0.X.Y
8791
```
8892
89-
12. **[Draft a new release][]** using GitHub web; fill in the fields as follows:
93+
13. **[Draft a new release][]** using GitHub web; fill in the fields as follows:
9094
- From the **release/tag dropdown**: Select the new release tag that you
9195
just pushed, v0.X.Y.
9296
- Set the **release title** to the release number (without the "v").
@@ -104,9 +108,9 @@ repo.
104108
105109
- Select **Create a discussion for this release**.
106110
107-
13. **Publish the release**: click _Publish release_.
108-
14. Test the release with a downstream project, such as [docsy-example].
109-
15. If you find issues, determine whether they need to be fixed immediately. If
111+
14. **Publish the release**: click _Publish release_.
112+
15. Test the release with a downstream project, such as [docsy-example].
113+
16. If you find issues, determine whether they need to be fixed immediately. If
110114
so, get fixes submitted, reviewed and approved. Then publish a dot release:
111115
go back to step 1.
112116
@@ -117,7 +121,7 @@ least one downstream project, then perform the following actions before any
117121
further changes are merged into the default branch:
118122
119123
1. Set `version` in [package.json] to the next planned (or the next dot) release
120-
with a dev suffix, such as `v0.X.Z-dev-unreleased`.
124+
with a dev suffix, such as `v0.X.Z-dev`.
121125
2. In the [CHANGELOG]:
122126
- **Create a new entry** for the next release by copying the ENTRY TEMPLATE
123127
at the end of the file.

docsy.dev/Makefile

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Set REFCACHE to another value to disable htmltest refcache-file manipulation
21
REFCACHE?=refcache
32
HTMLTEST_DIR=tmp
43
HTMLTEST?=htmltest # Specify as make arg if different
@@ -27,19 +26,12 @@ $(LINK_CACHE_FILE_DEST_DIR)/$(LINK_CACHE_FILE):
2726
echo '{}' > $(LINK_CACHE_FILE_DEST_DIR)/$(LINK_CACHE_FILE)
2827

2928
refcache-restore: $(LINK_CACHE_FILE_DEST_DIR)/$(LINK_CACHE_FILE) $(LINK_CACHE_FILE_SRC_DIR)
30-
ifeq (refcache, $(REFCACHE))
3129
cp $(LINK_CACHE_FILE_DEST_DIR)/$(LINK_CACHE_FILE) $(LINK_CACHE_FILE_SRC_DIR)/
32-
else
33-
@echo "SKIPPING refcache-restore"
34-
endif
3530

3631
refcache-save:
37-
ifeq (refcache, $(REFCACHE))
3832
cp $(LINK_CACHE_FILE_SRC_DIR)/$(LINK_CACHE_FILE) $(LINK_CACHE_FILE_DEST_DIR)/
33+
node scripts/unescape-refcache-json.mjs
3934
npx prettier --prose-wrap=always --write $(LINK_CACHE_FILE_DEST_DIR)/$(LINK_CACHE_FILE)
40-
else
41-
@echo "SKIPPING refcache-save"
42-
endif
4335

4436
check-links: $(GET_LINK_CHECKER_IF_NEEDED) \
4537
refcache-restore check-links-only refcache-save

docsy.dev/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"_commit:public": "HASH=$(git rev-parse --short main); cd public && git add -A && git commit -m \"Site at $HASH\"",
1111
"_hugo-dev": "npm run _hugo -- -e dev -DFE",
1212
"_hugo": "hugo --cleanDestinationDir --themesDir ../..",
13-
"_refcache:prune": "jq 'with_entries(select(.value.StatusCode < 400))' static/refcache.json > tmp/refcache.json && mv tmp/refcache.json static/refcache.json",
13+
"_refcache:prune-4xx": "jq 'with_entries(select(.value.StatusCode < 400))' static/refcache.json > tmp/refcache.json && mv tmp/refcache.json static/refcache.json",
1414
"_serve": "npm run _hugo-dev -- serve --minify --disableFastRender --renderToMemory",
1515
"build:preview": "cross-env npm run _hugo-dev -- --minify --baseURL \"${DEPLOY_PRIME_URL:-http://localhost}\"",
1616
"build:production": "npm run _hugo -- --minify",
@@ -20,7 +20,7 @@
2020
"check:links": "npm run _check:links",
2121
"clean": "rm -Rf public",
2222
"fix:format": "npm run _check:format -- --write",
23-
"fix": "npm run fix:format && npm run _refcache:prune",
23+
"fix": "npm run fix:format && npm run _refcache:prune-4xx",
2424
"make:public": "git init -b main public",
2525
"postbuild:preview": "npm run _check:links--warn",
2626
"postbuild:production": "npm run _check:links--warn",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env node
2+
3+
// Script to unescape refcache.json, which is necessary because of a bug in htmltest.
4+
// See https://github.com/wjdp/htmltest/issues/239
5+
6+
import { readFileSync, writeFileSync } from 'fs';
7+
8+
const refcacheFile = 'static/refcache.json';
9+
10+
console.log(
11+
`Unescaping ${refcacheFile}, which is necessary because of a bug in htmltest ...`,
12+
);
13+
14+
const data = JSON.parse(readFileSync(refcacheFile, 'utf8'));
15+
writeFileSync(refcacheFile, JSON.stringify(data, null, 2) + '\n');
16+
17+
console.log('Done.');

docsy.dev/static/refcache.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@
20752075
"StatusCode": 206,
20762076
"LastSeen": "2025-05-16T09:20:44.15864-04:00"
20772077
},
2078-
"https://prismjs.com/download.html#themes=prism\u0026languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml\u0026plugins=toolbar+copy-to-clipboard": {
2078+
"https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard": {
20792079
"StatusCode": 206,
20802080
"LastSeen": "2025-10-06T11:55:59.999Z"
20812081
},

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "docsy",
3-
"version": "0.12.1-dev-unreleased+20251017-1612Z",
4-
"version.next": "0.12.2-dev-unreleased",
3+
"version": "0.13.0-dev+38-g53cfee7",
4+
"version.next": "0.13.1-dev",
55
"repository": "github:google/docsy",
66
"homepage": "https://www.docsy.dev",
77
"license": "Apache-2.0",
@@ -18,22 +18,23 @@
1818
"_mkdir:hugo-mod": "node scripts/mkdirp-hugo-mod.js ..",
1919
"_prepare": "npm run _cp:bs-rfs && npm run _refresh-forward-sass-var && npm run _gen-chroma-styles && npm run get:hugo-modules",
2020
"_refresh-forward-sass-var": "bash -c scripts/refresh-sass-variables.pl",
21+
"_update:version-build-id": "node scripts/update-version-build-id.mjs",
2122
"cd:docsy.dev": "npm run _cd:docsy.dev -- npm run",
2223
"check:format": "npm list prettier && npm run _check:format || (echo '[help] Run: npm run fix:format'; exit 1)",
2324
"check": "npm run check:format",
2425
"ci:post": "npm run fix:format && npm run _diff:check",
2526
"ci:prepare": "npm run docsy.dev-install && npm run _prepare && npm run _diff:check",
2627
"docsy.dev-install": "npm run _cd:docsy.dev -- npm install",
2728
"fix:format": "npm run _check:format -- --write && npm run cd:docsy.dev fix:format",
28-
"fix": "npm run fix:format && npm run cd:docsy.dev fix",
29+
"fix:version": "npm run _update:version-build-id -- $(scripts/get-build-id.sh)",
30+
"fix": "npm run fix:format && npm run fix:version && npm run cd:docsy.dev fix",
2931
"get:hugo-modules": "node scripts/getHugoModules/index.mjs",
3032
"postinstall": "npm run _mkdir:hugo-mod",
3133
"test:all": "npm run ci:prepare && npm run check && npm run cd:docsy.dev test && npm run ci:post",
3234
"test:only": "npm run cd:docsy.dev test",
3335
"test": "echo 'RUNNING FIX AND TESTS...'; npm run fix && npm run test:only",
3436
"update:dep": "npm install --save-exact @fortawesome/fontawesome-free@latest bootstrap@latest",
35-
"update:packages": "npx npm-check-updates -x @fortawesome/fontawesome-free -u && npm run cd:docsy.dev update:packages",
36-
"update:version-build-id": "node scripts/update-version-build-id.js"
37+
"update:packages": "npx npm-check-updates -x @fortawesome/fontawesome-free -u && npm run cd:docsy.dev update:packages"
3738
},
3839
"dependencies": {
3940
"@fortawesome/fontawesome-free": "6.7.2",

scripts/get-build-id.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
#
3+
# Uses `git describe --tags main` to derive a build ID. This doesn't guarantee uniqueness,
4+
# but it's a good enough approximation for our purposes.
5+
#
6+
# Examples of the script output for a given git-describe output:
7+
# - v0.12.0-38-g53cfee7 -> 38-g53cfee7
8+
# - v0.12.0 -> '' (empty string when the current commit is exactly on a tag)
9+
10+
set -euo pipefail
11+
12+
# Get the git describe output from the main branch
13+
if ! git_describe=$(git describe --tags main 2>/dev/null); then
14+
echo "Error running git describe: command failed" >&2
15+
exit 1
16+
fi
17+
18+
# Extract the suffix after the tag (everything after the last version prefix)
19+
# Format: v0.12.0-38-g53cfee7
20+
if [[ $git_describe =~ ^v?[0-9.]+-(.+)$ ]]; then
21+
echo "${BASH_REMATCH[1]}"
22+
else
23+
# No suffix (exactly on a tag), return empty string
24+
echo ""
25+
fi
26+

scripts/update-version-build-id.js renamed to scripts/update-version-build-id.mjs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
/**
44
* Updates the version in package.json by adding a build ID.
5-
* Usage: node scripts/update-version-build-id.js [build-id]
65
*
7-
* If no build-id is provided, uses current UTC timestamp in YYYYMMDD-HHmmZ format.
6+
* Usage: node scripts/update-version-build-id.mjs [build-id]
7+
*
8+
* - If no build-id is provided: uses current UTC timestamp in YYYYMMDD-HHmmZ format
9+
* - If empty string "" is provided: removes the build ID (sets version to base version only)
10+
* - If a build-id is provided: uses that build ID
811
*/
912

10-
const fs = require('fs');
11-
const path = require('path');
13+
import fs from 'fs';
14+
import path from 'path';
15+
import { fileURLToPath } from 'url';
16+
17+
const __filename = fileURLToPath(import.meta.url);
18+
const __dirname = path.dirname(__filename);
1219

1320
function main() {
1421
// Get package.json path
@@ -17,13 +24,19 @@ function main() {
1724
// Read package.json
1825
const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
1926

20-
// Get build ID from command line or generate timestamp
21-
const buildId = process.argv[2] || generateTimestamp();
27+
let buildId;
28+
if (process.argv.length === 2) {
29+
// No argument provided
30+
buildId = generateTimestamp();
31+
} else {
32+
// Empty string means remove build ID
33+
buildId = process.argv[2];
34+
}
2235

2336
// Parse current version and add/update build ID
2437
const currentVersion = pkg.version;
2538
const baseVersion = currentVersion.split('+')[0]; // Remove existing build ID if present
26-
const newVersion = `${baseVersion}+${buildId}`;
39+
const newVersion = buildId ? `${baseVersion}+${buildId}` : baseVersion;
2740

2841
// Update version
2942
pkg.version = newVersion;
@@ -46,4 +59,3 @@ function generateTimestamp() {
4659
}
4760

4861
main();
49-

0 commit comments

Comments
 (0)