From 834ea90ae8793e47ec3e161fd30d4faad598709e Mon Sep 17 00:00:00 2001 From: Matthew McCall Date: Sat, 23 Mar 2024 14:43:31 -0400 Subject: [PATCH] [Workflow] Unify Code Coverage Workflow (#75) * Simplified code coverage commenting * Moved commenting to single file * Removed unused variable and use correct llvm-cov tool * Remove save PR number step --- .github/workflows/code-coverage-comment.yml | 81 --------------------- .github/workflows/code-coverage.yml | 37 ++++------ 2 files changed, 16 insertions(+), 102 deletions(-) delete mode 100644 .github/workflows/code-coverage-comment.yml diff --git a/.github/workflows/code-coverage-comment.yml b/.github/workflows/code-coverage-comment.yml deleted file mode 100644 index 3f978b85..00000000 --- a/.github/workflows/code-coverage-comment.yml +++ /dev/null @@ -1,81 +0,0 @@ -# ############################################################################## -# OASIS: Open Algebra Software for Inferring Solutions -# -# code-coverage-comment.yml -# ############################################################################## - -name: Code Coverage Comment - -on: - workflow_run: - workflows: [ "Code Coverage" ] - types: - - completed - -permissions: - contents: read - issues: write - pull-requests: write - -jobs: - write-comment: - runs-on: ubuntu-latest - if: | - github.event.workflow_run.event == 'pull_request' && - github.event.workflow_run.conclusion == 'success' - - steps: - # Downloads the artifacts uploaded by the pull request workflow run. - - name: Download artifacts - uses: actions/github-script@v6 - with: - script: | - let artifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - - let matchArtifact1 = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "pr-number" - })[0]; - let download1 = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact1.id, - archive_format: 'zip', - }); - - let matchArtifact2 = artifacts.data.artifacts.filter((artifact) => { - return artifact.name == "build-test-cover" - })[0]; - let download2 = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact2.id, - archive_format: 'zip', - }); - - let fs = require('fs'); - fs.writeFileSync('${{github.workspace}}/pr-number.zip', Buffer.from(download1.data)); - fs.writeFileSync('${{github.workspace}}/build-test-cover.zip', Buffer.from(download2.data)); - - # Unzips the artifacts. - - name: Unzip artifacts - run: unzip \*.zip - - # Writes a comment on the pull request. - - name: Comment on PR - uses: actions/github-script@v6 - with: - script: | - let fs = require('fs'); - let issue_number = Number(fs.readFileSync('./issue_number')); - let coverage_file = fs.readFileSync('./coverage/reports/index.txt'); - - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue_number, - body: '```\n' + coverage_file + '\n```' - }); diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index c89f6bae..772cc8ca 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -10,6 +10,9 @@ on: pull_request: branches: [ "master" ] +permissions: + pull-requests: write + jobs: collect-coverage: runs-on: ubuntu-latest @@ -26,13 +29,6 @@ jobs: run: | echo "build-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" echo "coverage-dir=${{ github.workspace }}/coverage" >> "$GITHUB_OUTPUT" - echo "pr-dir=${{ github.workspace }}/pr" >> "$GITHUB_OUTPUT" - - # Saves the PR number to use in writing a comment on the PR. - - name: Save PR number - run: | - mkdir -p ${{ steps.strings.outputs.pr-dir }} - echo "${{ github.event.number }}" > ${{ steps.strings.outputs.pr-dir }}/issue_number # Installs LLVM 17 on the runner. - name: Install LLVM 17 @@ -81,20 +77,19 @@ jobs: shell: bash run: | llvm-profdata-17 merge -sparse oasis.profraw -o oasis.profdata - llvm-cov-17 show -output-dir reports -instr-profile oasis.profdata ${{ steps.strings.outputs.build-dir }}/tests/OasisTests -sources ${{ github.workspace }}/src ${{ github.workspace }}/include + llvm-cov-17 report -instr-profile oasis.profdata ${{ steps.strings.outputs.build-dir }}/tests/OasisTests -sources ${{ github.workspace }}/src ${{ github.workspace }}/include > coverage.txt # Uploads the build, test, and code coverage artifacts. - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: build-test-cover - path: | - ${{ steps.strings.outputs.build-dir }} - !${{ steps.strings.outputs.build-dir }}/_deps - ${{ steps.strings.outputs.coverage-dir }} - - - name: Upload PR number - uses: actions/upload-artifact@v3 + - name: Comment on PR + uses: actions/github-script@v6 with: - name: pr-number - path: ${{ steps.strings.outputs.pr-dir }} + script: | + const fs = require('fs'); + const coverage_file = fs.readFileSync('${{ steps.strings.outputs.coverage-dir }}/coverage.txt'); + + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: '```\n' + coverage_file + '\n```' + });