Skip to content
Merged
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
2 changes: 2 additions & 0 deletions docsy.dev/content/en/project/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ Planned content organization (tentative):

## Site build information

Docsy version: `{{% _param versionWithBuildId %}}`

{{% td/site-build-info/netlify team="docsydocs" %}}
7 changes: 4 additions & 3 deletions docsy.dev/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ params:
to_year: present
privacy_policy: https://policies.google.com/privacy
archived_version: false
version: 0.14.2-dev-003-over-main-1f21d33c
version: 0.14.2-dev
versionWithBuildId: 0.14.2-dev+004-over-main-55a3fb27
github_repo: https://github.com/google/docsy
github_project_repo: https://github.com/google/docsy
github_subdir: docsy.dev
Expand Down Expand Up @@ -120,11 +121,11 @@ params:
developer:
- name: Contributing
url: /docs/contribution-guidelines/
icon: fa fa-book
icon: fa-solid fa-code-fork
desc: How to contribute
- name: Project docs and site info
url: /project/
icon: fa fa-book
icon: fa-solid fa-book
desc: Site design documentation and resources
- name: Tests
url: /tests/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docsy",
"version": "0.14.2-dev-003-over-main-1f21d33c",
"version": "0.14.2-dev+004-over-main-55a3fb27",
"repository": "github:google/docsy",
"homepage": "https://www.docsy.dev",
"license": "Apache-2.0",
Expand Down
4 changes: 2 additions & 2 deletions scripts/get-build-id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Example, from:
# - main at v0.14.0 (617b5960)
# - `git describe --tags` v0.14.0-1-g8047f659
# We get: 0.14.1-dev-001-over-main-617b5960
# We get: 0.14.1-dev+001-over-main-617b5960

set -euo pipefail

Expand All @@ -29,4 +29,4 @@ build_num_padded=$(printf "%03d" "${build_num}")
# Pin the base to the current main tip hash.
main_sha=$(git rev-parse --short=8 main)

echo "${major}.${minor}.${next_patch}-dev-${build_num_padded}-over-main-${main_sha}"
echo "${major}.${minor}.${next_patch}-dev+${build_num_padded}-over-main-${main_sha}"
94 changes: 88 additions & 6 deletions scripts/set-package-version/hugo-yaml.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// cSpell:ignore docsy

/**
* Utilities for reading and writing the version field in docsy.dev/hugo.yaml.
* Utilities for reading and writing version fields in docsy.dev/hugo.yaml.
*/

import fs from 'fs';
Expand Down Expand Up @@ -57,6 +57,15 @@ export function readHugoYaml() {
if (versionMatch) {
result.params.version = versionMatch[1].trim();
}

const versionWithBuildIdMatch = line.match(
/^ versionWithBuildId:\s*(.*)$/,
);
if (versionWithBuildIdMatch) {
result.params.versionWithBuildId = stripYamlQuotes(
versionWithBuildIdMatch[1].trim(),
);
}
}
}

Expand All @@ -67,9 +76,10 @@ export function writeHugoYaml(hugoYaml) {
const content = fs.readFileSync(getHugoYamlPath(), 'utf8');
const lines = content.split('\n');

// Update the version line under params
// Update version fields under params.
let inParams = false;
let updated = false;
let versionUpdated = false;
let versionWithBuildIdUpdated = false;
const newLines = lines.map((line) => {
const trimmed = line.trim();

Expand All @@ -93,16 +103,27 @@ export function writeHugoYaml(hugoYaml) {
if (inParams) {
const versionMatch = line.match(/^ version:\s*(.+)$/);
if (versionMatch && hugoYaml.params?.version !== undefined) {
updated = true;
versionUpdated = true;
return ` version: ${hugoYaml.params.version}`;
}

const versionWithBuildIdMatch = line.match(
/^ versionWithBuildId:\s*(.*)$/,
);
if (
versionWithBuildIdMatch &&
hugoYaml.params?.versionWithBuildId !== undefined
) {
versionWithBuildIdUpdated = true;
return ` versionWithBuildId: ${yamlScalar(hugoYaml.params.versionWithBuildId)}`;
}
}

return line;
});

// If version line wasn't found, add it after params:
if (!updated && hugoYaml.params?.version !== undefined) {
// Add missing version line under params.
if (!versionUpdated && hugoYaml.params?.version !== undefined) {
for (let i = 0; i < newLines.length; i++) {
if (newLines[i].trim() === 'params:') {
// Find the next non-indented line or end of params section
Expand All @@ -124,5 +145,66 @@ export function writeHugoYaml(hugoYaml) {
}
}

// Add missing versionWithBuildId line under params.
if (
!versionWithBuildIdUpdated &&
hugoYaml.params?.versionWithBuildId !== undefined
) {
for (let i = 0; i < newLines.length; i++) {
if (newLines[i].trim() === 'params:') {
// Prefer placing versionWithBuildId immediately after version.
let insertIndex = -1;
for (let j = i + 1; j < newLines.length; j++) {
if (newLines[j].match(/^ version:\s*/)) {
insertIndex = j + 1;
break;
}
if (
newLines[j].match(/^[a-z_]+:/) &&
!newLines[j].match(/^params:/) &&
!newLines[j].match(/^ /)
) {
break;
}
}

if (insertIndex === -1) {
insertIndex = i + 1;
while (
insertIndex < newLines.length &&
(newLines[insertIndex].match(/^ /) ||
newLines[insertIndex].trim() === '')
) {
insertIndex++;
}
}

newLines.splice(
insertIndex,
0,
` versionWithBuildId: ${yamlScalar(hugoYaml.params.versionWithBuildId)}`,
);
break;
}
}
}

fs.writeFileSync(getHugoYamlPath(), newLines.join('\n'));
}

function stripYamlQuotes(value) {
if (
(value.startsWith("'") && value.endsWith("'")) ||
(value.startsWith('"') && value.endsWith('"'))
) {
return value.slice(1, -1);
}
return value;
}

function yamlScalar(value) {
if (value === '') {
return "''";
}
return String(value);
}
Loading
Loading