diff --git a/.changeset/plain-hats-sniff.md b/.changeset/plain-hats-sniff.md deleted file mode 100644 index ddf4050fc..000000000 --- a/.changeset/plain-hats-sniff.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'mermaid': minor ---- - -chore:Added workflow file for validating pnpm-lock file diff --git a/.github/workflows/validate-lockfile.yml b/.github/workflows/validate-lockfile.yml index d1cf1eb13..1c88b3063 100644 --- a/.github/workflows/validate-lockfile.yml +++ b/.github/workflows/validate-lockfile.yml @@ -23,25 +23,34 @@ jobs: node-version: 20 - name: Validate pnpm-lock.yaml entries + id: validate # give this step an ID so we can reference its outputs run: | - forbidden=( - 'tarball:' # no tarball fields - 'packages/mermaid/src/vitepress' # no vitepress paths - ) + issues=() - for pat in "${forbidden[@]}"; do - if grep -qF "$pat" pnpm-lock.yaml; then - echo "❌ Forbidden pattern \"$pat\" found in pnpm-lock.yaml" - exit 1 - fi - done + # 1) No tarball references + if grep -qF 'tarball:' pnpm-lock.yaml; then + issues+=("• Tarball references found (forbidden)") + fi - - name: Ensure pnpm-lock.yaml only when package.json changes - run: | - git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > changed_files.txt - if grep -q '^pnpm-lock.yaml$' changed_files.txt && \ - ! grep -q 'package.json' changed_files.txt; then - echo "❌ pnpm-lock.yaml was changed without any package.json" + # 2) No unwanted vitepress paths + if grep -qF 'packages/mermaid/src/vitepress' pnpm-lock.yaml; then + issues+=("• Disallowed path 'packages/mermaid/src/vitepress' present") + fi + + # 3) Lockfile only changes when package.json changes + git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > changed.txt + if grep -q '^pnpm-lock.yaml$' changed.txt && ! grep -q 'package.json' changed.txt; then + issues+=("• pnpm-lock.yaml changed without any package.json modification") + fi + + # If any issues, output them and fail + if [ ${#issues[@]} -gt 0 ]; then + # Use the new GITHUB_OUTPUT approach to set a multiline output + { + echo "errors<> $GITHUB_OUTPUT exit 1 fi @@ -54,11 +63,9 @@ jobs: body: | ## 🔍 Lockfile Validation Failed - One or more issues were found in `pnpm-lock.yaml`: - - Tarball references are not allowed. - - `packages/mermaid/src/vitepress` path must not appear in the lockfile. - - `pnpm-lock.yaml` should only change when `package.json` changes. + The following issue(s) were detected in `pnpm-lock.yaml`: + ${{ steps.validate.outputs.errors }} - Please fix these issues and push an update. + Please address these and push an update. _Posted automatically by GitHub Actions_