| 1 | name: Validate pnpm-lock.yaml |
| 2 | |
| 3 | on: |
| 4 | pull_request_target: |
| 5 | paths: |
| 6 | - 'pnpm-lock.yaml' |
| 7 | - '**/package.json' |
| 8 | - '.github/workflows/validate-lockfile.yml' |
| 9 | |
| 10 | jobs: |
| 11 | validate-lockfile: |
| 12 | runs-on: ubuntu-latest |
| 13 | steps: |
| 14 | - name: Checkout code |
| 15 | uses: actions/checkout@v4 |
| 16 | with: |
| 17 | fetch-depth: 0 |
| 18 | ref: ${{ github.event.pull_request.head.sha }} |
| 19 | repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 20 | |
| 21 | - name: Validate pnpm-lock.yaml entries |
| 22 | id: validate # give this step an ID so we can reference its outputs |
| 23 | run: | |
| 24 | issues=() |
| 25 | |
| 26 | # 1) No tarball references |
| 27 | if grep -qF 'tarball:' pnpm-lock.yaml; then |
| 28 | issues+=("• Tarball references found (forbidden)") |
| 29 | fi |
| 30 | |
| 31 | # 2) No unwanted vitepress paths |
| 32 | if grep -qF 'packages/mermaid/src/vitepress' pnpm-lock.yaml; then |
| 33 | issues+=("• Disallowed path 'packages/mermaid/src/vitepress' present. Run \`rm -rf packages/mermaid/src/vitepress && pnpm install\` to regenerate.") |
| 34 | fi |
| 35 | |
| 36 | # 3) Lockfile only changes when package.json changes |
| 37 | git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > changed.txt |
| 38 | if grep -q '^pnpm-lock.yaml$' changed.txt && ! grep -q 'package.json' changed.txt; then |
| 39 | issues+=("• pnpm-lock.yaml changed without any package.json modification") |
| 40 | fi |
| 41 | |
| 42 | # If any issues, output them and fail |
| 43 | if [ ${#issues[@]} -gt 0 ]; then |
| 44 | # Use the new GITHUB_OUTPUT approach to set a multiline output |
| 45 | { |
| 46 | echo "errors<<EOF" |
| 47 | printf '%s\n' "${issues[@]}" |
| 48 | echo "EOF" |
| 49 | } >> $GITHUB_OUTPUT |
| 50 | exit 1 |
| 51 | fi |
| 52 | |
| 53 | - name: Find existing lockfile validation comment |
| 54 | if: always() |
| 55 | uses: peter-evans/find-comment@v3 |
| 56 | id: find-comment |
| 57 | with: |
| 58 | issue-number: ${{ github.event.pull_request.number }} |
| 59 | comment-author: 'github-actions[bot]' |
| 60 | body-includes: 'Lockfile Validation Failed' |
| 61 | |
| 62 | - name: Comment on PR if validation failed |
| 63 | if: failure() |
| 64 | uses: peter-evans/create-or-update-comment@v5 |
| 65 | with: |
| 66 | token: ${{ secrets.GITHUB_TOKEN }} |
| 67 | issue-number: ${{ github.event.pull_request.number }} |
| 68 | comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 69 | edit-mode: replace |
| 70 | body: | |
| 71 | ❌ **Lockfile Validation Failed** |
| 72 | |
| 73 | The following issue(s) were detected: |
| 74 | ${{ steps.validate.outputs.errors }} |
| 75 | |
| 76 | Please address these and push an update. |
| 77 | |
| 78 | _Posted automatically by GitHub Actions_ |
| 79 | |
| 80 | - name: Delete comment if validation passed |
| 81 | if: success() && steps.find-comment.outputs.comment-id != '' |
| 82 | uses: actions/github-script@v7 |
| 83 | with: |
| 84 | github-token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | script: | |
| 86 | await github.rest.issues.deleteComment({ |
| 87 | owner: context.repo.owner, |
| 88 | repo: context.repo.repo, |
| 89 | comment_id: ${{ steps.find-comment.outputs.comment-id }}, |
| 90 | }); |
| 91 | |