forked from macports/macports-ports
-
Notifications
You must be signed in to change notification settings - Fork 0
229 lines (203 loc) · 8.64 KB
/
Copy pathmirror.yml
File metadata and controls
229 lines (203 loc) · 8.64 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
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 "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: Update PortIndex files
env:
OLDEST_DARWIN: 9
NEWEST_DARWIN: 25
MIRROR_UPLOAD_URL: ${{ secrets.MIRROR_UPLOAD_URL }}
MIRROR_UPLOAD_CREDENTIALS: ${{ secrets.MIRROR_UPLOAD_CREDENTIALS }}
run: |
set -eu
# Start at last mirrored commit so we can get newer timestamps on only the changed files.
if [ -f last_commit ]; then
LAST_COMMIT="$(cat last_commit)"
else
LAST_COMMIT=""
fi
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.
mkdir -p tarball
if [ -n "$LAST_COMMIT" ]; then
echo "Fetching tarball for commit $LAST_COMMIT"
if curl -fL -O -u "$MIRROR_UPLOAD_CREDENTIALS" "${MIRROR_UPLOAD_URL}portindex-${LAST_COMMIT}.tar.bz2"; then
tar -C tarball -xjf "portindex-${LAST_COMMIT}.tar.bz2"
rm -f "portindex-${LAST_COMMIT}.tar.bz2"
git -C ports checkout "$LAST_COMMIT"
rsync -rltC --exclude=".git" --existing tarball/ports/ ports
git -C ports checkout "$CURRENT_COMMIT"
else
echo "Fetch failed, starting from scratch."
fi
else
echo "No mirror.last_commit value found, starting from scratch."
fi
mkdir -p tarball/ports
rsync -rltC --exclude=".git" --delete ports/ tarball/ports
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}"
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
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 {} \;
OS_MAJOR="$(uname -r | cut -f 1 -d .)"
OS_ARCH="$(uname -p)"
if [ -f "tarball/PortIndex_darwin_${OS_MAJOR}_${OS_ARCH}/PortIndex" ]; then
cp "tarball/PortIndex_darwin_${OS_MAJOR}_${OS_ARCH}/PortIndex" ports
else
echo "Warning: no PortIndex found for darwin_${OS_MAJOR}_${OS_ARCH}"
cp "tarball/PortIndex_darwin_${NEWEST_DARWIN}_${OS_ARCH}/PortIndex" ports
fi
chmod -R a+rX tarball
echo "Creating tarball for commit ${CURRENT_COMMIT}"
tar -C tarball -cjf "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: 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 status
env:
MIRROR_DB_URL: ${{ secrets.MIRROR_DB_URL }}
MIRROR_DB_CREDENTIALS: ${{ secrets.MIRROR_DB_CREDENTIALS }}
run: |
set -eu
CURRENT_COMMIT="$(git -C ports rev-parse HEAD)"
echo "Updating mirror.last_commit to: $CURRENT_COMMIT"
curl -fL -u "$MIRROR_DB_CREDENTIALS" "${MIRROR_DB_URL}SET/mirror.last_commit/${CURRENT_COMMIT}"