Skip to content

Commit ebb07fb

Browse files
committed
patches: Clone repo once instead of downloading patches individually.
Improve the performance of the patch phase of the install process by doing a single shallow clone of the repo, rather than downloading all needed files individually. A side benefit of this is that we can now also force the CI to build the version of a module in the checked out version of the repo, which is useful for anything besides a commit to master (e.g. PR to master, or a commit/PR to a different branch). Previously, they would all download the master version, and to test a different build, the PR would have to be temporarily modified to include the proper version.
1 parent 2e6e503 commit ebb07fb

File tree

2 files changed

+72
-24
lines changed

2 files changed

+72
-24
lines changed

.github/workflows/main.yml

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
- name: Build DAHDI
6767
run: |
6868
./phreaknet.sh make
69-
KSRC=/usr/src/linux phreaknet dahdi --drivers
69+
GIT_REPO_PATH=${GITHUB_WORKSPACE} KSRC=/usr/src/linux phreaknet dahdi --drivers
7070
dahdi-kernel-mainline:
7171
runs-on: ubuntu-24.04
7272
name: DAHDI, mainline kernel
@@ -94,7 +94,7 @@ jobs:
9494
- name: Build DAHDI
9595
run: |
9696
./phreaknet.sh make
97-
KSRC=/usr/src/linux phreaknet dahdi --drivers
97+
GIT_REPO_PATH=${GITHUB_WORKSPACE} KSRC=/usr/src/linux phreaknet dahdi --drivers
9898
dahdi-kernel-next:
9999
runs-on: ubuntu-24.04
100100
name: DAHDI, next kernel
@@ -122,7 +122,7 @@ jobs:
122122
- name: Build DAHDI
123123
run: |
124124
./phreaknet.sh make
125-
KSRC=/usr/src/linux-next phreaknet dahdi --drivers
125+
GIT_REPO_PATH=${GITHUB_WORKSPACE} KSRC=/usr/src/linux-next phreaknet dahdi --drivers
126126
ubuntu-latest:
127127
runs-on: ubuntu-24.04
128128
name: Ubuntu 24.04
@@ -132,7 +132,7 @@ jobs:
132132
- name: Build DAHDI and Asterisk
133133
run: |
134134
sudo ./phreaknet.sh make
135-
sudo phreaknet install --fast --dahdi --drivers --devmode --sip
135+
sudo GIT_REPO_PATH=${{ github.workspace }} phreaknet install --fast --dahdi --drivers --devmode --sip
136136
ubuntu-stable:
137137
runs-on: ubuntu-22.04
138138
name: Ubuntu 22.04
@@ -142,7 +142,8 @@ jobs:
142142
- name: Build DAHDI and Asterisk
143143
run: |
144144
sudo ./phreaknet.sh make
145-
sudo phreaknet install --fast --dahdi --drivers --devmode --sip
145+
# Environment variables don't carry through with sudo
146+
sudo GIT_REPO_PATH=${{ github.workspace }} phreaknet install --fast --dahdi --drivers --devmode --sip
146147
debian-stable-asterisk-lts:
147148
runs-on: ubuntu-24.04
148149
name: Debian 12, Asterisk 20
@@ -152,7 +153,7 @@ jobs:
152153
- name: Build DAHDI and Asterisk
153154
run: |
154155
./phreaknet.sh make
155-
phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
156+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
156157
- name: Run tests
157158
run: |
158159
phreaknet runtests
@@ -165,7 +166,7 @@ jobs:
165166
- name: Build DAHDI and Asterisk
166167
run: |
167168
./phreaknet.sh make
168-
phreaknet install --fast --dahdi --drivers --sip --testsuite
169+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --drivers --sip --testsuite
169170
- name: Run tests
170171
run: |
171172
phreaknet runtests
@@ -178,7 +179,7 @@ jobs:
178179
- name: Build DAHDI and Asterisk
179180
run: |
180181
./phreaknet.sh make
181-
phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
182+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
182183
fedora-42:
183184
runs-on: ubuntu-24.04
184185
name: Fedora 42
@@ -188,7 +189,7 @@ jobs:
188189
- name: Build DAHDI and Asterisk
189190
run: |
190191
./phreaknet.sh make
191-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
192+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --autokvers --drivers --devmode
192193
alma-9-5:
193194
runs-on: ubuntu-24.04
194195
name: Alma Linux 9.5
@@ -198,7 +199,7 @@ jobs:
198199
- name: Build DAHDI and Asterisk
199200
run: |
200201
./phreaknet.sh make
201-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
202+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --autokvers --drivers --devmode
202203
rocky-9:
203204
runs-on: ubuntu-24.04
204205
name: Rocky Linux 9.3
@@ -208,7 +209,7 @@ jobs:
208209
- name: Build DAHDI and Asterisk
209210
run: |
210211
./phreaknet.sh make
211-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
212+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --autokvers --drivers --devmode
212213
rocky-8:
213214
runs-on: ubuntu-24.04
214215
name: Rocky Linux 8.9
@@ -218,7 +219,7 @@ jobs:
218219
- name: Build DAHDI and Asterisk
219220
run: |
220221
./phreaknet.sh make
221-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
222+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --autokvers --drivers --devmode
222223
opensuse:
223224
runs-on: ubuntu-24.04
224225
name: openSUSE Tumbleweed
@@ -228,7 +229,7 @@ jobs:
228229
- name: Build Asterisk
229230
run: |
230231
./phreaknet.sh make
231-
phreaknet install --fast --devmode --sip
232+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --devmode --sip
232233
archlinux:
233234
runs-on: ubuntu-24.04
234235
name: Arch Linux
@@ -238,7 +239,7 @@ jobs:
238239
- name: Build DAHDI and Asterisk
239240
run: |
240241
./phreaknet.sh make
241-
phreaknet install --fast --dahdi --drivers --devmode --sip
242+
GIT_REPO_PATH=${GITHUB_WORKSPACE} phreaknet install --fast --dahdi --drivers --devmode --sip
242243
# FreeBSD CI disabled since libuuid headers can't get installed in CI?
243244
# freebsd-14:
244245
# runs-on: ubuntu-24.04

