-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·253 lines (220 loc) · 6.04 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·253 lines (220 loc) · 6.04 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
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
#!/bin/bash
# Copyright © Michal Čihař <michal@weblate.org>
#
# SPDX-License-Identifier: CC0-1.0
set -u -e
SYNC_BRANCH="weblate-meta-sync"
SYNC_COMMIT_MESSAGE="chore: sync with WeblateOrg/meta"
SYNC_PR_TITLE="$SYNC_COMMIT_MESSAGE"
SYNC_PR_BODY="Automated sync with WeblateOrg/meta."
REPOS="
customize-example
wlc
scripts
weblate
website
weblate_schemas
translation-finder
munin
fail2ban
docker
docker-base
docker-dev
docker-compose
hosted wllegal
language-data
graphics
helm
fonts
siphashc
openshift
kotlin-sdk
unicode-segmentation-rs
.github
"
# Copy the files to all repos if not present, these are expected to diverge
INITFILES="
.pre-commit-config.yaml
.github/renovate.json
"
# Copy these files unconditionally
COPYFILES="
.github/workflows/pre-commit.yml
.github/actions/pre-commit-setup/action.yml
.github/workflows/pull_requests.yaml
.github/workflows/dependency-review.yml
.github/FUNDING.yml
.yamllint.yml
.editorconfig
SECURITY.md
.github/PULL_REQUEST_TEMPLATE.md
.github/ISSUE_TEMPLATE/bug_report.yml
.github/ISSUE_TEMPLATE/feature_request.yml
"
# Automated comments
COMMENTFILES="
.github/comments/issue-fixed.md
.github/comments/issue-resolved.md
.github/comments/issue-newbie.md
"
# Update these files if present
PRESENTFILES="
.github/workflows/closing.yml
.github/workflows/stale.yml
.github/workflows/labels.yml
.github/matchers/sphinx-linkcheck.json
.github/matchers/sphinx-linkcheck-warn.json
.github/matchers/sphinx.json
.github/matchers/mypy.json
.github/release.yml
.eslintrc.yml
.stylelintrc
$COMMENTFILES
"
# Files to remove
REMOVEFILES="
.markdownlint.yml
.markdownlint.json
.github/stale.yml
.github/matchers/flake8.json
.github/matchers/eslint-compact.json
.github/matchers/flake8.json.license
.github/matchers/eslint-compact.json.license
.github/workflows/flake8.yml
.github/ISSUE_TEMPLATE/bug_report.md
.github/ISSUE_TEMPLATE/feature_request.md
.github/ISSUE_TEMPLATE/support_question.md
.github/ISSUE_TEMPLATE/support_question.yml
.github/.kodiak.toml
.github/workflows/ruff.yml
.github/workflows/eslint.yml
.github/workflows/stylelint.yml
.github/workflows/codeql-analysis.yml
.eslintrc.yml
.github/labels.yml
.github/workflows/label-sync.yml
"
if [ ! -f .venv/bin/activate ]; then
echo "Missing virtualenv in .venv!"
exit 1
fi
# shellcheck disable=SC1091
. .venv/bin/activate
export ROOT="$PWD"
mkdir -p repos
cd repos
copyfile() {
file=$1
repo=$2
dir=$(dirname "$file")
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
fi
if [ -f "../../${file%.*}.$repo.${file##*.}" ]; then
cp "../../${file%.*}.$repo.${file##*.}" "$file"
elif [ -f "../../$file.$repo" ]; then
cp "../../$file.$repo" "$file"
else
cp "../../$file" "$file"
fi
if [ -f "../../$file.license" ]; then
cp "../../$file.license" "$file.license"
elif [ -f "$file.license" ]; then
rm "$file.license"
fi
}
default_branch() {
local branch
if ! branch=$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD); then
echo "Could not determine default branch for $(basename "$PWD")" >&2
exit 1
fi
echo "${branch#origin/}"
}
sync_pr_url() {
gh pr list --head "$SYNC_BRANCH" --state open --json url --jq '.[0].url // ""'
}
push_sync_pr() {
local default_branch
local pr_url
default_branch=$1
git push --force-with-lease origin "$SYNC_BRANCH"
pr_url=$(sync_pr_url)
if [ -z "$pr_url" ]; then
gh pr create --base "$default_branch" --head "$SYNC_BRANCH" --title "$SYNC_PR_TITLE" --body "$SYNC_PR_BODY"
pr_url=$(sync_pr_url)
else
echo "Updating existing pull request: $pr_url"
fi
if [ -z "$pr_url" ]; then
echo "Could not find sync pull request for $(basename "$PWD")" >&2
exit 1
fi
gh pr merge "$pr_url" --auto --rebase
}
for repo in $REPOS; do
if [ ! -d "$repo" ]; then
git clone "git@github.com:WeblateOrg/$repo.git"
fi
cd "$repo"
git fetch --quiet --prune origin
DEFAULT_BRANCH=$(default_branch)
git reset --quiet --hard
git checkout --quiet -B "$DEFAULT_BRANCH" "origin/$DEFAULT_BRANCH"
git checkout --quiet -B "$SYNC_BRANCH" "$DEFAULT_BRANCH"
echo "== $repo =="
# Check README
if ! grep -q Logo-Darktext-borders.png README.* 2> /dev/null; then
echo "WARNING: README does not containing logo."
fi
# Markdownling migration
if [ -f .rumdl.toml ]; then
if ! grep -q rumdl .pre-commit-config.yaml; then
git rm .rumdl.toml
elif [ -f pyproject.toml ]; then
cat .rumdl.toml | grep -v '^#' | sed -e 's/^\[/[tool.rumdl./' -e s/tool.rumdl.global/tool.rumdl/ >> pyproject.toml
git rm .rumdl.toml
fi
fi
# Update files
mkdir -p .github/workflows/
for file in $INITFILES; do
if [ ! -f "$file" ]; then
copyfile "$file" "$repo"
fi
done
for file in $COPYFILES; do
copyfile "$file" "$repo"
done
for file in $PRESENTFILES; do
if [ -f "$file" ]; then
copyfile "$file" "$repo"
fi
done
for file in $REMOVEFILES; do
if [ -f "$file" ]; then
rm "$file"
fi
done
if [ -f .github/workflows/closing.yml ] || [ -f .github/workflows/labels.yml ]; then
for file in $COMMENTFILES; do
copyfile "$file" "$repo"
done
fi
# Configure GitHub release notes generating
if grep -q generateReleaseNotes .github/workflows/*; then
copyfile ".github/release.yml" "$repo"
fi
# Apply fixes
"$ROOT/repo-fixups"
# Update issue templates
"$ROOT/update-issue-config" "$ROOT"
# Add and push pull request
git add .
if ! git diff --cached --exit-code; then
git commit -m "$SYNC_COMMIT_MESSAGE"
push_sync_pr "$DEFAULT_BRANCH"
fi
echo
cd ..
done