diff --git a/.github/workflows/detekt-comment.yml b/.github/workflows/detekt-comment.yml index 49a5abc0c..d5b8c569e 100644 --- a/.github/workflows/detekt-comment.yml +++ b/.github/workflows/detekt-comment.yml @@ -7,7 +7,6 @@ on: - completed permissions: - actions: read pull-requests: write jobs: @@ -18,18 +17,32 @@ jobs: pull-requests: write steps: - - name: Get PR number + - name: Download PR event artifact uses: actions/github-script@v6 - id: get-pr with: script: | - const run = await github.rest.actions.getWorkflowRun({ + const fs = require('fs') + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ owner: context.repo.owner, repo: context.repo.repo, run_id: ${{ github.event.workflow_run.id }} - }); - return run.data.pull_requests[0].number; - result-encoding: string + }) + const matchArtifact = artifacts.data.artifacts.find(artifact => artifact.name === "pr") + const download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip' + }) + fs.writeFileSync('pr.zip', Buffer.from(download.data)) + + - run: unzip pr.zip + + - name: Get PR number + id: pr + run: | + PR_NUMBER=$(jq -r '.number' event.json) + echo "number=$PR_NUMBER" >> $GITHUB_OUTPUT - name: Comment PR uses: actions/github-script@v6 @@ -37,8 +50,9 @@ jobs: github-token: ${{secrets.GITHUB_TOKEN}} script: | github.rest.issues.createComment({ - issue_number: ${{ steps.get-pr.outputs.result }}, + issue_number: ${{ steps.pr.outputs.number }}, owner: context.repo.owner, repo: context.repo.repo, body: "Detekt check failed. Please run `./gradlew detekt --auto-correct` to fix the issues." }) + diff --git a/.github/workflows/detekt.yml b/.github/workflows/detekt.yml index a96138f11..da8e56b5b 100644 --- a/.github/workflows/detekt.yml +++ b/.github/workflows/detekt.yml @@ -20,3 +20,15 @@ jobs: - name: Run detekt id: detekt run: ./gradlew detekt --stacktrace + + - name: Save PR event + if: failure() + run: | + mkdir -p ./pr + echo '${{ toJson(github.event) }}' > ./pr/event.json + + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: pr + path: pr/