From e06ce32409088929dc10ce5c28947ce67daa8a83 Mon Sep 17 00:00:00 2001 From: dblock Date: Thu, 18 Apr 2024 10:54:48 -0400 Subject: [PATCH 1/2] Fix: replace pull_request_target with a download/upload artifact. Signed-off-by: dblock --- .github/workflows/coverage-comment.yml | 53 +++++++++++++++++++ .../{coverage.yml => coverage-gather.yml} | 25 +++++---- 2 files changed, 65 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..a65f2582f --- /dev/null +++ b/.github/workflows/coverage-comment.yml @@ -0,0 +1,53 @@ +name: Comment with API Coverage + +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" + })[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.zip', Buffer.from(download.data)); + - run: | + unzip coverage.zip + cat coverage.json + + - name: 'Comment on PR' + uses: actions/github-script@v3 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + var data = JSON.parse(fs.readFileSync('./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" < Date: Fri, 19 Apr 2024 07:23:38 -0400 Subject: [PATCH 2/2] Use upload/download-artifact@v4. Signed-off-by: dblock --- .github/workflows/coverage-comment.yml | 25 ++++--------------------- .github/workflows/coverage-gather.yml | 2 +- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/.github/workflows/coverage-comment.yml b/.github/workflows/coverage-comment.yml index a65f2582f..687c269a4 100644 --- a/.github/workflows/coverage-comment.yml +++ b/.github/workflows/coverage-comment.yml @@ -14,28 +14,11 @@ jobs: github.event.workflow_run.conclusion == 'success' steps: - name: Download Coverage Report - uses: actions/github-script@v3.1.0 + uses: actions/download-artifact@v4 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" - })[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.zip', Buffer.from(download.data)); - - run: | - unzip coverage.zip - cat coverage.json + github-token: ${{ secrets.GITHUB_TOKEN }} + name: coverage + run-id: ${{ github.event.workflow_run.id }} - name: 'Comment on PR' uses: actions/github-script@v3 diff --git a/.github/workflows/coverage-gather.yml b/.github/workflows/coverage-gather.yml index 0d1c8d217..703c0c6ab 100644 --- a/.github/workflows/coverage-gather.yml +++ b/.github/workflows/coverage-gather.yml @@ -56,7 +56,7 @@ jobs: "percent":$percent } EOL - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: coverage path: coverage.json \ No newline at end of file