mirror of
https://github.com/Cute-Dress/Dress.git
synced 2026-04-17 14:22:33 +00:00
💚 改进工作流为无需审批的版本
This commit is contained in:
100
.github/workflows/check_file_size.yml
vendored
100
.github/workflows/check_file_size.yml
vendored
@@ -1,7 +1,7 @@
|
|||||||
name: Check File Size
|
name: Check File Size
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request_target:
|
||||||
types: [opened, synchronize, reopened]
|
types: [opened, synchronize, reopened]
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
@@ -13,71 +13,59 @@ jobs:
|
|||||||
check-size:
|
check-size:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
fetch-depth: 0
|
|
||||||
|
|
||||||
- name: Check file sizes
|
- name: Check file sizes
|
||||||
id: check_files
|
|
||||||
continue-on-error: true
|
|
||||||
run: |
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
BASE_SHA="${{ github.event.pull_request.base.sha }}"
|
|
||||||
HEAD_SHA="${{ github.sha }}"
|
|
||||||
MAX_SIZE=$((1024 * 1024)) # 1 MB
|
|
||||||
|
|
||||||
echo "Comparing changes between $BASE_SHA and $HEAD_SHA"
|
|
||||||
|
|
||||||
failed=0
|
|
||||||
files_over=()
|
|
||||||
|
|
||||||
while IFS= read -r -d '' file; do
|
|
||||||
if [ -f "$file" ]; then
|
|
||||||
size=$(wc -c < "$file")
|
|
||||||
if [ "$size" -gt "$MAX_SIZE" ]; then
|
|
||||||
echo "Error: $file ($size bytes)"
|
|
||||||
files_over+=("- $file ($size bytes)")
|
|
||||||
failed=1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done < <(
|
|
||||||
git diff --name-only -z --diff-filter=AMCR "$BASE_SHA" "$HEAD_SHA"
|
|
||||||
)
|
|
||||||
|
|
||||||
if [ "$failed" -eq 1 ]; then
|
|
||||||
{
|
|
||||||
echo "file_list<<EOF"
|
|
||||||
printf "%s\n" "${files_over[@]}"
|
|
||||||
echo "EOF"
|
|
||||||
} >> "$GITHUB_OUTPUT"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "All changed files are under 1 MB."
|
|
||||||
fi
|
|
||||||
|
|
||||||
- name: Comment on PR and add label if size check failed
|
|
||||||
if: steps.check_files.outcome == 'failure'
|
|
||||||
uses: actions/github-script@v7
|
uses: actions/github-script@v7
|
||||||
with:
|
with:
|
||||||
script: |
|
script: |
|
||||||
const fileList = `${{ steps.check_files.outputs.file_list }}`;
|
const MAX_SIZE = 1024 * 1024; // 1 MB
|
||||||
if (fileList) {
|
const prNumber = context.payload.pull_request.number;
|
||||||
|
const owner = context.repo.owner;
|
||||||
|
const repo = context.repo.repo;
|
||||||
|
|
||||||
|
let page = 1;
|
||||||
|
let oversized = [];
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
const response = await github.rest.pulls.listFiles({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
pull_number: prNumber,
|
||||||
|
per_page: 100,
|
||||||
|
page
|
||||||
|
});
|
||||||
|
|
||||||
|
const files = response.data;
|
||||||
|
if (files.length === 0) break;
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
// 只检查新增或修改文件
|
||||||
|
if (["added", "modified", "renamed", "copied"].includes(file.status)) {
|
||||||
|
if (file.size > MAX_SIZE) {
|
||||||
|
oversized.push(`- ${file.filename} (${file.size} bytes)`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files.length < 100) break;
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oversized.length > 0) {
|
||||||
const body = `
|
const body = `
|
||||||
我们注意到以下文件的大小超过了 1MB,请在压缩后再次提交 Pull Request:
|
我们注意到以下文件的大小超过了 1MB, 请在压缩后再次提交 Pull Request:
|
||||||
We have noted that the following files exceed 1MB in size. Please resubmit your pull request after compressing them:
|
We have noted that the following files exceed 1MB in size. Please resubmit your pull request after compressing them:
|
||||||
|
|
||||||
${fileList}
|
${oversized.join("\n")}
|
||||||
`.trim();
|
`.trim();
|
||||||
|
|
||||||
await github.rest.issues.createComment({
|
await github.rest.issues.createComment({
|
||||||
owner: context.repo.owner,
|
owner,
|
||||||
repo: context.repo.repo,
|
repo,
|
||||||
issue_number: context.issue.number,
|
issue_number: prNumber,
|
||||||
body: body
|
body
|
||||||
});
|
});
|
||||||
|
|
||||||
throw new Error('File size check failed');
|
core.setFailed("File size check failed");
|
||||||
|
} else {
|
||||||
|
core.info("All changed files are under 1 MB.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user