From 331df2b484e719a3208563a9e8099ab50062bf6e Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 13:16:27 +1100 Subject: [PATCH 01/18] Test out GITHUB_STEP_SUMMARY manipulation --- .github/workflows/test.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b98020d..822372bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -114,3 +114,36 @@ jobs: - name: "clippy --all" run: cargo clippy --all --features=full --tests -- -D warnings + + node-build-report: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Install + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + + - uses: Swatinem/rust-cache@v2 + + - uses: actions/setup-node@v4 + with: + node-version: "20" + + - name: Build bundle + run: yarn build + - name: Size Reporting + run: | + ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) + ARROW1_BR_SIZE=$(brotli -Z -c pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) + echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY + echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY + echo "| pkg/esm/arrow1_bg.wasm | $ARROW_SIZE |" >> $GITHUB_STEP_SUMMARY + echo "| pkg/esm/arrow1_bg.wasm.br | $ARROW1_BR_SIZE |" >> $GITHUB_STEP_SUMMARY + # TODO: matrix equivalent of this / and/or use the @actions/core npm package \ No newline at end of file From 5fddd5730ba814dc155eaf18e22be6b741c73e29 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 13:28:14 +1100 Subject: [PATCH 02/18] \/sigh, package installs --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 822372bd..e2ad75a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -135,6 +135,10 @@ jobs: - uses: actions/setup-node@v4 with: node-version: "20" + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: brotli pv + version: 1.0 - name: Build bundle run: yarn build From 1970e6016c7e056789e0ecc944c653e92df9d975 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 13:41:35 +1100 Subject: [PATCH 03/18] Typo fix, in-job diagnostics --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2ad75a5..0a78af28 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -146,8 +146,10 @@ jobs: run: | ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) ARROW1_BR_SIZE=$(brotli -Z -c pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) + echo $ARROW1_SIZE + echo $ARROW1_BR_SIZE echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY - echo "| pkg/esm/arrow1_bg.wasm | $ARROW_SIZE |" >> $GITHUB_STEP_SUMMARY + echo "| pkg/esm/arrow1_bg.wasm | $ARROW1_SIZE |" >> $GITHUB_STEP_SUMMARY echo "| pkg/esm/arrow1_bg.wasm.br | $ARROW1_BR_SIZE |" >> $GITHUB_STEP_SUMMARY # TODO: matrix equivalent of this / and/or use the @actions/core npm package \ No newline at end of file From cb6e19d3a688a552c5c1096153f064e9f8f60962 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 14:13:32 +1100 Subject: [PATCH 04/18] Swap to maintained rust toolchain action --- .github/workflows/test.yml | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0a78af28..f26ca980 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,11 +13,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true + uses: dtolnay/rust-toolchain@stable - name: Install run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -33,13 +29,10 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - profile: minimal - override: true + targets: wasm32-unknown-unknown - - run: rustup target add wasm32-unknown-unknown - uses: Swatinem/rust-cache@v2 - run: cargo install cargo-all-features @@ -53,11 +46,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true + uses: dtolnay/rust-toolchain@stable - name: Install run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -84,11 +73,8 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - profile: minimal - override: true components: rustfmt - uses: Swatinem/rust-cache@v2 @@ -103,11 +89,8 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - profile: minimal - override: true components: clippy - uses: Swatinem/rust-cache@v2 @@ -121,11 +104,7 @@ jobs: - uses: actions/checkout@v4 - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true + uses: dtolnay/rust-toolchain@stable - name: Install run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -145,7 +124,8 @@ jobs: - name: Size Reporting run: | ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) - ARROW1_BR_SIZE=$(brotli -Z -c pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) + brotli -Z pkg/esm/arrow1_bg.wasm + ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null) echo $ARROW1_SIZE echo $ARROW1_BR_SIZE echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY From 13a1a2b81a2c4a4141869c5a189d802895bc8b32 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 14:26:13 +1100 Subject: [PATCH 05/18] Yet more diagnostics --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f26ca980..436470c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,4 +132,5 @@ jobs: echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY echo "| pkg/esm/arrow1_bg.wasm | $ARROW1_SIZE |" >> $GITHUB_STEP_SUMMARY echo "| pkg/esm/arrow1_bg.wasm.br | $ARROW1_BR_SIZE |" >> $GITHUB_STEP_SUMMARY + echo $GITHUB_STEP_SUMMARY # TODO: matrix equivalent of this / and/or use the @actions/core npm package \ No newline at end of file From b3083a373c6cc4562cd97a1092b1a4e538dc17af Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 14:32:45 +1100 Subject: [PATCH 06/18] Of course it's a file --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 436470c4..c74481a6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,5 +132,5 @@ jobs: echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY echo "| pkg/esm/arrow1_bg.wasm | $ARROW1_SIZE |" >> $GITHUB_STEP_SUMMARY echo "| pkg/esm/arrow1_bg.wasm.br | $ARROW1_BR_SIZE |" >> $GITHUB_STEP_SUMMARY - echo $GITHUB_STEP_SUMMARY + cat $GITHUB_STEP_SUMMARY # TODO: matrix equivalent of this / and/or use the @actions/core npm package \ No newline at end of file From 7c02cc6ddd01302e0cab93b7135f78b98fa8e673 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 14:45:41 +1100 Subject: [PATCH 07/18] Tweak - trim trailing newline --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c74481a6..18a6cc14 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -123,9 +123,9 @@ jobs: run: yarn build - name: Size Reporting run: | - ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null) + ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null | tr -d '\n') brotli -Z pkg/esm/arrow1_bg.wasm - ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null) + ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null | tr -d '\n') echo $ARROW1_SIZE echo $ARROW1_BR_SIZE echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY From 7d1cf1308466d08f34af7bcc6bd294e8e283e9fd Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 14:56:33 +1100 Subject: [PATCH 08/18] Account for carriage returns --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 18a6cc14..1e07e2ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -123,9 +123,9 @@ jobs: run: yarn build - name: Size Reporting run: | - ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null | tr -d '\n') + ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') brotli -Z pkg/esm/arrow1_bg.wasm - ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null | tr -d '\n') + ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') echo $ARROW1_SIZE echo $ARROW1_BR_SIZE echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY From 88ce3bc12cdd510ede4a33b9501f19d4f84184ba Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 15:10:12 +1100 Subject: [PATCH 09/18] Switch to asset matrix summary --- .github/workflows/test.yml | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e07e2ab..c3877ccf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,21 +116,18 @@ jobs: node-version: "20" - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: brotli pv + packages: brotli pv parallel version: 1.0 - name: Build bundle run: yarn build - name: Size Reporting run: | - ARROW1_SIZE=$(cat pkg/esm/arrow1_bg.wasm | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') - brotli -Z pkg/esm/arrow1_bg.wasm - ARROW1_BR_SIZE=$(cat pkg/esm/arrow1_bg.wasm.br | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') - echo $ARROW1_SIZE - echo $ARROW1_BR_SIZE - echo "| Asset | Size |" >> $GITHUB_STEP_SUMMARY - echo "| ------ | ---- |" >> $GITHUB_STEP_SUMMARY - echo "| pkg/esm/arrow1_bg.wasm | $ARROW1_SIZE |" >> $GITHUB_STEP_SUMMARY - echo "| pkg/esm/arrow1_bg.wasm.br | $ARROW1_BR_SIZE |" >> $GITHUB_STEP_SUMMARY - cat $GITHUB_STEP_SUMMARY - # TODO: matrix equivalent of this / and/or use the @actions/core npm package \ No newline at end of file + ls pkg/*/*.wasm | parallel brotli -f -Z {} + echo "| Asset | Size | Compressed Size |" >> $GITHUB_STEP_SUMMARY + echo "| ------ | ---- | --------------- |" >> $GITHUB_STEP_SUMMARY + for asset in $(ls pkg/*/*.wasm); do + SIZE=$(cat $asset | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') + COMPRESSED_SIZE=$(cat "${asset}.br" | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') + echo "| ${asset} | $SIZE | $COMPRESSED_SIZE |" >> $GITHUB_STEP_SUMMARY + done; From e4c82c9511c2bf30dc0356e5b7ebd603f3e94a11 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 15:57:20 +1100 Subject: [PATCH 10/18] Attach github step summary directly in PR --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c3877ccf..592f7a5e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,3 +131,8 @@ jobs: COMPRESSED_SIZE=$(cat "${asset}.br" | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') echo "| ${asset} | $SIZE | $COMPRESSED_SIZE |" >> $GITHUB_STEP_SUMMARY done; + - name: Comment PR with execution number + uses: thollander/actions-comment-pull-request@v2 + with: + filePath: $GITHUB_STEP_SUMMARY + comment_tag: execution From b7e0503a6e845c703e00587d1853bb3236464504 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Sat, 2 Dec 2023 16:05:13 +1100 Subject: [PATCH 11/18] Account for variable expansion, swap step name to something more appropriate --- .github/workflows/test.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 592f7a5e..388c945c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,8 +131,9 @@ jobs: COMPRESSED_SIZE=$(cat "${asset}.br" | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') echo "| ${asset} | $SIZE | $COMPRESSED_SIZE |" >> $GITHUB_STEP_SUMMARY done; - - name: Comment PR with execution number + cp $GITHUB_STEP_SUMMARY fixed_output.md + - name: Comment PR with summary output uses: thollander/actions-comment-pull-request@v2 with: - filePath: $GITHUB_STEP_SUMMARY + filePath: fixed_output.md comment_tag: execution From 08a8698ab1676119d1675022428bffccc9ed5411 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 10:15:00 +1100 Subject: [PATCH 12/18] Workaround for fork PR permissions --- .github/workflows/pr-manipulation.yml | 42 +++++++++++++++++++++++++++ .github/workflows/test.yml | 11 +++---- 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/pr-manipulation.yml diff --git a/.github/workflows/pr-manipulation.yml b/.github/workflows/pr-manipulation.yml new file mode 100644 index 00000000..a2f7c7e7 --- /dev/null +++ b/.github/workflows/pr-manipulation.yml @@ -0,0 +1,42 @@ +name: PR Comment Generation + +on: + workflow_run: + workflows: ["Build and Test"] + types: + - completed + +jobs: + comment_on_pr: + runs-on: ubuntu-latest + if: > + github.event.workflow_run.event == 'pull_request' && + github.event.workflow_run.conclusion == 'success' + steps: + - name: 'Download artifact' + 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 == "pr" + })[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}}/pr.zip', Buffer.from(download.data)); + - run: unzip pr.zip + + - name: Comment PR with summary output + uses: thollander/actions-comment-pull-request@v2 + with: + filePath: step_summary.md + comment_tag: execution diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 388c945c..351ff380 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -131,9 +131,10 @@ jobs: COMPRESSED_SIZE=$(cat "${asset}.br" | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') echo "| ${asset} | $SIZE | $COMPRESSED_SIZE |" >> $GITHUB_STEP_SUMMARY done; - cp $GITHUB_STEP_SUMMARY fixed_output.md - - name: Comment PR with summary output - uses: thollander/actions-comment-pull-request@v2 + mkdir -p ./pr + echo ${{ github.event.number }} > ./pr/NR + cp $GITHUB_STEP_SUMMARY ./pr/step_summary.md + - uses: actions/upload-artifact@v2 with: - filePath: fixed_output.md - comment_tag: execution + name: pr + path: pr/ \ No newline at end of file From 10b0b112d571e6b9831311629c18aac213c6f1ee Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 10:36:02 +1100 Subject: [PATCH 13/18] ensure the comment step upserts (rather than creating a new commit on each workflow run) --- .github/workflows/pr-manipulation.yml | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-manipulation.yml b/.github/workflows/pr-manipulation.yml index a2f7c7e7..4b9d17a1 100644 --- a/.github/workflows/pr-manipulation.yml +++ b/.github/workflows/pr-manipulation.yml @@ -35,8 +35,22 @@ jobs: fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); - run: unzip pr.zip - - name: Comment PR with summary output - uses: thollander/actions-comment-pull-request@v2 + - name: 'Comment on PR' + uses: actions/github-script@v3 with: - filePath: step_summary.md - comment_tag: execution + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const fs = require('fs'); + const issueNumber = Number(fs.readFileSync('./NR')); + const summaryContent = fs.readFileSync('./step_summary.md', 'utf-8'); + const existingCommentsOpts = github.issues.listComments({...context.repo, issue_number: issueNumber}); + const existingComments = await github.paginate(existingCommentsOpts); + const TAG = 'execution'; + const tagPattern = ``; + const body = `${summaryContent}\n${tagPattern}`; + const preExistingComment = existingComments.find((comment) => comment.body.includes(tagPattern)); + if(preExistingComment) { + await github.issues.updateComment({ ...context.repo, comment_id: preExistingComment.id, body }); + } else { + await github.issues.createComment({ ...context.repo, issue_number: issueNumber, body }); + } From 804b7504e366bce9c99d6a91bcbc7a7f97583827 Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 14:05:31 +1100 Subject: [PATCH 14/18] finalize pr manipulation workflow --- .github/workflows/pr-manipulation.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-manipulation.yml b/.github/workflows/pr-manipulation.yml index 4b9d17a1..a50e5fce 100644 --- a/.github/workflows/pr-manipulation.yml +++ b/.github/workflows/pr-manipulation.yml @@ -43,12 +43,14 @@ jobs: const fs = require('fs'); const issueNumber = Number(fs.readFileSync('./NR')); const summaryContent = fs.readFileSync('./step_summary.md', 'utf-8'); - const existingCommentsOpts = github.issues.listComments({...context.repo, issue_number: issueNumber}); + const existingCommentsOpts = github.issues.listComments.endpoint.merge({ + ...context.repo, issue_number: issueNumber + }); const existingComments = await github.paginate(existingCommentsOpts); const TAG = 'execution'; const tagPattern = ``; const body = `${summaryContent}\n${tagPattern}`; - const preExistingComment = existingComments.find((comment) => comment.body.includes(tagPattern)); + const preExistingComment = existingComments.find((comment) => comment.body?.includes(tagPattern)); if(preExistingComment) { await github.issues.updateComment({ ...context.repo, comment_id: preExistingComment.id, body }); } else { From 781f66b7aa3fde169cfc44c8f59e1d25239b675a Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 20:14:11 +1100 Subject: [PATCH 15/18] Implement delta reporting --- .github/workflows/pr-manipulation.yml | 24 ++--- .github/workflows/test.yml | 126 ++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 21 deletions(-) diff --git a/.github/workflows/pr-manipulation.yml b/.github/workflows/pr-manipulation.yml index a50e5fce..1ba44bf7 100644 --- a/.github/workflows/pr-manipulation.yml +++ b/.github/workflows/pr-manipulation.yml @@ -17,24 +17,23 @@ jobs: 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 }}, + const fs = require('fs'); + const artifacts = await github.actions.listWorkflowRunArtifacts({ + ...context.repo, + run_id: ${{github.event.workflow_run.id }}, }); - var matchArtifact = artifacts.data.artifacts.filter((artifact) => { + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "pr" })[0]; - var download = await github.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', + const download = await github.actions.downloadArtifact({ + ...context.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', }); - var fs = require('fs'); + fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data)); - run: unzip pr.zip - + - name: 'Comment on PR' uses: actions/github-script@v3 with: @@ -43,6 +42,7 @@ jobs: const fs = require('fs'); const issueNumber = Number(fs.readFileSync('./NR')); const summaryContent = fs.readFileSync('./step_summary.md', 'utf-8'); + const existingCommentsOpts = github.issues.listComments.endpoint.merge({ ...context.repo, issue_number: issueNumber }); diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 351ff380..f45dab18 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -116,7 +116,7 @@ jobs: node-version: "20" - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: brotli pv parallel + packages: brotli pv parallel jq version: 1.0 - name: Build bundle @@ -124,16 +124,124 @@ jobs: - name: Size Reporting run: | ls pkg/*/*.wasm | parallel brotli -f -Z {} - echo "| Asset | Size | Compressed Size |" >> $GITHUB_STEP_SUMMARY - echo "| ------ | ---- | --------------- |" >> $GITHUB_STEP_SUMMARY - for asset in $(ls pkg/*/*.wasm); do - SIZE=$(cat $asset | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') - COMPRESSED_SIZE=$(cat "${asset}.br" | pv -f -b 2>&1 >/dev/null | tr -d '\n\r') - echo "| ${asset} | $SIZE | $COMPRESSED_SIZE |" >> $GITHUB_STEP_SUMMARY - done; mkdir -p ./pr + echo "| Asset | Size | Compressed Size |" >> ./pr/step_summary.md + echo "| ------ | ---- | --------------- |" >> ./pr/step_summary.md + for asset in $(ls pkg/*/*.wasm); do + export SIZE=$(stat --format '%s' $asset) + export COMPRESSED_SIZE=$(stat --format '%s' "${asset}.br") + export asset + echo "| ${asset} | $(echo $SIZE | numfmt --to=si --suffix="B") | $(echo $COMPRESSED_SIZE | numfmt --to=si --suffix="B") |" >> ./pr/step_summary.md + echo $(jq -n '{"asset": $ENV.asset, "size": $ENV.SIZE | tonumber, "compressed_size": $ENV.COMPRESSED_SIZE | tonumber}') + done | jq -s 'map({ (.asset|tostring): .}) | add' > ./pr/asset_manifest.json echo ${{ github.event.number }} > ./pr/NR - cp $GITHUB_STEP_SUMMARY ./pr/step_summary.md + if [[ "${{ github.event_type }}" != "pull_request" ]]; then + cat ./pr/step_summary.md > $GITHUB_STEP_SUMMARY + fi; + - uses: actions/upload-artifact@v2 + with: + name: pr + path: pr/ + delta_generation: + runs-on: ubuntu-latest + if: > + github.event_name == 'pull_request' + needs: node-build-report + steps: + - uses: actions/download-artifact@v2 + with: + name: pr + path: pr/ + - name: 'Download artifact' + uses: actions/github-script@v7 + with: + script: | + const fs = require('fs'); + const { execSync } = require('child_process'); + const baseContext = { + repo: { + repo: '${{ github.event.pull_request.base.repo.name }}', + owner: '${{ github.event.pull_request.base.repo.owner.login }}' + } + }; + const baseWorkflows = await github.rest.actions.listWorkflowRuns({ + ...baseContext.repo, + branch: '${{ github.event.pull_request.base.ref }}', + status: 'success', + workflow_id: 'test.yml', + }); + const matchWorkflow = baseWorkflows.data?.workflow_runs?.[0]; + const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ + ...baseContext.repo, + run_id: matchWorkflow?.id, + }); + const matchArtifact = artifacts.data.artifacts.filter((artifact) => { + return artifact.name == "pr" + })[0]; + const download = await github.rest.actions.downloadArtifact({ + ...baseContext.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + + fs.writeFileSync('${{github.workspace}}/base.zip', Buffer.from(download.data)); + execSync(`unzip -p base.zip asset_manifest.json >base_asset_manifest.json || true`); + // now, read in the asset manifests, for the head and base + let baseAssets = {}; + try { + baseAssets = JSON.parse(fs.readFileSync('./base_asset_manifest.json')); + } catch (error) { + console.log('No base asset manifest found'); + } + const assets = JSON.parse(fs.readFileSync('./pr/asset_manifest.json')); + const unitOptions = { + style: 'unit', unit: 'byte', unitDisplay: 'narrow', notation: 'compact', + maximumSignificantDigits: 3 + }; + const formatter = new Intl.NumberFormat('en-US', unitOptions); + const signedFormatter = new Intl.NumberFormat('en-US', { ...unitOptions, signDisplay: 'always' }); + const percentFormatter = Intl.NumberFormat('en-US', { style: 'percent', signDisplay: 'always' }); + const colorMap = { + '-1': 'green', + 1: 'red', + 0: 'black', + NaN: 'black' + }; + // compute deltas and output markdown fragments + const lineFragments = Object.entries(assets).map(([k, v]) => { + const baseAsset = baseAssets[k] ?? {}; + const { asset, size, compressed_size, size_delta, compressed_size_delta } = { + ...v, + ...Object.fromEntries(['size', 'compressed_size'].map(subK => { + // compute the percentage change, NaN if the asset wasn't available + const proportionalDelta = 1 - v?.[subK] / baseAsset?.[subK]; + const absoluteDelta = baseAsset?.[subK] - v?.[subK] + const sign = Math.sign(proportionalDelta); + // conditionally color the output via an inline latex block + let fragment = ''; + if(Number.isFinite(proportionalDelta)) { + fragment = `${signedFormatter.format(absoluteDelta)} ${percentFormatter.format(proportionalDelta)}`; + } else { + fragment = 'N/A'; + } + if(!Number.isFinite(proportionalDelta) || sign === 0) { + return [`${subK}_delta`, fragment] + } else { + const formattedFragment = `$\\color{${colorMap[sign]}}\\text{${fragment.replace('%', '\\%')}}$`; + return [`${subK}_delta`, formattedFragment] + } + })) + }; + // output a markdown fragment + const sizeFragment = `${formatter.format(size)} ${size_delta}` + const compressedFragment = `${formatter.format(compressed_size)} ${compressed_size_delta}` + return [asset, sizeFragment, compressedFragment] + }); + await core.summary.addHeading('Asset Sizes').addTable([ + [{data: 'Asset', header: true}, {data: 'Uncompressed Size', header: true}, {data: 'Compressed Size', header: true}], + ...lineFragments + ]).write(); + fs.cpSync(process.env.GITHUB_STEP_SUMMARY, './pr/step_summary.md') - uses: actions/upload-artifact@v2 with: name: pr From 487c4a8cec55e14d3d942cb0267c8fe200fe00ce Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 20:39:40 +1100 Subject: [PATCH 16/18] Switch to report_build.sh for size reporting purposes --- .github/workflows/test.yml | 6 +++--- scripts/report_build.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 scripts/report_build.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f45dab18..2cd116f5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -120,14 +120,14 @@ jobs: version: 1.0 - name: Build bundle - run: yarn build + run: ./scripts/report_build.sh - name: Size Reporting run: | - ls pkg/*/*.wasm | parallel brotli -f -Z {} + ls report_pkg/*/*.wasm | parallel brotli -f -Z {} mkdir -p ./pr echo "| Asset | Size | Compressed Size |" >> ./pr/step_summary.md echo "| ------ | ---- | --------------- |" >> ./pr/step_summary.md - for asset in $(ls pkg/*/*.wasm); do + for asset in $(ls report_pkg/*/*.wasm); do export SIZE=$(stat --format '%s' $asset) export COMPRESSED_SIZE=$(stat --format '%s' "${asset}.br") export asset diff --git a/scripts/report_build.sh b/scripts/report_build.sh new file mode 100755 index 00000000..618893ba --- /dev/null +++ b/scripts/report_build.sh @@ -0,0 +1,30 @@ +rm -rf report_pkg +mkdir -p report_pkg + +echo "Building arrow-rs slim" +wasm-pack build \ + --release \ + --no-pack \ + --out-dir report_pkg/slim \ + --out-name arrow1 \ + --target web \ + --features=arrow1 & +echo "Building arrow-rs sync" +wasm-pack build \ + --release \ + --no-pack \ + --out-dir report_pkg/sync \ + --out-name arrow1 \ + --target web \ + --features={arrow1,reader,writer,all_compressions} & + +echo "Building arrow-rs async_full" +wasm-pack build \ + --release \ + --no-pack \ + --out-dir report_pkg/async_full \ + --out-name arrow1 \ + --target web \ + --features={arrow1,reader,writer,all_compressions,async} & + +wait; \ No newline at end of file From 642313ceb3b38f615b2330cac6901458ba6021bb Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 20:50:22 +1100 Subject: [PATCH 17/18] Account for non-existent pr artifact in base --- .github/workflows/test.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2cd116f5..00539328 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -105,6 +105,8 @@ jobs: - name: Install Rust uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown - name: Install run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh @@ -138,7 +140,7 @@ jobs: if [[ "${{ github.event_type }}" != "pull_request" ]]; then cat ./pr/step_summary.md > $GITHUB_STEP_SUMMARY fi; - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: pr path: pr/ @@ -148,7 +150,7 @@ jobs: github.event_name == 'pull_request' needs: node-build-report steps: - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: pr path: pr/ @@ -178,14 +180,16 @@ jobs: const matchArtifact = artifacts.data.artifacts.filter((artifact) => { return artifact.name == "pr" })[0]; - const download = await github.rest.actions.downloadArtifact({ - ...baseContext.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - - fs.writeFileSync('${{github.workspace}}/base.zip', Buffer.from(download.data)); - execSync(`unzip -p base.zip asset_manifest.json >base_asset_manifest.json || true`); + if(matchArtifact) { + const download = await github.rest.actions.downloadArtifact({ + ...baseContext.repo, + artifact_id: matchArtifact.id, + archive_format: 'zip', + }); + + fs.writeFileSync('${{github.workspace}}/base.zip', Buffer.from(download.data)); + execSync(`unzip -p base.zip asset_manifest.json >base_asset_manifest.json || true`); + } // now, read in the asset manifests, for the head and base let baseAssets = {}; try { @@ -242,7 +246,7 @@ jobs: ...lineFragments ]).write(); fs.cpSync(process.env.GITHUB_STEP_SUMMARY, './pr/step_summary.md') - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: pr path: pr/ \ No newline at end of file From 770a0a74dfb2310d95c709e1815a3663dbd4e14b Mon Sep 17 00:00:00 2001 From: Nicholas Roberts Date: Mon, 4 Dec 2023 21:05:27 +1100 Subject: [PATCH 18/18] Fix reversed deltas, strip report_pkg prefix in deltas --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 00539328..751c1a11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -154,7 +154,7 @@ jobs: with: name: pr path: pr/ - - name: 'Download artifact' + - name: 'Generate size deltas' uses: actions/github-script@v7 with: script: | @@ -218,8 +218,8 @@ jobs: ...v, ...Object.fromEntries(['size', 'compressed_size'].map(subK => { // compute the percentage change, NaN if the asset wasn't available - const proportionalDelta = 1 - v?.[subK] / baseAsset?.[subK]; - const absoluteDelta = baseAsset?.[subK] - v?.[subK] + const proportionalDelta = v?.[subK] / baseAsset?.[subK] - 1; + const absoluteDelta = v?.[subK] - baseAsset?.[subK] const sign = Math.sign(proportionalDelta); // conditionally color the output via an inline latex block let fragment = ''; @@ -239,7 +239,7 @@ jobs: // output a markdown fragment const sizeFragment = `${formatter.format(size)} ${size_delta}` const compressedFragment = `${formatter.format(compressed_size)} ${compressed_size_delta}` - return [asset, sizeFragment, compressedFragment] + return [asset.replace('report_pkg/', ''), sizeFragment, compressedFragment] }); await core.summary.addHeading('Asset Sizes').addTable([ [{data: 'Asset', header: true}, {data: 'Uncompressed Size', header: true}, {data: 'Compressed Size', header: true}],