From 4e01d0495d33270dbd34a10d5c01c0c5ad030c20 Mon Sep 17 00:00:00 2001 From: Adam Mika Date: Fri, 1 Dec 2023 14:47:55 -0700 Subject: [PATCH] first pass at trying to get failed rustfmt summary as comment --- .github/workflows/ci.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8edf1f7..16bfce2e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,9 @@ jobs: format: name: cargo fmt runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write steps: - uses: actions/checkout@v4 - name: Setup Rustfmt @@ -39,3 +42,20 @@ jobs: components: rustfmt - name: Rustfmt Check uses: actions-rust-lang/rustfmt@v1 + - name: Save Failure Summary (if needed) + if: failure() + run: echo "$GITHUB_STEP_SUMMARY" > summary.md + - name: Comment Failure Summary (if needed) + if: failure() && github.event_name == 'pull_request' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const summary = fs.readFileSync('summary.md', 'utf8'); + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: summary + });