From ff4237fa2410c96a1438e6d22cd519207b5e71b2 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:40:41 -0800 Subject: [PATCH] Match mypy primer comment code (#13318) These actions diverged, making them more closely match makes it easier to maintain --- .github/workflows/mypy_primer.yml | 35 +++++++++++++++++------ .github/workflows/mypy_primer_comment.yml | 31 ++++++++++---------- 2 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.github/workflows/mypy_primer.yml b/.github/workflows/mypy_primer.yml index fc0ffbfed20e..7f1dbb9a5f31 100644 --- a/.github/workflows/mypy_primer.yml +++ b/.github/workflows/mypy_primer.yml @@ -57,18 +57,35 @@ jobs: --output concise \ | tee diff_${{ matrix.shard-index }}.txt ) || [ $? -eq 1 ] - - name: Upload mypy_primer diff - uses: actions/upload-artifact@v4 - with: - name: mypy_primer_diff_${{ matrix.shard-index }} - path: diff_${{ matrix.shard-index }}.txt - if: ${{ matrix.shard-index == 0 }} name: Save PR number run: | echo ${{ github.event.pull_request.number }} | tee pr_number.txt - - if: ${{ matrix.shard-index == 0 }} - name: Upload PR number + - name: Upload mypy_primer diff + PR number uses: actions/upload-artifact@v4 + if: ${{ matrix.shard-index == 0 }} + with: + name: mypy_primer_diffs-${{ matrix.shard-index }} + path: | + diff_${{ matrix.shard-index }}.txt + pr_number.txt + - name: Upload mypy_primer diff + uses: actions/upload-artifact@v4 + if: ${{ matrix.shard-index != 0 }} + with: + name: mypy_primer_diffs-${{ matrix.shard-index }} + path: diff_${{ matrix.shard-index }}.txt + + join_artifacts: + name: Join artifacts + runs-on: ubuntu-latest + needs: [mypy_primer] + permissions: + contents: read + steps: + - name: Merge artifacts + uses: actions/upload-artifact/merge@v4 with: - name: mypy_primer_diff_pr_number - path: pr_number.txt + name: mypy_primer_diffs + pattern: mypy_primer_diffs-* + delete-merged: true diff --git a/.github/workflows/mypy_primer_comment.yml b/.github/workflows/mypy_primer_comment.yml index 8b5aedd9fbb7..5fa6fe016706 100644 --- a/.github/workflows/mypy_primer_comment.yml +++ b/.github/workflows/mypy_primer_comment.yml @@ -1,4 +1,4 @@ -name: Post mypy_primer comment +name: Comment with mypy_primer diff on: workflow_run: @@ -14,8 +14,8 @@ permissions: jobs: comment: name: Comment PR from mypy_primer - if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: Download diffs uses: actions/github-script@v7 @@ -27,20 +27,18 @@ jobs: repo: context.repo.repo, run_id: ${{ github.event.workflow_run.id }}, }); - const matchArtifacts = artifacts.data.artifacts.filter((artifact) => - artifact.name.startsWith("mypy_primer_diff")); + const [matchArtifact] = artifacts.data.artifacts.filter((artifact) => + artifact.name == "mypy_primer_diffs"); - for (const matchArtifact of matchArtifacts) { - const download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: "zip", - }); - fs.writeFileSync(`${matchArtifact.name}.zip`, Buffer.from(download.data)); - } + const download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifact.id, + archive_format: "zip", + }); + fs.writeFileSync("diff.zip", Buffer.from(download.data)); - - run: for file in *.zip; do unzip $file; done + - run: unzip diff.zip - run: | cat diff_*.txt | tee fulldiff.txt @@ -48,7 +46,7 @@ jobs: id: post-comment uses: actions/github-script@v7 with: - github-token: ${{secrets.GITHUB_TOKEN}} + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs') let data = fs.readFileSync('fulldiff.txt', { encoding: 'utf8' }) @@ -61,6 +59,9 @@ jobs: data = truncated_data + `\n\n... (truncated ${lines_truncated} lines) ...\n` } + console.log("Diff from mypy_primer:") + console.log(data) + let body if (data.trim()) { body = 'Diff from [mypy_primer](https://github.com/hauntsaninja/mypy_primer), showing the effect of this PR on open source code:\n```diff\n' + data + '```'