-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
301 lines (270 loc) · 11.6 KB
/
mirror.yml
File metadata and controls
301 lines (270 loc) · 11.6 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
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
name: "Index & mirror changed ports"
on:
push:
branches:
- master
paths-ignore:
- '.github/**'
permissions:
contents: read
jobs:
delete-cancelled-runs:
permissions:
actions: write
runs-on: 'ubuntu-latest'
if: github.repository_owner == 'macports'
steps:
- uses: 'MercuryTechnologies/delete-cancelled-runs@1.0.0'
with:
workflow-file: 'mirror.yml'
max-deletions: 10
build:
name: Index and mirror
concurrency:
group: mirror-${{ github.ref }}
runs-on: macos-latest
if: github.repository_owner == 'macports'
steps:
- name: Checkout ports
uses: actions/checkout@v6
with:
fetch-depth: 2
path: ports
show-progress: false
- name: Checkout mpbb
uses: actions/checkout@v6
with:
fetch-depth: 1
repository: macports/mpbb
ref: master
path: mpbb
show-progress: false
- name: Checkout contrib
uses: actions/checkout@v6
with:
fetch-depth: 1
repository: macports/macports-contrib
ref: master
path: contrib
show-progress: false
- name: Bootstrap MacPorts
env:
MP_CI_RELEASE: ${{ vars.MP_CI_RELEASE }}
run: |
. ports/.github/workflows/bootstrap.sh
# Add getopt, mpbb and the MacPorts paths to $PATH for the
# subsequent steps.
echo "/opt/mports/bin" >> $GITHUB_PATH
echo "/opt/local/bin" >> $GITHUB_PATH
echo "/opt/local/sbin" >> $GITHUB_PATH
- name: Determine list of changed ports
id: portlist
env:
MIRROR_DB_URL: ${{ secrets.MIRROR_DB_URL }}
MIRROR_DB_CREDENTIALS: ${{ secrets.MIRROR_DB_CREDENTIALS }}
run: |
set -eu
echo "Getting mirror.last_commit ..."
LAST_COMMIT="$(curl -sL -u "$MIRROR_DB_CREDENTIALS" "${MIRROR_DB_URL}GET/mirror.last_commit?type=txt")"
if [ -z "$LAST_COMMIT" ]; then
echo "No mirror.last_commit found, using default value."
LAST_COMMIT="$(git -C ports rev-parse HEAD~1)"
else
echo "$LAST_COMMIT" > last_commit
echo "Deepening macports-ports clone to $LAST_COMMIT"
DEPTH=2
while ! git -C ports merge-base --is-ancestor "$LAST_COMMIT" HEAD; do
if [ $DEPTH -gt 500 ]; then
echo "Didn't find commit with depth=$DEPTH - giving up"
LAST_COMMIT="HEAD~10"
rm -f last_commit
break
fi
DEPTH="$(( $DEPTH * 2 ))"
git -C ports fetch "--depth=$DEPTH" origin "$GITHUB_REF"
done
fi
echo "last_commit=$LAST_COMMIT" >> "$GITHUB_OUTPUT"
echo "Finding modified ports"
portlist=$( \
git -C ports/ diff --name-only --diff-filter=AM "${LAST_COMMIT}..HEAD" \
| grep -E '^[^._/][^/]*/[^/]+/(Portfile$|files/)' \
| cut -d/ -f2 \
| sort -u \
| tr '\n' ' ' \
| sed 's/ $//')
echo "$portlist"
echo "portlist=$portlist" >> "$GITHUB_OUTPUT"
- name: Restore cached PortIndex
id: restore-portindex
uses: actions/cache/restore@v5
with:
path: tarball
key: portindex-${{ runner.os }}-${{ steps.portlist.outputs.last_commit }}
- name: Prepare ports tree
id: prep-ports
env:
MIRROR_UPLOAD_URL: ${{ secrets.MIRROR_UPLOAD_URL }}
MIRROR_UPLOAD_CREDENTIALS: ${{ secrets.MIRROR_UPLOAD_CREDENTIALS }}
LAST_COMMIT: ${{ steps.portlist.outputs.last_commit }}
run: |
set -eu
CURRENT_COMMIT="$(git -C ports rev-parse HEAD)"
# rsync gotcha: openrsync's -C option behaves differently to
# samba.org rsync's, in particular not excluding .git.
if [ -n "$LAST_COMMIT" ]; then
if [ -e tarball/ports/.git_commit -a "$(cat tarball/ports/.git_commit)" = "$LAST_COMMIT" ]; then
echo "Cached tarball restored for commit $LAST_COMMIT"
else
rm -rf tarball
echo "Fetching tarball for commit $LAST_COMMIT"
if curl -fL -O -u "$MIRROR_UPLOAD_CREDENTIALS" "${MIRROR_UPLOAD_URL}portindex-${LAST_COMMIT}.tar.bz2"; then
mkdir -p tarball
BZIP2=/usr/bin/bzip2
if sudo port -b install --no-rev-upgrade lbzip2; then
if [ -x /opt/local/bin/lbzip2 ]; then
BZIP2=/opt/local/bin/lbzip2
fi
fi
tar -C tarball -xf "portindex-${LAST_COMMIT}.tar.bz2" \
--use-compress-program "$BZIP2"
rm -f "portindex-${LAST_COMMIT}.tar.bz2"
else
echo "Fetch failed, starting from scratch."
fi
fi
if [ -e tarball ]; then
git -C ports checkout "$LAST_COMMIT"
# Restore timestamps
rsync -rltC --exclude=".*" --existing tarball/ports/ ports
# Will update timestamps on only the files changed between LAST_COMMIT and CURRENT_COMMIT.
git -C ports checkout "$CURRENT_COMMIT"
fi
else
echo "No mirror.last_commit value found, starting from scratch."
rm -rf tarball
fi
mkdir -p tarball/ports
rsync -rltC --exclude=".git" --delete ports/ tarball/ports
echo "$CURRENT_COMMIT" > tarball/ports/.git_commit
# update PortIndex for current platform so port mirror can run
OS_MAJOR="$(uname -r | cut -f 1 -d .)"
OS_ARCH="$(uname -p)"
INDEXDIR="tarball/PortIndex_darwin_${OS_MAJOR}_${OS_ARCH}"
mkdir -p "$INDEXDIR"
platform_arg="macosx_${OS_MAJOR}_${OS_ARCH}"
if [ -f "mpbb/index_vars/${platform_arg}" ]; then
platform_arg="file:mpbb/index_vars/${platform_arg}"
fi
portindex -p "$platform_arg" -o "$INDEXDIR" ports
cp -c "${INDEXDIR}/PortIndex" "${INDEXDIR}/PortIndex.quick" ports
chmod -R a+rX ports
CUR_DIR="$(dirname "$(realpath ports)")"
while [ -n "$CUR_DIR" -a "$CUR_DIR" != "/" ]; do
sudo chmod a+rx "$CUR_DIR"
CUR_DIR="$(dirname "$CUR_DIR")"
done
echo "current_commit=$CURRENT_COMMIT" >> "$GITHUB_OUTPUT"
echo "os_major=$OS_MAJOR" >> "$GITHUB_OUTPUT"
echo "os_arch=$OS_ARCH" >> "$GITHUB_OUTPUT"
- name: Mirror all changed ports
env:
DISTFILES_URL: https://nue.de.distfiles.macports.org/
MIRROR_DB_URL: ${{ secrets.MIRROR_DB_URL }}
MIRROR_DB_CREDENTIALS: ${{ secrets.MIRROR_DB_CREDENTIALS }}
MIRROR_SSH_HOST: ${{ secrets.MIRROR_SSH_HOST }}
MIRROR_SSH_USER: ${{ secrets.MIRROR_SSH_USER }}
MIRROR_SSH_HOSTKEY: ${{ secrets.MIRROR_SSH_HOSTKEY }}
MIRROR_SSH_KEY: ${{ secrets.MIRROR_SSH_KEY }}
portlist: ${{ steps.portlist.outputs.portlist }}
run: |
set -eu
sudo mv /opt/local/var/macports .
sudo chown -R "$(id -un)" ./macports
sudo ln -s "$(realpath ./macports)" /opt/local/var/
echo "Mirroring ports: $portlist"
if ! port-tclsh mpbb/tools/mirror-multi.tcl -s -r "$MIRROR_DB_URL" "$MIRROR_DB_CREDENTIALS" -d "$DISTFILES_URL" $portlist; then
echo "Mirroring of some ports failed."
fi
echo "Making distfiles readable"
sudo chmod -R a+rX ./macports
touch ssh_key
chmod 0600 ssh_key
echo "$MIRROR_SSH_KEY" > ssh_key
echo "$MIRROR_SSH_HOSTKEY" > ssh_known_hosts
export RSYNC_RSH="ssh -l $MIRROR_SSH_USER -i ssh_key -oUserKnownHostsFile=ssh_known_hosts -p 23"
echo "Uploading distfiles"
rsync -av --ignore-existing --progress ./macports/distfiles/ "${MIRROR_SSH_HOST}:pub/distfiles"
rm -f ssh_key ssh_known_hosts
echo "Updating mirrored status of ports"
port-tclsh mpbb/tools/update-mirrordb.tcl "$MIRROR_DB_URL" "$MIRROR_DB_CREDENTIALS" mirror_done portfile_hash_cache portname_portfile_map
- name: Update PortIndex files
id: update-portindex
env:
OLDEST_DARWIN: 9
NEWEST_DARWIN: 25
CURRENT_COMMIT: ${{ steps.prep-ports.outputs.current_commit }}
OS_MAJOR: ${{ steps.prep-ports.outputs.os_major }}
OS_ARCH: ${{ steps.prep-ports.outputs.os_arch }}
run: |
set -eu
OS_MAJOR_LIST="$(seq "$OLDEST_DARWIN" "$NEWEST_DARWIN")"
for CUR_MAJOR in $OS_MAJOR_LIST; do
ARCHS="i386"
if [ "$CUR_MAJOR" -ge 20 ]; then
ARCHS="arm $ARCHS"
elif [ "$CUR_MAJOR" -le 9 ]; then
ARCHS="$ARCHS powerpc"
fi
for CUR_ARCH in $ARCHS; do
INDEXDIR="tarball/PortIndex_darwin_${CUR_MAJOR}_${CUR_ARCH}"
if [ "$CUR_MAJOR" -ne "$OS_MAJOR" -o "$CUR_ARCH" != "$OS_ARCH" ]; then
mkdir -p "$INDEXDIR"
platform_arg="macosx_${CUR_MAJOR}_${CUR_ARCH}"
if [ -f "mpbb/index_vars/${platform_arg}" ]; then
platform_arg="file:mpbb/index_vars/${platform_arg}"
fi
portindex -p "$platform_arg" -o "$INDEXDIR" ports
fi
port-tclsh contrib/portindex2json/portindex2json.tcl "${INDEXDIR}/PortIndex" --info commit="${CURRENT_COMMIT}" > "${INDEXDIR}/PortIndex.json"
done
done
find tarball -maxdepth 1 -type d -name 'PortIndex_darwin_*_*' -mtime +24h -exec rm -rfv {} \;
chmod -R a+rX tarball
- name: Deploy PortIndex
env:
MIRROR_UPLOAD_URL: ${{ secrets.MIRROR_UPLOAD_URL }}
MIRROR_UPLOAD_CREDENTIALS: ${{ secrets.MIRROR_UPLOAD_CREDENTIALS }}
CURRENT_COMMIT: ${{ steps.prep-ports.outputs.current_commit }}
run: |
set -eu
echo "Creating tarball for commit ${CURRENT_COMMIT}"
if [ -x /opt/local/bin/lbzip2 ]; then
BZIP2=/opt/local/bin/lbzip2
else
BZIP2=/usr/bin/bzip2
if sudo port -b install --no-rev-upgrade lbzip2; then
if [ -x /opt/local/bin/lbzip2 ]; then
BZIP2=/opt/local/bin/lbzip2
fi
fi
fi
tar -C tarball -c --use-compress-program "$BZIP2" --gid 0 --uid 0 --numeric-owner \
-f "portindex-${CURRENT_COMMIT}.tar.bz2" .
echo "Uploading tarball for commit ${CURRENT_COMMIT}"
curl -fL -u "$MIRROR_UPLOAD_CREDENTIALS" --upload-file "portindex-${CURRENT_COMMIT}.tar.bz2" "$MIRROR_UPLOAD_URL" > /dev/null
- name: Update status
env:
MIRROR_DB_URL: ${{ secrets.MIRROR_DB_URL }}
MIRROR_DB_CREDENTIALS: ${{ secrets.MIRROR_DB_CREDENTIALS }}
CURRENT_COMMIT: ${{ steps.prep-ports.outputs.current_commit }}
run: |
set -eu
echo "Updating mirror.last_commit to: $CURRENT_COMMIT"
curl -fL -u "$MIRROR_DB_CREDENTIALS" "${MIRROR_DB_URL}SET/mirror.last_commit/${CURRENT_COMMIT}"
- name: Save PortIndex
id: save-portindex
uses: actions/cache/save@v5
with:
path: tarball
key: portindex-${{ runner.os }}-${{ steps.prep-ports.outputs.current_commit }}