|
5 | 5 | branches: [master] |
6 | 6 |
|
7 | 7 | jobs: |
8 | | - build: |
| 8 | + readme-check: |
9 | 9 | runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + pull-requests: write |
| 12 | + contents: read |
10 | 13 | steps: |
11 | 14 | - uses: actions/checkout@v4 |
| 15 | + with: |
| 16 | + fetch-depth: 0 |
12 | 17 |
|
13 | | - - name: Install Rust toolchain |
14 | | - uses: dtolnay/rust-toolchain@stable |
| 18 | + - name: Check README.md was not edited directly |
| 19 | + id: readme |
| 20 | + run: | |
| 21 | + TRUSTED="mre jakubsacha" |
| 22 | + AUTHOR="${{ github.event.pull_request.user.login }}" |
| 23 | + for u in $TRUSTED; do |
| 24 | + if [ "$AUTHOR" = "$u" ]; then |
| 25 | + echo "trusted=true" >> "$GITHUB_OUTPUT" |
| 26 | + exit 0 |
| 27 | + fi |
| 28 | + done |
| 29 | + if git diff --name-only origin/master...HEAD | grep -q "^README.md$"; then |
| 30 | + echo "modified=true" >> "$GITHUB_OUTPUT" |
| 31 | + fi |
15 | 32 |
|
16 | | - - name: Prevent file change |
17 | | - uses: xalvarez/prevent-file-change-action@v1 |
| 33 | + - name: Comment and fail on direct README edit |
| 34 | + if: steps.readme.outputs.modified == 'true' |
| 35 | + env: |
| 36 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + PR: ${{ github.event.pull_request.number }} |
| 38 | + REPO: ${{ github.repository }} |
| 39 | + run: | |
| 40 | + gh api "repos/$REPO/issues/$PR/comments" \ |
| 41 | + -f body="README.md was edited directly. The README is generated from the YAML files in \`data/tools/\`. Please add or edit the corresponding file in \`data/tools/\` instead and do not touch README.md." \ |
| 42 | + --silent |
| 43 | + echo "README.md must not be edited directly." >&2 |
| 44 | + exit 1 |
| 45 | +
|
| 46 | + render: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + permissions: |
| 49 | + pull-requests: write |
| 50 | + contents: read |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
18 | 53 | with: |
19 | | - githubToken: ${{ secrets.GITHUB_TOKEN }} |
20 | | - pattern: README.md |
21 | | - trustedAuthors: mre, jakubsacha |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Install Rust toolchain |
| 57 | + uses: dtolnay/rust-toolchain@stable |
22 | 58 |
|
23 | 59 | - name: Render list |
24 | | - run: make render-skip-deprecated |
| 60 | + id: render |
| 61 | + run: | |
| 62 | + make render-skip-deprecated 2>&1 | tee /tmp/render-output.txt |
| 63 | + exit ${PIPESTATUS[0]} |
| 64 | +
|
| 65 | + - name: Comment render error on failure |
| 66 | + if: failure() && steps.render.outcome == 'failure' |
| 67 | + env: |
| 68 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 69 | + PR: ${{ github.event.pull_request.number }} |
| 70 | + REPO: ${{ github.repository }} |
| 71 | + run: | |
| 72 | + OUTPUT=$(grep -E "^Error" /tmp/render-output.txt | head -20) |
| 73 | + { |
| 74 | + echo "The render step failed with the following error:" |
| 75 | + echo "" |
| 76 | + echo '```' |
| 77 | + echo "$OUTPUT" |
| 78 | + echo '```' |
| 79 | + echo "" |
| 80 | + echo "Please check your YAML file in \`data/tools/\` against the format used by other tools in that directory." |
| 81 | + } > /tmp/render-comment.txt |
| 82 | + gh api "repos/$REPO/issues/$PR/comments" \ |
| 83 | + -f body=@/tmp/render-comment.txt \ |
| 84 | + --silent |
0 commit comments