Skip to content

Commit

Permalink
Verify release-version on push to release or master
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Jul 18, 2023
1 parent 07df9ee commit fff3acd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Build Vitepress docs

on:
push:
branches:
- master
- release/*
pull_request:
merge_group:

Expand All @@ -25,5 +29,9 @@ jobs:
- name: Install Packages
run: pnpm install --frozen-lockfile

- name: Verify release verion
if: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release')) }}
run: pnpm --filter mermaid run docs:verify-version

- name: Run Build
run: pnpm --filter mermaid run docs:build:vitepress
13 changes: 0 additions & 13 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ jobs:
- name: Install Packages
run: pnpm install --frozen-lockfile

- name: Update release verion
run: |
pnpm --filter mermaid run docs:release-version
pnpm --filter mermaid run docs:build
- name: Commit changes
uses: EndBug/add-and-commit@v9
with:
add: '["docs", "packages/mermaid/src/docs"]'
author_name: ${{ github.actor }}
author_email: ${{ github.actor }}@users.noreply.github.com
message: 'chore: Update MERMAID_RELEASE_VERSION in docs'

- name: Setup Pages
uses: actions/configure-pages@v3

Expand Down
1 change: 1 addition & 0 deletions packages/mermaid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"docs:serve": "pnpm docs:build:vitepress && vitepress serve src/vitepress",
"docs:spellcheck": "cspell --config ../../cSpell.json \"src/docs/**/*.md\"",
"docs:release-version": "ts-node-esm scripts/update-release-version.mts",
"docs:verify-version": "ts-node-esm scripts/update-release-version.mts --verify",
"types:build-config": "ts-node-esm --transpileOnly scripts/create-types-from-json-schema.mts",
"types:verify-config": "ts-node-esm scripts/create-types-from-json-schema.mts --verify",
"release": "pnpm build",
Expand Down
27 changes: 23 additions & 4 deletions packages/mermaid/scripts/update-release-version.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,39 @@ import {
} from '../src/docs.mjs';
import { writeFile } from 'fs/promises';

const verifyOnly: boolean = process.argv.includes('--verify');
const versionPlaceholder = '<MERMAID_RELEASE_VERSION>';

const main = async () => {
const sourceDirGlob = posix.join('.', SOURCE_DOCS_DIR, '**');
const mdFileGlobs = getGlobs([posix.join(sourceDirGlob, '*.md')]);
mdFileGlobs.push('!**/community/development.md');
const mdFiles = await getFilesFromGlobs(mdFileGlobs);
mdFiles.sort();
const mdFilesWithPlaceholder: string[] = [];
for (const mdFile of mdFiles) {
const content = readSyncedUTF8file(mdFile);
const updatedContent = content.replace(/<MERMAID_RELEASE_VERSION>/g, MERMAID_RELEASE_VERSION);
if (content !== updatedContent) {
await writeFile(mdFile, updatedContent);
console.log(`Updated MERMAID_RELEASE_VERSION in ${mdFile}`);
if (content.includes(versionPlaceholder)) {
mdFilesWithPlaceholder.push(mdFile);
}
}

if (mdFilesWithPlaceholder.length === 0) {
return;
}

if (verifyOnly) {
console.log(
`${mdFilesWithPlaceholder.length} file(s) were found with the placeholder ${versionPlaceholder}. Run \`pnpm --filter mermaid docs:release-version\` to update them.`
);
process.exit(1);
}

for (const mdFile of mdFilesWithPlaceholder) {
const content = readSyncedUTF8file(mdFile);
const newContent = content.replace(versionPlaceholder, MERMAID_RELEASE_VERSION);
await writeFile(mdFile, newContent);
}
};

void main();

0 comments on commit fff3acd

Please sign in to comment.