2022-04-15 00:56:07 -05:00
|
|
|
name: Update Metadata
|
2022-04-13 02:46:57 -05:00
|
|
|
|
|
|
|
on:
|
2022-08-12 10:29:19 -05:00
|
|
|
# CAREFUL! https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
|
|
|
|
pull_request_target:
|
|
|
|
types: [opened, edited, synchronize, reopened]
|
2022-04-13 02:46:57 -05:00
|
|
|
|
2022-06-17 10:58:29 -05:00
|
|
|
concurrency:
|
2023-01-18 22:22:17 -05:00
|
|
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
2022-06-17 10:58:29 -05:00
|
|
|
cancel-in-progress: true
|
|
|
|
|
2022-04-13 02:46:57 -05:00
|
|
|
jobs:
|
2022-04-15 00:56:07 -05:00
|
|
|
update-metadata:
|
2022-04-13 02:46:57 -05:00
|
|
|
runs-on: ubuntu-latest
|
2022-07-20 04:29:07 -05:00
|
|
|
|
2022-04-13 02:46:57 -05:00
|
|
|
steps:
|
2022-04-15 00:56:07 -05:00
|
|
|
- name: Add labels
|
2022-09-03 03:17:08 -05:00
|
|
|
uses: silverhand-io/actions-add-labels-run-steps@v1.2.1
|
2022-04-13 02:46:57 -05:00
|
|
|
with:
|
|
|
|
title: ${{ github.event.pull_request.title || github.event.issue.title }}
|
|
|
|
github-token: ${{ github.token }}
|
|
|
|
|
2022-04-15 00:56:07 -05:00
|
|
|
- name: Add assignees
|
2022-07-20 09:52:37 -05:00
|
|
|
if: |
|
|
|
|
contains(fromJson('["opened", "reopened"]'), github.event.action) &&
|
|
|
|
!endsWith(github.event.pull_request.user.login, '[bot]')
|
2022-04-13 02:46:57 -05:00
|
|
|
uses: actions-ecosystem/action-add-assignees@v1
|
|
|
|
with:
|
|
|
|
github_token: ${{ github.token }}
|
2022-07-20 09:52:37 -05:00
|
|
|
assignees: ${{ github.event.pull_request.user.login }}
|
2022-05-09 11:08:05 -05:00
|
|
|
|
|
|
|
pr-size-diff:
|
|
|
|
runs-on: ubuntu-latest
|
2022-07-20 04:29:07 -05:00
|
|
|
|
2022-05-09 11:08:05 -05:00
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v3
|
|
|
|
with:
|
2022-08-14 09:19:34 -05:00
|
|
|
# https://github.com/actions/checkout/issues/518#issuecomment-890401887
|
|
|
|
ref: refs/pull/${{ github.event.number }}/merge
|
2022-05-09 11:08:05 -05:00
|
|
|
fetch-depth: 0
|
2022-08-12 10:29:19 -05:00
|
|
|
persist-credentials: false
|
2022-05-09 11:08:05 -05:00
|
|
|
|
|
|
|
- name: Prepare
|
|
|
|
run: |
|
|
|
|
git checkout master
|
|
|
|
git checkout -
|
2022-05-09 23:05:58 -05:00
|
|
|
curl -fsSLO https://gist.githubusercontent.com/gao-sun/88dac6c38e86f4ae12c8a7c3e777040a/raw/07276574142455b3dfeace5d7f4a370447a112b3/git-file-size-diff.sh
|
2022-05-09 11:08:05 -05:00
|
|
|
chmod +x git-file-size-diff.sh
|
|
|
|
|
|
|
|
- uses: actions/github-script@v6
|
|
|
|
id: message
|
|
|
|
with:
|
|
|
|
result-encoding: string
|
|
|
|
script: |
|
2022-05-09 23:05:58 -05:00
|
|
|
const child_process = require('child_process');
|
|
|
|
const result = child_process
|
|
|
|
.execSync('./git-file-size-diff.sh --cached master', { encoding: 'utf-8' })
|
|
|
|
.split('\n');
|
|
|
|
const diff = Number(result.pop());
|
2022-05-09 11:08:05 -05:00
|
|
|
|
|
|
|
// https://stackoverflow.com/a/18650828/12514940
|
|
|
|
function formatBytes(bytes, decimals = 2) {
|
|
|
|
if (bytes === 0) return '0 Bytes';
|
|
|
|
|
|
|
|
const k = 1024;
|
|
|
|
const dm = decimals < 0 ? 0 : decimals;
|
|
|
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPrefix(bytes) {
|
|
|
|
if (bytes === 0) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return diff > 0 ? ':chart_with_upwards_trend: +' : ':chart_with_downwards_trend: -';
|
|
|
|
}
|
|
|
|
|
2022-05-09 23:05:58 -05:00
|
|
|
function format(bytes) {
|
|
|
|
return `${
|
|
|
|
bytes > 1024 * 10 ? ':warning: ' : ''
|
|
|
|
}${
|
|
|
|
getPrefix(bytes)
|
|
|
|
}${formatBytes(Math.abs(bytes))}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
const filesHeader = `|Name|Diff|\n|---|---|\n`;
|
|
|
|
const filesData = result.map((row) => {
|
|
|
|
const [diff, filename] = row.split('\t');
|
2022-05-09 23:26:01 -05:00
|
|
|
return `|${filename}|${format(Number(diff))}|`;
|
|
|
|
}).join('\n');
|
2022-05-09 23:05:58 -05:00
|
|
|
|
2022-05-10 07:34:18 -05:00
|
|
|
return `#### COMPARE TO \`master\`\n**Total Size Diff** ${format(diff)}\n${
|
|
|
|
result.length ? `\n<details>\n<summary><b>Diff by File</b></summary>\n\n${filesHeader}${filesData}</details>\n` : ''
|
|
|
|
}`;
|
2022-05-09 11:08:05 -05:00
|
|
|
|
|
|
|
- uses: marocchino/sticky-pull-request-comment@v2
|
|
|
|
with:
|
|
|
|
message: |
|
|
|
|
${{ steps.message.outputs.result }}
|