From 5971b7db23ea50d83f02570a9116315c843c8a04 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 18 Apr 2024 10:54:48 -0400 Subject: [PATCH] Fix: replace pull_request_target with a download/upload artifact. Signed-off-by: dblock --- .github/workflows/coverage-comment.yml | 51 +++++++++++++++++++ .../{coverage.yml => coverage-gather.yml} | 25 +++++---- 2 files changed, 63 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/coverage-comment.yml rename .github/workflows/{coverage.yml => coverage-gather.yml} (78%) diff --git a/.github/workflows/coverage-comment.yml b/.github/workflows/coverage-comment.yml new file mode 100644 index 000000000..3f96bcb22 --- /dev/null +++ b/.github/workflows/coverage-comment.yml @@ -0,0 +1,51 @@ +name: Comment wuth API Coverage + +# read-write repo token +# access to secrets +on: + workflow_run: + workflows: ["Gather API Coverage"] + types: + - completed + +jobs: + comment: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: Download Coverage Report + uses: actions/github-script@v3.1.0 + with: + script: | + var artifacts = await github.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: ${{github.event.workflow_run.id }}, + }); + var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "coverage.json" + })[0]; + var download = await github.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/coverage.json', Buffer.from(download.data)); + + - name: 'Comment on PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const data = require('./coverage.json'); + console.log(data); + await github.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: data.pull_request, + body: "API specs implemented for ${{ data.current }}/${{ data.total }} (${{ data.percent }}%) APIs." + }); \ No newline at end of file diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage-gather.yml similarity index 78% rename from .github/workflows/coverage.yml rename to .github/workflows/coverage-gather.yml index 4ad04baf0..0d1c8d217 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage-gather.yml @@ -1,6 +1,6 @@ -name: API Coverage +name: Gather API Coverage -on: [push, pull_request_target] +on: [push, pull_request] env: JAVA_VERSION: 11 @@ -14,8 +14,6 @@ jobs: steps: - name: Checkout Repo uses: actions/checkout@v2 - with: - ref: ${{ github.event.pull_request.head.sha }} - name: Build Spec working-directory: ./tools run: |- @@ -50,14 +48,15 @@ jobs: total=`jq -r '.paths | keys | length' build/local-openapi.json` percent=$((current * 100 / total)) echo "API specs implemented for $current/$total ($percent%) APIs." - cat >>"$GITHUB_OUTPUT" <>"coverage.json" <