|
| 1 | +name: Validate README.md |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened] |
| 6 | + paths: |
| 7 | + - "instructions/**" |
| 8 | + - "prompts/**" |
| 9 | + - "chatmodes/**" |
| 10 | + - "*.js" |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate-readme: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | + - name: Setup Node.js |
| 22 | + uses: actions/setup-node@v4 |
| 23 | + with: |
| 24 | + node-version: "20" |
| 25 | + |
| 26 | + - name: Update README.md |
| 27 | + run: node update-readme.js |
| 28 | + |
| 29 | + - name: Check for README.md changes |
| 30 | + id: check-diff |
| 31 | + run: | |
| 32 | + if git diff --exit-code README.md; then |
| 33 | + echo "No changes to README.md after running update script." |
| 34 | + echo "status=success" >> $GITHUB_OUTPUT |
| 35 | + else |
| 36 | + echo "Changes detected in README.md after running update script." |
| 37 | + echo "status=failure" >> $GITHUB_OUTPUT |
| 38 | + echo "diff<<EOF" >> $GITHUB_OUTPUT |
| 39 | + git diff README.md >> $GITHUB_OUTPUT |
| 40 | + echo "EOF" >> $GITHUB_OUTPUT |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Comment on PR if README.md needs updating |
| 44 | + if: steps.check-diff.outputs.status == 'failure' |
| 45 | + uses: actions/github-script@v7 |
| 46 | + with: |
| 47 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + script: | |
| 49 | + const diff = `${{ steps.check-diff.outputs.diff }}`; |
| 50 | + const body = `## ⚠️ README.md needs to be updated |
| 51 | +
|
| 52 | + The \`update-readme.js\` script detected changes that need to be made to the README.md file. |
| 53 | +
|
| 54 | + Please run \`node update-readme.js\` locally and commit the changes before merging this PR. |
| 55 | +
|
| 56 | + <details> |
| 57 | + <summary>View diff</summary> |
| 58 | + |
| 59 | + \`\`\`diff |
| 60 | + ${diff} |
| 61 | + \`\`\` |
| 62 | + </details>`; |
| 63 | +
|
| 64 | + github.rest.issues.createComment({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + issue_number: context.issue.number, |
| 68 | + body: body |
| 69 | + }); |
| 70 | +
|
| 71 | + - name: Fail workflow if README.md needs updating |
| 72 | + if: steps.check-diff.outputs.status == 'failure' |
| 73 | + run: | |
| 74 | + echo "❌ README.md needs to be updated. Please run 'node update-readme.js' locally and commit the changes." |
| 75 | + exit 1 |
0 commit comments