phreaknet.sh

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,10 @@ dahdi_patch() {
14671467

14681468
git_patch() {
14691469
printf "Applying git patch: %s\n" "$1"
1470-
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/master/patches/$1" -O /tmp/$1 --no-cache
1470+
cp "$GIT_REPO_PATH/patches/$1" "/tmp/$1"
1471+
if [ $? -ne 0 ]; then
1472+
die "File $1 does not exist"
1473+
fi
14711474
git apply "/tmp/$1"
14721475
if [ $? -ne 0 ]; then
14731476
die "Failed to apply git patch $1... this should be reported..."
@@ -1517,16 +1520,17 @@ asterisk_pr() {
15171520
}
15181521

15191522
git_custom_patch() {
1523+
CUSTOM_PATCH_FILE=/tmp/tmp_git_patch.diff
15201524
printf "Applying git patch: %s\n" "$1"
1521-
wget -q "$1" -O /tmp/tmp_git_patch.diff --no-cache
1522-
if [ ! -f /tmp/tmp_git_patch.diff ]; then
1525+
wget -q "$1" -O $CUSTOM_PATCH_FILE --no-cache
1526+
if [ ! -f $CUSTOM_PATCH_FILE ]; then
15231527
die "Failed to download patch $1"
15241528
fi
1525-
git apply "/tmp/tmp_git_patch.diff"
1529+
git apply $CUSTOM_PATCH_FILE
15261530
if [ $? -ne 0 ]; then
15271531
die "Failed to apply git patch $1... this should be reported..."
15281532
fi
1529-
rm "/tmp/tmp_git_patch.diff"
1533+
rm $CUSTOM_PATCH_FILE
15301534
}
15311535

15321536
dahdi_unpurge() { # undo "great purge" of 2018: $1 = DAHDI_LIN_SRC_DIR
@@ -1866,6 +1870,8 @@ install_dahdi() {
18661870
dahdi_unpurge $DAHDI_LIN_SRC_DIR # for some reason, this needs to be applied before the next branch patches
18671871
fi
18681872

1873+
instantiate_repo
1874+
18691875
# Compiler fixes for 5.17/5.18:
18701876
if [ $DAHDI_MM_VER -lt 33 ]; then
18711877
phreak_fuzzy_patch "dahdi_pci.diff"
@@ -2107,9 +2113,9 @@ install_dahdi() {
21072113

21082114
phreak_tree_module() { # $1 = file to patch, $2 = whether failure is acceptable
21092115
printf "Adding new module: %s\n" "$1"
2110-
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/master/$1" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1" --no-cache
2116+
cp "$GIT_REPO_PATH/$1" "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1"
21112117
if [ $? -ne 0 ]; then
2112-
echoerr "Failed to download module: $1"
2118+
echoerr "Failed to copy module: $1"
21132119
if [ "$2" != "1" ]; then # unless failure is acceptable, abort
21142120
exit 2
21152121
fi
@@ -2118,6 +2124,7 @@ phreak_tree_module() { # $1 = file to patch, $2 = whether failure is acceptable
21182124

21192125
phreak_tree_module_branch() { # $1 = file to patch, $2 = whether failure is acceptable, $3 = branch name
21202126
printf "Adding new module: %s\n" "$1"
2127+
# Always need to download, since the local copy of the git repo is on the master branch
21212128
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/$3/$1" -O "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1" --no-cache
21222129
if [ $? -ne 0 ]; then
21232130
echoerr "Failed to download module from branch $3, retrying with master..."
@@ -2154,9 +2161,9 @@ phreak_nontree_patch() { # $1 = patched file, $2 = patch name
21542161

21552162
phreak_tree_patch() { # $1 = patched file, $2 = patch name
21562163
printf "Applying patch %s to %s\n" "$2" "$1"
2157-
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/master/patches/$2" -O "/tmp/$2" --no-cache
2164+
cp "$GIT_REPO_PATH/patches/$2" "/tmp/$2"
21582165
if [ $? -ne 0 ]; then
2159-
echoerr "Failed to download patch: $2"
2166+
echoerr "Failed to copy patch: $2"
21602167
exit 2
21612168
fi
21622169
patch -u -b "$1" -i "/tmp/$2"
@@ -2169,7 +2176,7 @@ phreak_tree_patch() { # $1 = patched file, $2 = patch name
21692176

21702177
phreak_fuzzy_patch() {
21712178
printf "Applying patch %s to %s\n" "$1" "$1"
2172-
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/master/patches/$1" -O "/tmp/$1" --no-cache
2179+
cp "$GIT_REPO_PATH/patches/$1" "/tmp/$1"
21732180
if [ $? -ne 0 ]; then
21742181
echoerr "Failed to download patch: $1"
21752182
exit 2
@@ -2243,13 +2250,51 @@ add_experimental() {
22432250
custom_module "res/res_pjsip_sca_body_generator.c" "https://code.phreaknet.org/asterisk/res_pjsip_sca_body_generator.c"
22442251
}
22452252

2253+
# Instantiate an instance of the PhreakScript repository, if not already present
2254+
# This is necessary since this script file is designed to be able to be used standalone,
2255+
# without the rest of the repository necessarily being present.
2256+
instantiate_repo() {
2257+
# GitHub no longers allows svn access (which was useful to download a subset of a repo)
2258+
# Settle for using a shallow clone
2259+
# At this point, this is more efficient than individually downloading all of the files
2260+
# used by phreak_tree_module and phreak_tree_patch.
2261+
if [ "${GIT_REPO_PATH}" = "" ]; then
2262+
# pushd is a bashism, can't use it!
2263+
ORIG_DIR="$PWD"
2264+
cd /tmp
2265+
if [ ! -d phreakscript ]; then
2266+
printf "GIT_REPO_PATH not already set and not found in /tmp, cloning...\n"
2267+
git clone --depth=1 https://github.com/InterLinked1/phreakscript.git
2268+
else
2269+
printf "GIT_REPO_PATH not already set but found in /tmp, updating...\n"
2270+
cd /tmp/phreakscript
2271+
git checkout master
2272+
git pull
2273+
fi
2274+
GIT_REPO_PATH=/tmp/phreakscript
2275+
if [ ! -d $GIT_REPO_PATH ]; then
2276+
die "Directory does not exist: $GIT_REPO_PATH"
2277+
fi
2278+
printf "GIT_REPO_PATH is now %s\n" "$GIT_REPO_PATH"
2279+
cd "$ORIG_DIR"
2280+
else
2281+
printf "GIT_REPO_PATH already provided: %s\n" "$GIT_REPO_PATH"
2282+
if [ ! -d "$GIT_REPO_PATH" ]; then
2283+
die "Directory does not exist: $GIT_REPO_PATH"
2284+
fi
2285+
fi
2286+
}
2287+
22462288
phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
22472289
### Inject custom PhreakNet patches to add additional functionality and features.
22482290
### If/when/as these are integrated upstream, they will be removed from this function.
22492291

2292+
instantiate_repo
2293+
22502294
cd $AST_SOURCE_PARENT_DIR/$2
22512295

22522296
## Add Standalone PhreakNet Modules
2297+
# XXX In theory, something like cp $GIT_REPO_PATH/apps/*.c apps, etc. would also suffice, rather than enumerating
22532298
phreak_tree_module "apps/app_acts.c"
22542299
phreak_tree_module "apps/app_assert.c"
22552300
phreak_tree_module "apps/app_audichron.c"
@@ -3229,6 +3274,7 @@ elif [ "$cmd" = "install" ]; then
32293274
echoerr "Distro not supported for package audit"
32303275
fi
32313276
fi
3277+
32323278
# Install Pre-Reqs
32333279
printf "%s %d\n" "Starting installation with country code" $AST_CC
32343280
quell_mysql
@@ -3735,6 +3781,7 @@ elif [ "$cmd" = "fullpatch" ]; then
37353781
filename="${filename}.c"
37363782
fi
37373783
fi
3784+
instantiate_repo
37383785
phreak_tree_module "$filename"
37393786
elif [ "$cmd" = "runtest" ]; then
37403787
if [ ${#2} -eq 0 ]; then

0 commit comments

Comments
 (0)