-
Notifications
You must be signed in to change notification settings - Fork 196
333 lines (302 loc) · 14.1 KB
/
lint-pr.yml
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
name: "Lint PR"
on:
pull_request:
types:
- opened
- edited
- synchronize
push:
branches:
- release/**
schedule:
- cron: "0 8 * * *"
permissions:
contents: read
actions: read
pull-requests: write
jobs:
pr-title:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
# Please look up the latest version from
# https://github.com/amannn/action-semantic-pull-request/releases
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v6
with:
script: |
const AZDO_TICKET_REGEX = 'https:\/\/(dev\.azure\.com\/msazure|msazure\.visualstudio\.com)\/Microsoft%20Teams%20Extensibility';
const AZDO_TICKET_REGEX_WXP = 'https:\/\/office\.visualstudio\.com\/OC';
const pullRequest = context.payload.pull_request;
if(pullRequest.title.startsWith("feat")) {
const body = pullRequest.body;
const match = body?.match(AZDO_TICKET_REGEX) || body?.match(AZDO_TICKET_REGEX_WXP);
if(!match) {
core.setFailed("Feat PR should contains AZDO tickets");
}
} else if(pullRequest.title.startsWith("fix")) {
const body = pullRequest.body;
const match = body?.match(AZDO_TICKET_REGEX) || body?.match(AZDO_TICKET_REGEX_WXP);
if(!match && !body) {
core.setFailed("Fix PR should contains AZDO tickets or descrptions");
}
}
check-format:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: setup project
uses: ./.github/actions/setup-project
- name: prettier check files in PR on Fork
if: ${{ github.event.pull_request.head.repo.full_name != 'OfficeDev/TeamsFx' }}
run: |
git remote add upstream https://github.com/OfficeDev/TeamsFx.git
git fetch upstream ${{ github.event.pull_request.base.ref }}
VAR=$(realpath .github/scripts/lint-pr.sh)
pnpm -r exec -- bash $VAR upstream/${{ github.event.pull_request.base.ref }}
- name: prettier check files in PR on local
if: ${{ github.event.pull_request.head.repo.full_name == 'OfficeDev/TeamsFx' }}
run: |
VAR=$(realpath .github/scripts/lint-pr.sh)
pnpm -r exec -- bash $VAR origin/${{ github.event.pull_request.base.ref }}
- name: Check if there are changes
id: changes
run: |
git add .
VAR=$(git diff --cached --name-only)
if [ ! -z "$VAR" ]
then
echo $VAR
echo '======================================= Prompt Information ==============================================='
echo 'There may be some unformatted files in your PR, please run these commands on Git Bash terminal: '
echo '1. npm run setup'
echo '2. VAR=$(realpath .github/scripts/lint-pr.sh) '
echo '3. pnpm -r exec -- bash $VAR ${your-PR-target-branch}'
echo 'please replace the ${your-PR-target-branch} as the target branch of your PR, such as origin/dev or upstream/dev'
exit 1
fi
- name: Check unused strings
working-directory: ./packages/fx-core
run: npm run checkUnusedStrings
shell: bash
env:
CI: true
check-yaml-lint:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Install Yaml lint and mustache
run: |
pip install yamllint
npm install mustache -g
echo "{}" > test.json
- name: check origin or remote
id: remote
run: |
if [ ${{ github.event.pull_request.head.repo.full_name == 'OfficeDev/TeamsFx' }} ]
then
echo "target=origin" >> $GITHUB_OUTPUT
else
echo "target=remote" >> $GITHUB_OUTPUT
fi
- name: check yaml lint origin
run: |
TRAGET=${{steps.remote.outputs.target}}/${{ github.event.pull_request.base.ref }}
YMLTPL=$(git diff --diff-filter=MARC $TRAGET...HEAD --name-only -- templates | grep -E '.yml.tpl$'|xargs)
echo $YMLTPL
if [ ! -z "$YMLTPL" ]
then
for obj in "$YMLTPL"
do
mustache test.json $obj | yamllint -d "{extends: relaxed, rules: {line-length: {max: 100}}}" -
done
fi
check-sensitive-content:
if: ${{ github.event_name == 'pull_request' || github.event_name == 'schedule' }}
runs-on: ubuntu-latest
steps:
- shell: bash
if: ${{ github.event_name == 'pull_request'}}
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "depth=$(($(jq length <<< '${{ toJson(github.event.commits) }}') + 1))" >> $GITHUB_ENV
echo "branch=${{ github.ref_name }}" >> $GITHUB_ENV
fi
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "depth=$((${{ github.event.pull_request.commits }} + 1))" >> $GITHUB_ENV
echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
fi
- uses: actions/checkout@v4
if: ${{ github.event_name == 'pull_request'}}
with:
ref: ${{env.branch}}
repository: ${{github.event.pull_request.head.repo.full_name}}
fetch-depth: ${{env.depth}}
- uses: trufflesecurity/trufflehog@main
if: ${{ github.event_name == 'pull_request'}}
with:
extra_args: --only-verified
- if: ${{ github.event_name == 'schedule' }}
uses: actions/checkout@v4
- if: ${{ github.event_name == 'schedule' }}
uses: trufflesecurity/trufflehog@main
with:
base: ""
head: ${{ github.ref_name }}
extra_args: --only-verified
attension-on-version:
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' && github.event.action != 'edited' }}
runs-on: ubuntu-latest
steps:
- name: checkout branch
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
ref: ${{ github.event.pull_request.head.ref }}
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v7
- name: check origin or remote
id: remote
run: |
if [ ${{ github.event.pull_request.head.repo.full_name == 'OfficeDev/TeamsFx' }} ]
then
echo "target=origin" >> $GITHUB_OUTPUT
else
echo "target=remote" >> $GITHUB_OUTPUT
fi
- name: check feature history
id: description
shell: "/bin/bash {0}"
run: |
head=${{steps.remote.outputs.target}}/${{ github.event.pull_request.base.ref }}
echo $head
history_cli_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/cli | grep "^feat")
echo $history_cli_feat
history_toolkit_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/vscode-extension | grep "^feat")
echo $history_toolkit_feat
history_core_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/fx-core | grep "^feat")
echo $history_core_feat
history_sdk_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/sdk | grep "^feat")
echo $history_sdk_feat
history_sdk_react_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/sdk-react | grep "^feat")
echo $history_sdk_react_feat
history_dotnet_sdk_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/dotnet-sdk | grep "^feat")
echo $history_dotnet_sdk_feat
echo -e '\nFx-core feat commits:\n' "$history_core_feat" '\n\nCLI feat commits:\n' "$history_cli_feat" '\n\nExtension-toolkit feat commits:\n' "$history_toolkit_feat" '\n\nSDK feat commits:\n' "$history_sdk_feat" '\n\nSDK React feat commits:\n' "$history_sdk_react_feat" '\n\n.Net SDK feat commits:\n' "$history_dotnet_sdk_feat" '\n'> feat_history.txt
history_cli_fix=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/cli | grep "^fix")
echo $history_cli_fix
history_toolkit_fix=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/vscode-extension | grep "^fix")
echo $history_toolkit_fix
history_core_fix=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/fx-core | grep "^fix")
echo $history_core_fix
history_sdk_fix=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/sdk | grep "^fix")
echo $history_sdk_fix
history_sdk_react_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/sdk-react | grep "^fix")
echo $history_sdk_react_fix
history_dotnet_sdk_feat=$(git log --pretty=format:"%s %h" $head...HEAD -- packages/dotnet-sdk | grep "^fix")
echo $history_dotnet_sdk_fix
echo -e '\nFx-core fix commits:\n' "$history_core_fix" '\n\nCLI fix commits:\n' "$history_cli_fix" '\n\nExtension-toolkit fix commits:\n' "$history_toolkit_fix" '\n\nSDK fix commits:\n' "$history_sdk_fix" '\n\nSDK React fix commits:\n' "$history_sdk_react_fix" '\n\n.Net SDK fix commits:\n' "$history_dotnet_sdk_fix" '\n'> fix_history.txt
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 14
- name: list history
if: ${{ github.event.pull_request.base.ref == 'main' }}
run: |
cat feat_history.txt > version_info.txt
cat fix_history.txt >> version_info.txt
- uses: JoseThen/[email protected]
with:
file_path: './version_info.txt'
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
create-cherry-pick-issue:
if: ${{ github.event_name == 'push' && !contains(github.event.pull_request.labels.*.name, 'cherry-pick-hotfix') }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
pull-requests: read
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get latest release branch
id: get-latest-release
run: |
# 找出版本号最大的 release 分支,分为两类:
# 1. release/NUM 或 release/NUM.NUM 格式
LATEST_NUM_RELEASE=$(git branch -r | grep -E '^ origin/release/[0-9]+(\.[0-9]+)?$' | sed 's/origin\///' | sort -t'/' -k2 -V | tail -n1)
# 2. release/VSNUMPNUM 格式
LATEST_VS_RELEASE=$(git branch -r | grep -E '^ origin/release/VS[0-9]+P[0-9]+$' | sed 's/origin\///' | sort -t'/' -k2 -V | tail -n1)
echo "latest_vsc_release=$LATEST_NUM_RELEASE" >> $GITHUB_OUTPUT
echo "latest_vs_release=$LATEST_VS_RELEASE" >> $GITHUB_OUTPUT
- name: Create Issue
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # Use a PAT with the required permissions
script: |
const currentTarget = context.payload.pull_request.base.ref;
const latestVSCRelease = '${{ steps.get-latest-release.outputs.latest_vsc_release }}';
const latestVSRelease = '${{ steps.get-latest-release.outputs.latest_vs_release }}';
const prNumber = context.payload.pull_request.number;
const prTitle = context.payload.pull_request.title;
const prAuthor = context.payload.pull_request.user.login;
let targetBranches = ['dev'];
if (latestVSCRelease && currentTarget !== latestVSCRelease) {
targetBranches.push(latestVSCRelease);
}
if (latestVSRelease && currentTarget !== latestVSRelease) {
targetBranches.push(latestVSRelease);
}
const branchList = targetBranches.map(branch => `- [ ] cherry-pick #${prNumber} to ${branch}`).join('\n');
const issueBody = `
### Cherry-pick Reminder
@${prAuthor} Hello!
This is an automatically created reminder. Your PR #${prNumber} (\`${prTitle}\`) is being merged into the \`${currentTarget}\` branch.
Please ensure to cherry-pick these changes to the following branches:
${branchList}
#### Steps to Follow:
1. Wait for the current PR to be merged.
2. Execute the following commands locally:
\`\`\`bash
git fetch origin
git checkout <target_branch>
git cherry-pick <commit_hash>
git push origin <target_branch>
\`\`\`
3. Or create a new PR to merge these changes into the above branches.
After completion, please check the items above ✓
> Note: This is an automatically created issue. You can close this issue after completing all the operations.
`;
try {
const issue = await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `[Cherry-pick] PR #${prNumber} needs to be synchronized to other branches`,
body: issueBody,
labels: ['cherry-pick-hotfix'],
assignees: [prAuthor] // Add PR author as assignee
});
console.log(`Created issue #${issue.data.number}`);
} catch (error) {
console.log('Error creating issue:', error);
core.setFailed(error.message);
}