|
| 1 | +name: Diff |
| 2 | +on: |
| 3 | + issue_comment: |
| 4 | + types: [created] |
| 5 | + |
| 6 | +jobs: |
| 7 | + generate: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + outputs: |
| 10 | + diffs: ${{ steps.regress-ci.outputs.diffs }} |
| 11 | + if: ${{ github.event.issue.pull_request }} |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + |
| 15 | + - uses: dtolnay/rust-toolchain@master |
| 16 | + with: |
| 17 | + toolchain: stable |
| 18 | + |
| 19 | + - name: Cache |
| 20 | + uses: Swatinem/rust-cache@v2 |
| 21 | + with: |
| 22 | + shared-key: "diff" |
| 23 | + |
| 24 | + - run: cargo regress ci |
| 25 | + id: regress-ci |
| 26 | + env: |
| 27 | + GITHUB_COMMENT: ${{ github.event.comment.body }} |
| 28 | + GITHUB_COMMENT_PR: ${{ github.event.comment.issue_url }} |
| 29 | + diff: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + needs: [generate] |
| 32 | + if: needs.generate.outputs.diffs != '{}' && needs.generate.outputs.diffs != '[]' && needs.generate.outputs.diffs != '' |
| 33 | + strategy: |
| 34 | + matrix: |
| 35 | + include: ${{ fromJson(needs.generate.outputs.diffs) }} |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v4 |
| 38 | + |
| 39 | + - uses: dtolnay/rust-toolchain@master |
| 40 | + with: |
| 41 | + toolchain: stable |
| 42 | + |
| 43 | + - name: Cache |
| 44 | + uses: Swatinem/rust-cache@v2 |
| 45 | + with: |
| 46 | + shared-key: "diff" |
| 47 | + |
| 48 | + - uses: taiki-e/install-action@v2 |
| 49 | + if: matrix.needs_semver_checks |
| 50 | + with: |
| 51 | + tool: cargo-semver-checks |
| 52 | + |
| 53 | + # if a new line is added here, make sure to update the `summary` job to reference the new step index |
| 54 | + - uses: taiki-e/install-action@v2 |
| 55 | + with: |
| 56 | + tool: git-delta |
| 57 | + |
| 58 | + - run: cargo regress diff ${{ matrix.command }} --use-pager-directly |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ github.token }} |
| 61 | + GITHUB_PR: ${{ matrix.pr }} |
| 62 | + GIT_PAGER: delta --hunk-header-style omit |
| 63 | + summary: |
| 64 | + runs-on: ubuntu-latest |
| 65 | + needs: [diff, generate] |
| 66 | + if: always() && needs.generate.outputs.diffs != '{}' && needs.generate.outputs.diffs != '[]' && needs.generate.outputs.diffs != '' |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - run: | |
| 71 | + PR_ID=$(echo "${{ github.event.comment.issue_url }}" | grep -o '[0-9]\+$') |
| 72 | + gh run view ${{ github.run_id }} --json jobs | \ |
| 73 | + jq -r '"Diff for [comment]("+$comment+")\n\n" + ([.jobs[] | select(.name | startswith("diff")) | "- [" + (.name | capture("\\((?<name>[^,]+),.*") | .name) + "](" + .url + "?pr=" + $pr_id + "#step:7:45)"] | join("\n"))' --arg pr_id "$PR_ID" --arg comment "${{ github.event.comment.url }}"| \ |
| 74 | + gh pr comment "$PR_ID" --body "$(< /dev/stdin)" |
| 75 | + env: |
| 76 | + GH_TOKEN: ${{ github.token }} |
0 commit comments