-
Notifications
You must be signed in to change notification settings - Fork 31
133 lines (116 loc) · 5.42 KB
/
semver-label.yml
File metadata and controls
133 lines (116 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
name: Semver Label
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
semver_label:
runs-on: ubuntu-latest
steps:
- name: Checkout base branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
- name: Checkout PR merge result
uses: actions/checkout@v6
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
path: pr
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version-file: 'base/.nvmrc'
- name: Build base branch
run: |
echo "Base SHA: $(git -C base rev-parse HEAD)"
cd base
npm install
npm run build
- name: Build PR branch
run: |
echo "PR merge SHA: $(git -C pr rev-parse HEAD)"
cd pr
npm install
npm run build
- name: Create build diff
run: |
cp -r base/Sources/ContentScopeScripts/dist base/build/apple 2>/dev/null || true
cp -r pr/Sources/ContentScopeScripts/dist pr/build/apple 2>/dev/null || true
node base/.github/scripts/diff-directories.js base pr > /tmp/build_diff.txt
echo "Build diff size: $(wc -c < /tmp/build_diff.txt) bytes"
- name: Get PR source files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
gh pr view "$PR_NUMBER" --json files --jq '.files[].path' > /tmp/pr_files.txt 2>/dev/null || true
- name: Run semver analysis
id: analyse
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: |
export BUILD_DIFF="$(cat /tmp/build_diff.txt 2>/dev/null || echo '')"
export PR_FILES="$(cat /tmp/pr_files.txt 2>/dev/null || echo '')"
RESULT=$(node base/.github/scripts/semver-analysis.mjs)
echo "Raw result: $RESULT"
SEVERITY=$(echo "$RESULT" | jq -r '.severity')
echo "severity=$SEVERITY" >> "$GITHUB_OUTPUT"
- name: Label PR
if: steps.analyse.outputs.severity != ''
uses: actions/github-script@v8
env:
SEVERITY: ${{ steps.analyse.outputs.severity }}
with:
script: |
const prNumber = context.payload.pull_request.number;
const severity = process.env.SEVERITY;
const label = `semver-${severity}`;
const semverLabels = ['semver-major', 'semver-minor', 'semver-patch'];
const labelColors = { 'semver-major': 'B60205', 'semver-minor': 'FBCA04', 'semver-patch': '0E8A16' };
const labelDescriptions = {
'semver-major': 'Breaking change — triggers major version bump',
'semver-minor': 'New feature — triggers minor version bump',
'semver-patch': 'Bug fix / internal — no release needed'
};
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label
});
} catch {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label,
color: labelColors[label],
description: labelDescriptions[label]
});
}
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
for (const l of currentLabels) {
if (semverLabels.includes(l.name) && l.name !== label) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: l.name
});
}
}
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: [label]
});
console.log(`Applied label: ${label}`);