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...@@ -3,29 +3,29 @@ name: PR Size
3on:3on:
4 pull_request_target:4 pull_request_target:
5 types: [opened, reopened, synchronize, ready_for_review, converted_to_draft]5 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
7permissions:13permissions:
8 contents: read14 contents: read
9 issues: write
10 pull-requests: read
1115
12jobs:16jobs:
13 label:17 prepare-config:
14 name: Label PR size18 name: Prepare PR size config
15 runs-on: ubuntu-24.0419 runs-on: ubuntu-24.04
16 concurrency:20 outputs:
17 group: pr-size-${{ github.event.pull_request.number }}21 labels_json: ${{ steps.config.outputs.labels_json }}
18 cancel-in-progress: true
19 steps:22 steps:
20 - name: Sync PR size label23 - id: config
24 name: Build PR size label config
21 uses: actions/github-script@v725 uses: actions/github-script@v7
22 with:26 with:
27 result-encoding: string
23 script: |28 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
29 const managedLabels = [29 const managedLabels = [
30 {30 {
31 name: "size:XS",31 name: "size:XS",
...@@ -59,31 +59,23 @@ jobs:...@@ -59,31 +59,23 @@ jobs:
59 },59 },
60 ];60 ];
6161
62 const managedLabelNames = new Set(managedLabels.map((label) => label.name));62 core.setOutput("labels_json", JSON.stringify(managedLabels));
6363 sync-label-definitions:
64 const resolveSizeLabel = (totalChangedLines) => {64 name: Sync PR size label definitions
65 if (totalChangedLines < 10) {65 needs: prepare-config
66 return "size:XS";66 if: github.event_name != 'pull_request_target'
67 }67 runs-on: ubuntu-24.04
6868 permissions:
69 if (totalChangedLines < 30) {69 contents: read
70 return "size:S";70 issues: write
71 }71 steps:
7272 - name: Ensure PR size labels exist
73 if (totalChangedLines < 100) {73 uses: actions/github-script@v7
74 return "size:M";74 env:
75 }75 PR_SIZE_LABELS_JSON: ${{ needs.prepare-config.outputs.labels_json }}
7676 with:
77 if (totalChangedLines < 500) {77 script: |
78 return "size:L";78 const managedLabels = JSON.parse(process.env.PR_SIZE_LABELS_JSON ?? "[]");
79 }
80
81 if (totalChangedLines < 1000) {
82 return "size:XL";
83 }
84
85 return "size:XXL";
86 };
8779
88 for (const label of managedLabels) {80 for (const label of managedLabels) {
89 try {81 try {
...@@ -125,6 +117,56 @@ jobs:...@@ -125,6 +117,56 @@ jobs:
125 }117 }
126 }118 }
127 }119 }
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
129 const nextLabelName = resolveSizeLabel(changedLines);171 const nextLabelName = resolveSizeLabel(changedLines);
130172