From 0de9b202cf6c5d01f760027af93622b78385a867 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 17:35:17 +0000 Subject: [PATCH 01/17] Initial coverage report. --- .github/workflows/ci.yml | 43 ++++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + noxfile.py | 3 +-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cf0f9245..46e9318a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -96,8 +96,20 @@ jobs: - run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl + - name: Store coverage file + uses: actions/upload-artifact@v3 + with: + # We have a single artifact shared for each workflow run. + # in this way we should intefere with coverage reports from other PRs + # or previous runs for the same PR. + name: coverage-${{ github.run_id }} + # Is important to keep the unique names for the coverage files + # so that when uploaded to the same artifact, they don't overlap. + path: .coverage.* + - name: Codecov run: | + coverage combine codecov -n "GitHub Actions - ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}" @@ -232,6 +244,37 @@ jobs: password: ${{ secrets.PYPI_TOKEN }} verbose: true + coverage-report: + name: Coverage report + runs-on: ubuntu-latest + needs: + # We are waiting only for test jobs. + - test-linux + - test-windows + steps: + - uses: actions/checkout@v3 + + - name: Install dependencies + run: python -m pip install --upgrade pip coverage[toml] diff_cover + + - name: Download coverage reports + uses: actions/download-artifact@v3 + with: + name: coverage-${{ github.run_id }} + path: . + + - name: Combine coverage + run: coverage combine + + - name: Report coverage + run: coverage report + + - name: Diff coverage + run: | + coverage xml + diff-cover --fail-under=100 coverage.xml + + # This is a meta-job to simplify PR CI enforcement configuration in GitHub. # Inside the GitHub config UI you only configure this job as required. # All the extra requirements are defined "as code" as part of the `needs` diff --git a/.gitignore b/.gitignore index c44127a6..d7a5a53a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ dist/ venv/ htmlcov/ .coverage +coverage.xml *~ *.lock apidocs/ diff --git a/noxfile.py b/noxfile.py index 38b65b98..0056f8e7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -36,9 +36,8 @@ def tests(session: nox.Session) -> None: session.run("coverage", "run", "--module", "twisted.trial", *posargs) if os.environ.get("CI") != "true": + # When running the test localy, show the coverage report. session.notify("coverage_report") - else: - session.run("coverage", "combine") @nox.session From 4dd13730f30187208499ece990c3c655736e0da2 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 18:14:24 +0000 Subject: [PATCH 02/17] Enable for windows. --- .github/CODEOWNERS | 2 -- .github/workflows/ci.yml | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) delete mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index b2d2c22e..00000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,2 +0,0 @@ -# See https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners -* @twisted/twisted-contributors diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 46e9318a..8a59dfe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -105,10 +105,11 @@ jobs: name: coverage-${{ github.run_id }} # Is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. - path: .coverage.* + path: .coverage* - name: Codecov run: | + ls -al .coverage* coverage combine codecov -n "GitHub Actions - ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}" @@ -149,8 +150,21 @@ jobs: - run: nox --python ${{ matrix.python.action }} -e ${{ matrix.task.nox }} -- --use-wheel dist/*.whl + - name: Store coverage file + uses: actions/upload-artifact@v3 + with: + # We have a single artifact shared for each workflow run. + # in this way we should intefere with coverage reports from other PRs + # or previous runs for the same PR. + name: coverage-${{ github.run_id }} + # Is important to keep the unique names for the coverage files + # so that when uploaded to the same artifact, they don't overlap. + path: .coverage* + - name: Codecov run: | + ls -al .coverage* + coverage combine codecov -n "GitHub Actions - ${{ matrix.task.name}} - ${{ matrix.os.name }} ${{ matrix.python.name }}" check: @@ -253,6 +267,8 @@ jobs: - test-windows steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Install dependencies run: python -m pip install --upgrade pip coverage[toml] diff_cover @@ -267,7 +283,7 @@ jobs: run: coverage combine - name: Report coverage - run: coverage report + run: coverage report --no-skip-covered --show-missing - name: Diff coverage run: | From cf12435818957514566dd6d9b53480bc2706071c Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 21:30:54 +0000 Subject: [PATCH 03/17] Try to support windows paths for coverage. --- .github/workflows/ci.yml | 1 + pyproject.toml | 6 +++++- src/towncrier/newsfragments/410.misc | 0 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 src/towncrier/newsfragments/410.misc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a59dfe6..343136ae 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -309,6 +309,7 @@ jobs: - test-windows - check - pypi-publish + - coverage-report steps: - name: Require all successes uses: re-actors/alls-green@3a2de129f0713010a71314c74e33c0e3ef90e696 diff --git a/pyproject.toml b/pyproject.toml index bff18919..c02e71ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -91,7 +91,11 @@ branch = true source = ["towncrier"] [tool.coverage.paths] -source = ["src", ".nox/*/site-packages"] +source = [ + "src", + "*.nox/*/site-packages", + "*.nox\\*\\*\\site-packages" +] [tool.coverage.report] show_missing = true diff --git a/src/towncrier/newsfragments/410.misc b/src/towncrier/newsfragments/410.misc new file mode 100644 index 00000000..e69de29b From 10d82253dbf263f09a81cb1eddfa58ab80c735e6 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 21:47:37 +0000 Subject: [PATCH 04/17] Try the branch. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 343136ae..cc1faacf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -287,8 +287,9 @@ jobs: - name: Diff coverage run: | + git fetch coverage xml - diff-cover --fail-under=100 coverage.xml + diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml # This is a meta-job to simplify PR CI enforcement configuration in GitHub. From 2a1ffafc360be57154ddecab7462c9a5bbccb4a9 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 22:09:34 +0000 Subject: [PATCH 05/17] Update all-success to newer version that as no set-output warnings. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc1faacf..c5533e99 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -313,6 +313,6 @@ jobs: - coverage-report steps: - name: Require all successes - uses: re-actors/alls-green@3a2de129f0713010a71314c74e33c0e3ef90e696 + uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe with: jobs: ${{ toJSON(needs) }} From d787a30526d4a78250841a6329214814de9fa51f Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 22:26:08 +0000 Subject: [PATCH 06/17] Add a comment. --- .github/scripts/pr_comment.js | 42 +++++++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 19 ++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 .github/scripts/pr_comment.js diff --git a/.github/scripts/pr_comment.js b/.github/scripts/pr_comment.js new file mode 100644 index 00000000..449561ef --- /dev/null +++ b/.github/scripts/pr_comment.js @@ -0,0 +1,42 @@ +/* +Have a single comment on a PR, identified by a comment marker. + +Create a new comment if no comment already exists. +Update the content of the existing comment. + + +https://octokit.github.io/rest.js/v19 +*/ +module.exports = async ({octokit_rest, context, process}) => { + if (context.eventName != "pull_request") { + // Only PR are supported. + return + } + + var sleep = function(second) { + return new Promise(resolve => setTimeout(resolve, second * 1000)) + } + + /* + Perform the actual logic. + + This is wrapped so that we can retry on errors. + */ + var doAction = async function() { + + await octokit_rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.event.number, + body: process.env.COMMENT_BODY, + }); + + } + + try { + await doAction() + } catch (e) { + await sleep(5) + await doAction() + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5533e99..44147ea1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -283,13 +283,28 @@ jobs: run: coverage combine - name: Report coverage - run: coverage report --no-skip-covered --show-missing + id: coverage-report + run: | + coverage report --no-skip-covered --show-missing + echo "coverage-report=$(coverage report --show-missing)" >> $GITHUB_OUTPUT + + # Use the generic JS script to call our custom script + # for sending a comment to a PR. + - uses: actions/github-script@v3 + env: + COMMENT_MARKER: coverage-report + COMMENT_BODY: ${{ needs.coverage-report.outputs.report }} + with: + script: | + const script = require(`${process.env.GITHUB_WORKSPACE}/.github/scripts/pr_comment.js`) + // Only pass top level objects as GHA does dependecy injection. + await script({github, context, process}) - name: Diff coverage run: | git fetch coverage xml - diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml + diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml # This is a meta-job to simplify PR CI enforcement configuration in GitHub. From 04d844836fcaff5e45eff814b4c39361d0f28213 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 22:39:46 +0000 Subject: [PATCH 07/17] Pass comment via a file to handle newlines. --- .github/scripts/pr_comment.js | 15 +++++++++++++-- .github/workflows/ci.yml | 5 ++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/scripts/pr_comment.js b/.github/scripts/pr_comment.js index 449561ef..74960d01 100644 --- a/.github/scripts/pr_comment.js +++ b/.github/scripts/pr_comment.js @@ -24,12 +24,23 @@ module.exports = async ({octokit_rest, context, process}) => { */ var doAction = async function() { + fs = require('fs'); + var body = fs.readFile( + process.env.GITHUB_WORKSPACE + "/" + process.env.COMMENT_BODY) + + var comments = await octokit.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.event.number, + }) + console.log(comments) + await octokit_rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.event.number, - body: process.env.COMMENT_BODY, - }); + body: body, + }) } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 44147ea1..2fcb1f8f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -283,17 +283,16 @@ jobs: run: coverage combine - name: Report coverage - id: coverage-report run: | coverage report --no-skip-covered --show-missing - echo "coverage-report=$(coverage report --show-missing)" >> $GITHUB_OUTPUT + coverage report --show-missing > coverage-report.txt # Use the generic JS script to call our custom script # for sending a comment to a PR. - uses: actions/github-script@v3 env: COMMENT_MARKER: coverage-report - COMMENT_BODY: ${{ needs.coverage-report.outputs.report }} + COMMENT_BODY: coverage-report.txt with: script: | const script = require(`${process.env.GITHUB_WORKSPACE}/.github/scripts/pr_comment.js`) From a86b23b1e206cdf5897d59f6c72a1df8d227ce8c Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Fri, 4 Nov 2022 22:45:26 +0000 Subject: [PATCH 08/17] Use nodejs like a pro. --- .github/scripts/pr_comment.js | 43 ++++++++++++++++++++++++++++------- .github/workflows/ci.yml | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/.github/scripts/pr_comment.js b/.github/scripts/pr_comment.js index 74960d01..c6b94ecf 100644 --- a/.github/scripts/pr_comment.js +++ b/.github/scripts/pr_comment.js @@ -7,7 +7,8 @@ Update the content of the existing comment. https://octokit.github.io/rest.js/v19 */ -module.exports = async ({octokit_rest, context, process}) => { +module.exports = async ({github, context, process}) => { + var octokit_rest = github if (context.eventName != "pull_request") { // Only PR are supported. return @@ -24,23 +25,49 @@ module.exports = async ({octokit_rest, context, process}) => { */ var doAction = async function() { + console.log(context) + fs = require('fs'); - var body = fs.readFile( - process.env.GITHUB_WORKSPACE + "/" + process.env.COMMENT_BODY) - var comments = await octokit.rest.issues.listComments({ + const body = fs.readFileSync( + process.env.GITHUB_WORKSPACE + "/" + process.env.COMMENT_BODY, 'utf8'); + var comment_id = null + var comment_marker = '\n' + process.env.COMMENT_MARKER + var comment_body = body + comment_marker + + var comments = await octokit_rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.event.number, + issue_number: context.payload.number, }) + console.log(comments) + comments.data.forEach(comment => { + if (comment.body.endsWith(comment_marker)) { + comment_id = comment.id + } + }) + + if (comment_id) { + // We have an existing comment. + // update the content. + await octokit_rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: comment_id, + body: comment_body, + }) + return + } + + // Create a new comment. await octokit_rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.event.number, - body: body, - }) + issue_number: context.payload.number, + body: comment_body, + }) } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fcb1f8f..d338a6dd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -291,7 +291,7 @@ jobs: # for sending a comment to a PR. - uses: actions/github-script@v3 env: - COMMENT_MARKER: coverage-report + COMMENT_MARKER: "" COMMENT_BODY: coverage-report.txt with: script: | From e4d2e1af602b1a3837f1728870acdbf71747ddaa Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 19:54:34 +0000 Subject: [PATCH 09/17] Apply suggestions from code review Co-authored-by: Kyle Altendorf --- .github/workflows/ci.yml | 9 +++++---- noxfile.py | 2 +- pyproject.toml | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d338a6dd..79df16aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -154,10 +154,10 @@ jobs: uses: actions/upload-artifact@v3 with: # We have a single artifact shared for each workflow run. - # in this way we should intefere with coverage reports from other PRs + # in this way we should not interfere with coverage reports from other PRs # or previous runs for the same PR. name: coverage-${{ github.run_id }} - # Is important to keep the unique names for the coverage files + # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. path: .coverage* @@ -271,7 +271,9 @@ jobs: fetch-depth: 0 - name: Install dependencies - run: python -m pip install --upgrade pip coverage[toml] diff_cover + run: | + python -m pip install --upgrade pip + python -m pip install --upgrade coverage[toml] diff_cover - name: Download coverage reports uses: actions/download-artifact@v3 @@ -301,7 +303,6 @@ jobs: - name: Diff coverage run: | - git fetch coverage xml diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml diff --git a/noxfile.py b/noxfile.py index 0056f8e7..f82b77d0 100644 --- a/noxfile.py +++ b/noxfile.py @@ -36,7 +36,7 @@ def tests(session: nox.Session) -> None: session.run("coverage", "run", "--module", "twisted.trial", *posargs) if os.environ.get("CI") != "true": - # When running the test localy, show the coverage report. + # When running the test locally, show the coverage report. session.notify("coverage_report") diff --git a/pyproject.toml b/pyproject.toml index c02e71ce..a1d8a0ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,6 +94,7 @@ source = ["towncrier"] source = [ "src", "*.nox/*/site-packages", + # required until coverage 6.6.0 is used: https://github.com/nedbat/coveragepy/issues/991 "*.nox\\*\\*\\site-packages" ] From 8208990ecbdbd4454d39a3f461215c7aba748e62 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 21:11:54 +0000 Subject: [PATCH 10/17] Include diff. Wrap in markdown. --- .github/scripts/pr_comment.js | 2 +- .github/workflows/ci.yml | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/scripts/pr_comment.js b/.github/scripts/pr_comment.js index c6b94ecf..da4e11ad 100644 --- a/.github/scripts/pr_comment.js +++ b/.github/scripts/pr_comment.js @@ -33,7 +33,7 @@ module.exports = async ({github, context, process}) => { process.env.GITHUB_WORKSPACE + "/" + process.env.COMMENT_BODY, 'utf8'); var comment_id = null var comment_marker = '\n' + process.env.COMMENT_MARKER - var comment_body = body + comment_marker + var comment_body = body + comment_marker var comments = await octokit_rest.issues.listComments({ owner: context.repo.owner, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79df16aa..2be8ec85 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -286,8 +286,13 @@ jobs: - name: Report coverage run: | + coverage xml coverage report --no-skip-covered --show-missing - coverage report --show-missing > coverage-report.txt + # Wrap in + echo '```' > coverage-report.txt + coverage report --show-missing >> coverage-report.txt + diff-cover --compare-branch origin/trunk coverage.xml >> coverage-report.txt + echo '```' >> coverage-report.txt # Use the generic JS script to call our custom script # for sending a comment to a PR. @@ -301,10 +306,9 @@ jobs: // Only pass top level objects as GHA does dependecy injection. await script({github, context, process}) - - name: Diff coverage + - name: Enforce diff coverage run: | - coverage xml - diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml + diff-cover --fail-under=100 --compare-branch origin/trunk coverage.xml # This is a meta-job to simplify PR CI enforcement configuration in GitHub. From dac2d586ebe7585b0fd4f7bd3a711cbd2c8d16c9 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 21:12:00 +0000 Subject: [PATCH 11/17] Enable test report. --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a1d8a0ed..f202af36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -107,5 +107,4 @@ exclude_lines = [ ] omit = [ "src/towncrier/__main__.py", - "src/towncrier/test/*", ] From 12f3c8124399efb97f6595a7e0bc6f6cfb2535d4 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 22:04:34 +0000 Subject: [PATCH 12/17] Fix after re-review. --- .github/scripts/pr_comment.js | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/pr_comment.js b/.github/scripts/pr_comment.js index da4e11ad..c6b94ecf 100644 --- a/.github/scripts/pr_comment.js +++ b/.github/scripts/pr_comment.js @@ -33,7 +33,7 @@ module.exports = async ({github, context, process}) => { process.env.GITHUB_WORKSPACE + "/" + process.env.COMMENT_BODY, 'utf8'); var comment_id = null var comment_marker = '\n' + process.env.COMMENT_MARKER - var comment_body = body + comment_marker + var comment_body = body + comment_marker var comments = await octokit_rest.issues.listComments({ owner: context.repo.owner, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2be8ec85..24562feb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -100,10 +100,10 @@ jobs: uses: actions/upload-artifact@v3 with: # We have a single artifact shared for each workflow run. - # in this way we should intefere with coverage reports from other PRs + # in this way we should not interfere with coverage reports from other PRs # or previous runs for the same PR. name: coverage-${{ github.run_id }} - # Is important to keep the unique names for the coverage files + # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. path: .coverage* From 77f12dc55b0f1b7bcd0e91f7b3b130fb9b402178 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 22:40:48 +0000 Subject: [PATCH 13/17] Remove run_id from coverage artifact. --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 24562feb..c8472c86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -102,7 +102,7 @@ jobs: # We have a single artifact shared for each workflow run. # in this way we should not interfere with coverage reports from other PRs # or previous runs for the same PR. - name: coverage-${{ github.run_id }} + name: coverage # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. path: .coverage* @@ -156,7 +156,7 @@ jobs: # We have a single artifact shared for each workflow run. # in this way we should not interfere with coverage reports from other PRs # or previous runs for the same PR. - name: coverage-${{ github.run_id }} + name: coverage # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. path: .coverage* @@ -278,7 +278,7 @@ jobs: - name: Download coverage reports uses: actions/download-artifact@v3 with: - name: coverage-${{ github.run_id }} + name: coverage path: . - name: Combine coverage From 743613efe4705f071f09718c9fce0b1ad7a2adac Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 22:53:50 +0000 Subject: [PATCH 14/17] Add a name for the comment script. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c8472c86..5a6428cf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -296,7 +296,8 @@ jobs: # Use the generic JS script to call our custom script # for sending a comment to a PR. - - uses: actions/github-script@v3 + - name: Send coverage comment to PR + uses: actions/github-script@v3 env: COMMENT_MARKER: "" COMMENT_BODY: coverage-report.txt From e0ca8107807bb3db10490dd2261410985b6b9c5a Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sat, 5 Nov 2022 23:02:07 +0000 Subject: [PATCH 15/17] Remove comment about single artifact as this is what we have by default for a workflow. --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a6428cf..0f119862 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,9 +99,6 @@ jobs: - name: Store coverage file uses: actions/upload-artifact@v3 with: - # We have a single artifact shared for each workflow run. - # in this way we should not interfere with coverage reports from other PRs - # or previous runs for the same PR. name: coverage # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. @@ -153,9 +150,6 @@ jobs: - name: Store coverage file uses: actions/upload-artifact@v3 with: - # We have a single artifact shared for each workflow run. - # in this way we should not interfere with coverage reports from other PRs - # or previous runs for the same PR. name: coverage # It is important to keep the unique names for the coverage files # so that when uploaded to the same artifact, they don't overlap. From 322ce2591f67028ff5e7ee5a16620a6c0b309af0 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 6 Nov 2022 01:07:51 +0000 Subject: [PATCH 16/17] Add restricted permissions for token. --- .github/workflows/ci.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f119862..5b554989 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: tags: [ "**" ] pull_request: +permissions: + contents: read + defaults: run: shell: bash @@ -255,6 +258,10 @@ jobs: coverage-report: name: Coverage report runs-on: ubuntu-latest + permissions: + # Even we send a comment to a PR, we use the issues API. + # Issues and PR share the same comment API. + issues: write needs: # We are waiting only for test jobs. - test-linux @@ -282,7 +289,7 @@ jobs: run: | coverage xml coverage report --no-skip-covered --show-missing - # Wrap in + # Wrap output in markdown verbatim text. echo '```' > coverage-report.txt coverage report --show-missing >> coverage-report.txt diff-cover --compare-branch origin/trunk coverage.xml >> coverage-report.txt From 04a1c1b1a5f011c0db71f9ebceb0b7fb2ff7d451 Mon Sep 17 00:00:00 2001 From: Adi Roiban Date: Sun, 6 Nov 2022 13:04:03 +0000 Subject: [PATCH 17/17] Use markdown report for diff-cover. --- .github/workflows/ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5b554989..3757d50b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -292,8 +292,9 @@ jobs: # Wrap output in markdown verbatim text. echo '```' > coverage-report.txt coverage report --show-missing >> coverage-report.txt - diff-cover --compare-branch origin/trunk coverage.xml >> coverage-report.txt echo '```' >> coverage-report.txt + diff-cover --markdown-report diff-cover.md --compare-branch origin/trunk coverage.xml + cat diff-cover.md >> coverage-report.txt # Use the generic JS script to call our custom script # for sending a comment to a PR.