authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-12 12:01:27-07:00
committergravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-12 12:01:27-07:00
logd9d0216e98062bb69c0b3f7cb67cd9a3c5742216
tree18b3b703a2c7eb59f82cb020e4c79d5222112a71
parentc52ad29b31e890164d0e22443f36c1e39483d3bc

fix pr size workflow


1 files changed, 80 insertions(+), 38 deletions(-)

.github/workflows/pr-size.yml+80-38
......@@ -3,29 +3,29 @@ name: PR Size
33on:
44 pull_request_target:
55 types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]
6 workflow_dispatch:
7 push:
8 branches:
9 - main
10 paths:
11 - .github/workflows/pr-size.yml
612
713permissions:
814 contents: read
9 issues: write
10 pull-requests: read
1115
1216jobs:
13 label:
14 name: Label PR size
17 prepare-config:
18 name: Prepare PR size config
1519 runs-on: ubuntu-24.04
16 concurrency:
17 group: pr-size-${{ github.event.pull_request.number }}
18 cancel-in-progress: true
20 outputs:
21 labels_json: ${{ steps.config.outputs.labels_json }}
1922 steps:
20 - name: Sync PR size label
23 - id: config
24 name: Build PR size label config
2125 uses: actions/github-script@v7
2226 with:
27 result-encoding: string
2328 script: |
24 const issueNumber = context.payload.pull_request.number;
25 const additions = context.payload.pull_request.additions ?? 0;
26 const deletions = context.payload.pull_request.deletions ?? 0;
27 const changedLines = additions + deletions;
28
2929 const managedLabels = [
3030 {
3131 name: "size:XS",
......@@ -59,31 +59,23 @@ jobs:
5959 },
6060 ];
6161
62 const managedLabelNames = new Set(managedLabels.map((label) => label.name));
63
64 const resolveSizeLabel = (totalChangedLines) => {
65 if (totalChangedLines < 10) {
66 return "size:XS";
67 }
68
69 if (totalChangedLines < 30) {
70 return "size:S";
71 }
72
73 if (totalChangedLines < 100) {
74 return "size:M";
75 }
76
77 if (totalChangedLines < 500) {
78 return "size:L";
79 }
80
81 if (totalChangedLines < 1000) {
82 return "size:XL";
83 }
84
85 return "size:XXL";
86 };
62 core.setOutput("labels_json", JSON.stringify(managedLabels));
63 sync-label-definitions:
64 name: Sync PR size label definitions
65 needs: prepare-config
66 if: github.event_name != 'pull_request_target'
67 runs-on: ubuntu-24.04
68 permissions:
69 contents: read
70 issues: write
71 steps:
72 - name: Ensure PR size labels exist
73 uses: actions/github-script@v7
74 env:
75 PR_SIZE_LABELS_JSON: ${{ needs.prepare-config.outputs.labels_json }}
76 with:
77 script: |
78 const managedLabels = JSON.parse(process.env.PR_SIZE_LABELS_JSON ?? "[]");
8779
8880 for (const label of managedLabels) {
8981 try {
......@@ -125,6 +117,56 @@ jobs:
125117 }
126118 }
127119 }
120 label:
121 name: Label PR size
122 needs: prepare-config
123 if: github.event_name == 'pull_request_target'
124 runs-on: ubuntu-24.04
125 permissions:
126 contents: read
127 issues: read
128 pull-requests: write
129 concurrency:
130 group: pr-size-${{ github.event.pull_request.number }}
131 cancel-in-progress: true
132 steps:
133 - name: Sync PR size label
134 uses: actions/github-script@v7
135 env:
136 PR_SIZE_LABELS_JSON: ${{ needs.prepare-config.outputs.labels_json }}
137 with:
138 script: |
139 const issueNumber = context.payload.pull_request.number;
140 const additions = context.payload.pull_request.additions ?? 0;
141 const deletions = context.payload.pull_request.deletions ?? 0;
142 const changedLines = additions + deletions;
143 const managedLabels = JSON.parse(process.env.PR_SIZE_LABELS_JSON ?? "[]");
144
145 const managedLabelNames = new Set(managedLabels.map((label) => label.name));
146
147 const resolveSizeLabel = (totalChangedLines) => {
148 if (totalChangedLines < 10) {
149 return "size:XS";
150 }
151
152 if (totalChangedLines < 30) {
153 return "size:S";
154 }
155
156 if (totalChangedLines < 100) {
157 return "size:M";
158 }
159
160 if (totalChangedLines < 500) {
161 return "size:L";
162 }
163
164 if (totalChangedLines < 1000) {
165 return "size:XL";
166 }
167
168 return "size:XXL";
169 };
128170
129171 const nextLabelName = resolveSizeLabel(changedLines);
130172