From fff3acd0648902f939a50cdb77871c213c264b76 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Tue, 18 Jul 2023 21:55:44 +0530 Subject: [PATCH] Verify release-version on push to release or master --- .github/workflows/build-docs.yml | 8 ++++++ .github/workflows/publish-docs.yml | 13 --------- packages/mermaid/package.json | 1 + .../scripts/update-release-version.mts | 27 ++++++++++++++++--- 4 files changed, 32 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index b25ff89cc7..152b177ae9 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -1,6 +1,10 @@ name: Build Vitepress docs on: + push: + branches: + - master + - release/* pull_request: merge_group: @@ -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 diff --git a/.github/workflows/publish-docs.yml b/.github/workflows/publish-docs.yml index d66d61a26f..f63e587502 100644 --- a/.github/workflows/publish-docs.yml +++ b/.github/workflows/publish-docs.yml @@ -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 diff --git a/packages/mermaid/package.json b/packages/mermaid/package.json index fd5a459a02..cf0979d48f 100644 --- a/packages/mermaid/package.json +++ b/packages/mermaid/package.json @@ -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", diff --git a/packages/mermaid/scripts/update-release-version.mts b/packages/mermaid/scripts/update-release-version.mts index edd2017b92..82fa6442a7 100644 --- a/packages/mermaid/scripts/update-release-version.mts +++ b/packages/mermaid/scripts/update-release-version.mts @@ -15,20 +15,39 @@ import { } from '../src/docs.mjs'; import { writeFile } from 'fs/promises'; +const verifyOnly: boolean = process.argv.includes('--verify'); +const versionPlaceholder = ''; + 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(//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();