-
Notifications
You must be signed in to change notification settings - Fork 438
199 lines (170 loc) · 6.9 KB
/
testmerge.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
name: 'Testmerge Worker'
concurrency:
group: testmerge
on:
workflow_dispatch:
inputs:
apply_to_stable:
description: 'Apply testmerge to stable branch'
type: boolean
required: true
default: false
env:
BASE_BRANCH: master220
TESTMERGE_BRANCH: testmerge
STABLE_BRANCH: stable
REQUIRED_LABEL: testmerge
jobs:
process:
runs-on: ubuntu-latest
steps:
- name: Get pull requests with required label and check for merge conflicts
id: get_labeled_prs
uses: actions/github-script@v7
with:
script: |
const label_needed = '${{ env.REQUIRED_LABEL }}';
const { data: pullRequests } = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
per_page: 100
});
const labeledPRs = [];
const sortedPRsASC = pullRequests.sort((a, b) => a.created_at.localeCompare(b.created_at));
for (const pr of sortedPRsASC) {
if (pr.labels.some(label => label.name === label_needed)) {
console.log(`PR ${pr.title}`);
const { data: prInfo } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
if (prInfo.mergeable) {
labeledPRs.push({
number: pr.number,
title: pr.title,
sha: pr.head.sha
});
}
}
}
const prDetails = JSON.stringify(labeledPRs);
console.log(`Pull Requests with the label "${label_needed}" and no merge conflicts:\n${prDetails}`);
if (prDetails.length == 0) {
core.setFailed(`No pull requests with the label "${label_needed}" and no merge conflicts found.`);
}
core.setOutput('labeled_pr_details', prDetails);
- name: Git checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
ref: ${{ env.BASE_BRANCH }}
- uses: actions/setup-python@v5
with:
python-version: '3.11.6'
cache: 'pip'
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
cache-dependency-path: ./tgui/yarn.lock
- name: Install python packages
run: |
pip3 install -r tools/requirements.txt
pip3 install GitPython
- name: Iterate over PRs and perform actions
id: prepare_testmerge_branch
run: |
set -e
# Define the color functions
red() {
echo -e "\033[31m$1\033[0m"
}
green() {
echo -e "\033[32m$1\033[0m"
}
yellow() {
echo -e "\033[33m$1\033[0m"
}
git config --local user.email "[email protected]"
git config --local user.name "Testmerge Worker"
git switch ${{ env.TESTMERGE_BRANCH }} || git switch -c ${{ env.TESTMERGE_BRANCH }}
git reset --hard ${{ env.BASE_BRANCH }}
./tools/hooks/install.sh
./tgui/bin/tgui --install-git-hooks
MERGED_PRS=()
# Print debug information
echo "PR details JSON:"
echo '${{ steps.get_labeled_prs.outputs.labeled_pr_details }}'
while read -r PR_DETAIL; do
PR_NUMBER=$(echo "$PR_DETAIL" | jq -r '.number')
PR_TITLE=$(echo "$PR_DETAIL" | jq -r '.title')
PR_LAST_COMMIT=$(echo "$PR_DETAIL" | jq -r '.sha' | head -c 7)
PR_STRING="$PR_TITLE (#$PR_NUMBER) [$PR_LAST_COMMIT]"
echo "::group::$PR_STRING"
git fetch origin pull/$PR_NUMBER/head:pr-$PR_NUMBER
echo "Preparing..."
# Check for merge conflicts
git merge --no-commit --no-ff pr-$PR_NUMBER || true
CONFLICTS=$(git ls-files -u | wc -l)
if [ "$CONFLICTS" -gt 0 ] ; then
echo "::endgroup::"
echo "$(red "$PR_STRING: There is a merge conflict. Skipping!")"
git merge --abort
continue
fi
git merge --abort
git merge --squash pr-$PR_NUMBER
git commit -m "$PR_TITLE (#$PR_NUMBER) [testmerge][$PR_LAST_COMMIT]"
# Perform your git actions here, for example:
echo "::endgroup::"
echo "$(green "$PR_STRING: Successfully merged!")"
MERGED_PRS+=("$PR_NUMBER")
done < <(echo '${{ steps.get_labeled_prs.outputs.labeled_pr_details }}' | jq -c '.[]')
# Generate changelog
python3 tools/changelog/gen_changelog.py
git add html/changelogs/archive/\*.yml
CHANGES=$(git diff --name-only --cached | wc -l)
if [ "$CHANGES" -gt 0 ] ; then
git config --local user.email "[email protected]"
git config --local user.name "Changelog Generation"
git commit -m "Automatic changelog generation"
fi
# Generate TGUI bundle
./tgui/bin/tgui
CHANGES=$(git diff | wc -l)
if [ "$CHANGES" -gt 0 ] ; then
git config --local user.email "[email protected]"
git config --local user.name "TGUI bundle Generation"
git commit -am "Testmerge TGUI bundle build generation"
fi
git push -f origin ${{ env.TESTMERGE_BRANCH }}
if [ ${{ inputs.apply_to_stable }} ] ; then
git fetch origin ${{ env.STABLE_BRANCH }}
git push -f --set-upstream origin ${{ env.STABLE_BRANCH }}
fi
# Output the list of merged PRs
echo "${MERGED_PRS[@]}"
echo "merged_prs=${MERGED_PRS[@]}" >> $GITHUB_OUTPUT
echo "END"
#- name: Comment on merged PRs
# uses: actions/github-script@v7
# with:
# github-token: ${{secrets.GITHUB_TOKEN}}
# script: |
# console.log('${{ steps.prepare_testmerge_branch.outputs.merged_prs }}')
# const mergedPRs = '${{ steps.prepare_testmerge_branch.outputs.merged_prs }}'.split(' ');
# console.log(mergedPRs);
# for (const prNumber of mergedPRs) {
# await github.rest.issues.createComment({
# owner: context.repo.owner,
# repo: context.repo.repo,
# issue_number: parseInt(prNumber),
# body: 'Данный PR был добавлен в ветку "${{ env.TESTMERGE_BRANCH }}" для тестов. Он попадёт на сервер после деплоя.'
# });
# console.log(`Commented on PR #${prNumber}`);
# }