|
| 1 | +name: PR Reviewdog |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - "Test" |
| 7 | + types: |
| 8 | + - completed |
| 9 | + |
| 10 | +permissions: |
| 11 | + # Download artifact from lint workflow. |
| 12 | + actions: read |
| 13 | + # Post inline review comments via reviewdog. |
| 14 | + pull-requests: write |
| 15 | + # Report commit status. |
| 16 | + statuses: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + reviewdog: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + env: |
| 22 | + STATUS_PATH: repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_sha }} |
| 23 | + STATUS_CONTEXT: ${{ github.workflow }} |
| 24 | + STATUS_TARGET: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 25 | + steps: |
| 26 | + - name: Mark status as pending |
| 27 | + env: |
| 28 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + run: | |
| 30 | + gh api "$STATUS_PATH" \ |
| 31 | + -f state=pending \ |
| 32 | + -f context="$STATUS_CONTEXT" \ |
| 33 | + -f description='Running' \ |
| 34 | + -f target_url="$STATUS_TARGET" |
| 35 | +
|
| 36 | + - name: Identify PR |
| 37 | + id: identify-pr |
| 38 | + env: |
| 39 | + BASE_REPO: ${{ github.repository }} |
| 40 | + GITHUB_TOKEN: ${{ github.token }} |
| 41 | + HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} |
| 42 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 43 | + run: | |
| 44 | + PR_NUMBER=$(gh api "repos/$HEAD_REPO/commits/$HEAD_SHA/pulls" \ |
| 45 | + --jq ".[] | select(.base.repo.full_name == \"$BASE_REPO\") | .number") |
| 46 | + echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Download artifact |
| 49 | + if: steps.identify-pr.outputs.number |
| 50 | + continue-on-error: true |
| 51 | + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 52 | + with: |
| 53 | + name: lint-results |
| 54 | + path: lint-results |
| 55 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + run-id: ${{ github.event.workflow_run.id }} |
| 57 | + |
| 58 | + - name: Check for artifact |
| 59 | + id: check |
| 60 | + if: steps.identify-pr.outputs.number && hashFiles('lint-results/') != '' |
| 61 | + run: echo "HAS_ARTIFACT=true" >> "$GITHUB_OUTPUT" |
| 62 | + |
| 63 | + - name: Checkout |
| 64 | + if: steps.identify-pr.outputs.number |
| 65 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 66 | + with: |
| 67 | + path: browser-compat-data |
| 68 | + ref: main |
| 69 | + persist-credentials: false |
| 70 | + |
| 71 | + - name: Setup reviewdog |
| 72 | + if: steps.check.outputs.HAS_ARTIFACT == 'true' |
| 73 | + uses: reviewdog/action-setup@d8a7baabd7f3e8544ee4dbde3ee41d0011c3a93f # v1.5.0 |
| 74 | + with: |
| 75 | + reviewdog_version: latest |
| 76 | + |
| 77 | + - name: Add PR review with suggested changes using `git diff` output |
| 78 | + if: steps.check.outputs.HAS_ARTIFACT == 'true' && hashFiles('lint-results/lint.diff') != '' |
| 79 | + working-directory: browser-compat-data |
| 80 | + env: |
| 81 | + CI_PULL_REQUEST: ${{ steps.identify-pr.outputs.number }} |
| 82 | + CI_COMMIT: ${{ github.event.workflow_run.head_sha }} |
| 83 | + CI_REPO_OWNER: ${{ github.repository_owner }} |
| 84 | + CI_REPO_NAME: ${{ github.event.repository.name }} |
| 85 | + CI_BRANCH: ${{ github.event.workflow_run.head_branch }} |
| 86 | + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + run: | |
| 88 | + env -u GITHUB_ACTIONS reviewdog \ |
| 89 | + -guess \ |
| 90 | + -name="bcd-linter" \ |
| 91 | + -f=diff \ |
| 92 | + -f.diff.strip=1 \ |
| 93 | + -filter-mode=diff_context \ |
| 94 | + -reporter=github-pr-review < ../lint-results/lint.diff |
| 95 | +
|
| 96 | + - name: Mark status as success |
| 97 | + if: success() |
| 98 | + env: |
| 99 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + run: | |
| 101 | + gh api "$STATUS_PATH" \ |
| 102 | + -f state=success \ |
| 103 | + -f context="$STATUS_CONTEXT" \ |
| 104 | + -f description='Successful' \ |
| 105 | + -f target_url="$STATUS_TARGET" |
| 106 | +
|
| 107 | + - name: Mark status as failure |
| 108 | + if: failure() |
| 109 | + env: |
| 110 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 111 | + run: | |
| 112 | + gh api "$STATUS_PATH" \ |
| 113 | + -f state=failure \ |
| 114 | + -f context="$STATUS_CONTEXT" \ |
| 115 | + -f description='Failing' \ |
| 116 | + -f target_url="$STATUS_TARGET" |
0 commit comments