|
| 1 | +name: PR Check |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [master] |
| 6 | + paths: |
| 7 | + - "data/tools/**.yml" |
| 8 | + - "ci/**" |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + pr_number: |
| 12 | + description: "PR number to check" |
| 13 | + required: true |
| 14 | + tool_files: |
| 15 | + description: "Space-separated list of tool YAML files to check (e.g. data/tools/foo.yml)" |
| 16 | + required: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + pr-check: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + permissions: |
| 22 | + contents: read |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Check out PR head for manual runs |
| 29 | + if: github.event_name == 'workflow_dispatch' |
| 30 | + run: | |
| 31 | + git fetch origin "refs/pull/${{ inputs.pr_number }}/head" |
| 32 | + git checkout FETCH_HEAD -- ${{ inputs.tool_files }} |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Get changed tool files |
| 37 | + id: changed |
| 38 | + run: | |
| 39 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 40 | + FILES="${{ inputs.tool_files }}" |
| 41 | + else |
| 42 | + FILES=$(git diff --name-only --diff-filter=A origin/master...HEAD -- 'data/tools/*.yml' 'data/tools/*.yaml' | tr '\n' ' ') |
| 43 | + fi |
| 44 | + echo "files=$FILES" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + - name: Install Rust toolchain |
| 47 | + uses: dtolnay/rust-toolchain@stable |
| 48 | + |
| 49 | + - name: Cache cargo registry |
| 50 | + uses: actions/cache@v4 |
| 51 | + with: |
| 52 | + path: | |
| 53 | + ~/.cargo/registry |
| 54 | + ~/.cargo/git |
| 55 | + ci/target |
| 56 | + key: pr-check-${{ runner.os }}-${{ hashFiles('ci/Cargo.lock') }} |
| 57 | + restore-keys: | |
| 58 | + pr-check-${{ runner.os }}- |
| 59 | +
|
| 60 | + - name: Build pr-check |
| 61 | + run: cargo build --release --manifest-path ci/Cargo.toml -p pr-check |
| 62 | + |
| 63 | + - name: Run pr-check |
| 64 | + id: run-check |
| 65 | + env: |
| 66 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 68 | + PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} |
| 69 | + # For pull_request events (including forks), write the comment to a |
| 70 | + # file instead of posting it directly. The fork's GITHUB_TOKEN does |
| 71 | + # not have write access to the base repository, so direct posting |
| 72 | + # returns 403. The pr-comment workflow picks up this artifact and |
| 73 | + # posts the comment with the right permissions. |
| 74 | + COMMENT_OUTPUT_FILE: ${{ github.event_name == 'pull_request' && 'pr-check-output/comment.md' || '' }} |
| 75 | + run: | |
| 76 | + mkdir -p pr-check-output |
| 77 | + echo "$PR_NUMBER" > pr-check-output/pr_number.txt |
| 78 | + if ci/target/release/pr-check ${{ steps.changed.outputs.files }}; then |
| 79 | + echo "passed" > pr-check-output/result.txt |
| 80 | + else |
| 81 | + echo "failed" > pr-check-output/result.txt |
| 82 | + fi |
| 83 | +
|
| 84 | + - name: Upload check results |
| 85 | + if: always() && github.event_name == 'pull_request' |
| 86 | + uses: actions/upload-artifact@v4 |
| 87 | + with: |
| 88 | + name: pr-check-output |
| 89 | + path: pr-check-output/ |
| 90 | + |
| 91 | + - name: Fail if checks did not pass |
| 92 | + if: always() |
| 93 | + run: | |
| 94 | + result=$(cat pr-check-output/result.txt 2>/dev/null || echo "failed") |
| 95 | + [ "$result" = "passed" ] |
0 commit comments