87 lines
2.9 KiB
YAML
87 lines
2.9 KiB
YAML
name: pr-size-test-result
|
|
|
|
on:
|
|
workflow_run:
|
|
workflows: [ios-ci]
|
|
types:
|
|
- completed
|
|
|
|
jobs:
|
|
comment-on-pr:
|
|
runs-on: ubuntu-22.04
|
|
steps:
|
|
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_run
|
|
# TODO: de-duplicate with re-usable action
|
|
- name: 'Download size-test-result artifact'
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
run_id: context.payload.workflow_run.id,
|
|
});
|
|
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
|
|
return artifact.name == "size-test-result"
|
|
})[0];
|
|
let download = await github.rest.actions.downloadArtifact({
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
artifact_id: matchArtifact.id,
|
|
archive_format: 'zip',
|
|
});
|
|
let fs = require('fs');
|
|
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/size-test-result.zip`, Buffer.from(download.data));
|
|
|
|
- name: 'Unzip render-test-result artifact'
|
|
run: unzip size-test-result.zip
|
|
|
|
- name: Show directory structure
|
|
run: ls -R
|
|
|
|
# Move ./size artifact to ./size_main and store as cache
|
|
|
|
- run: mv size size_main
|
|
if: github.event.workflow_run.event != 'pull_request'
|
|
|
|
- name: Save size
|
|
if: github.event.workflow_run.event != 'pull_request'
|
|
uses: actions/cache/save@v3
|
|
with:
|
|
path: |
|
|
size_main
|
|
key: ios-size
|
|
|
|
# Restore cache so we can output the difference
|
|
|
|
- name: Restore size
|
|
if: github.event.workflow_run.event == 'pull_request'
|
|
uses: actions/cache/restore@v3
|
|
with:
|
|
path: |
|
|
size_main
|
|
key: ios-size
|
|
|
|
- run: |
|
|
echo pr_number="$(cat ./pr_number)" >> "$GITHUB_ENV"
|
|
echo old_size="$(cat ./size_main)" >> "$GITHUB_ENV"
|
|
echo new_size="$(cat ./size)" >> "$GITHUB_ENV"
|
|
echo percentage_change=$(awk 'NR==FNR{a=$0;next}{printf "%+.2f%%\n", 100*($0-a)/a}' ./size ./size_main) >> "$GITHUB_ENV"
|
|
if: github.event.workflow_run.event == 'pull_request'
|
|
|
|
- name: 'Leave comment on PR with test results'
|
|
if: github.event.workflow_run.event == 'pull_request'
|
|
uses: marocchino/sticky-pull-request-comment@v2
|
|
with:
|
|
header: size-test-result
|
|
number: ${{ env.pr_number }}
|
|
hide_and_recreate: true
|
|
hide_classify: "OUTDATED"
|
|
message: |
|
|
### Size test result
|
|
|
|
Old size: ${{ env.old_size }} bytes
|
|
New size: ${{ env.new_size }} bytes
|
|
Difference: **${{ env.percentage_change }}**
|
|
|