-
Notifications
You must be signed in to change notification settings - Fork 37
170 lines (147 loc) · 6.06 KB
/
pr.yml
File metadata and controls
170 lines (147 loc) · 6.06 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: PR
on:
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
defaults:
run:
shell: bash -l {0}
jobs:
Build:
name: Build
permissions:
statuses: write
pull-requests: write
contents: write
uses: ./.github/workflows/_build.yml
secrets:
GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
Dependabot:
runs-on: ubuntu-24.04-16cores-public
permissions:
pull-requests: write
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
steps:
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Fetch Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@21025c705c08248db411dc16f3619e6b5f9ea21a # v2.5.0
with:
github-token: "${{ steps.app-token.outputs.token }}"
skip-commit-verification: true
- name: Add bpk label
if: contains(steps.dependabot-metadata.outputs.dependency-names, 'bpk-')
run: gh pr edit "$PR_URL" --add-label "bpk" --remove-label "javascript"
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
PR_URL: ${{github.event.pull_request.html_url}}
- name: Apply dependency labels
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
UPDATE_TYPE: ${{ steps.metadata.outputs.update-type }}
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const prNumber = context.issue.number;
const updateType = process.env.UPDATE_TYPE;
// Get current labels
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber
});
const currentLabelNames = currentLabels.map(label => label.name);
const conflictingLabels = ['major', 'minor', 'patch'];
// Remove conflicting labels if they exist
for (const conflictingLabel of conflictingLabels) {
if (currentLabelNames.includes(conflictingLabel)) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
name: conflictingLabel
});
console.log(`Removed conflicting label: ${conflictingLabel}`);
}
}
// Determine specific dependency label based on update type
let specificLabel = null;
switch (updateType) {
case 'version-update:semver-major':
case 'version-update:semver-premajor':
specificLabel = 'majorDependency';
break;
case 'version-update:semver-minor':
case 'version-update:semver-preminor':
specificLabel = 'minorDependency';
break;
case 'version-update:semver-patch':
case 'version-update:semver-prepatch':
specificLabel = 'patchDependency';
break;
default:
console.log(`Unknown update type: ${updateType}, will use dependencies only`);
}
const labelsToAdd = [];
// Add the dependencies label if it's not already present (required for CI)
if (!currentLabelNames.includes('dependencies')) {
labelsToAdd.push('dependencies');
}
// Add specific dependency label if determined and not already present
if (specificLabel && !currentLabelNames.includes(specificLabel)) {
labelsToAdd.push(specificLabel);
}
if (labelsToAdd.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: labelsToAdd
});
console.log(`Added labels: ${labelsToAdd.join(', ')}`);
} else {
console.log('All required labels already present');
}
CopilotAgent:
runs-on: ubuntu-24.04-16cores-public
permissions:
pull-requests: write
steps:
- uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: app-token
with:
app-id: ${{ vars.GH_APP_ID }}
private-key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- name: Detect Copilot commits and label PR
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const { data: commits } = await github.rest.pulls.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const isCopilot = commits.some(commit => {
const authorLogin = commit.author?.login || "";
const committerLogin = commit.committer?.login || "";
const message = commit.commit.message || "";
const hasAuthorCopilot = /copilot/i.test(authorLogin) ||
/copilot/i.test(committerLogin);
const hasCoAuthorCopilot = /co-authored-by:\s*.*copilot/i.test(message);
return hasAuthorCopilot || hasCoAuthorCopilot;
});
if (isCopilot) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['ai: copilot']
});
}