Skip to content

Commit 9ac4543

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 9ac4543

File tree

2 files changed

+44
-15
lines changed

2 files changed

+44
-15
lines changed

.github/workflows/main.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
GIT_REPO_PATH=$PWD sudo phreaknet install --fast --dahdi --drivers --devmode --sip
136136
ubuntu-stable:
137137
runs-on: ubuntu-22.04
138138
name: Ubuntu 22.04
@@ -142,7 +142,7 @@ jobs:
142142
- name: Build DAHDI and Asterisk
143143
run: |
144144
sudo ./phreaknet.sh make
145-
sudo phreaknet install --fast --dahdi --drivers --devmode --sip
145+
GIT_REPO_PATH=$PWD sudo phreaknet install --fast --dahdi --drivers --devmode --sip
146146
debian-stable-asterisk-lts:
147147
runs-on: ubuntu-24.04
148148
name: Debian 12, Asterisk 20
@@ -152,7 +152,7 @@ jobs:
152152
- name: Build DAHDI and Asterisk
153153
run: |
154154
./phreaknet.sh make
155-
phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
155+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
156156
- name: Run tests
157157
run: |
158158
phreaknet runtests
@@ -165,7 +165,7 @@ jobs:
165165
- name: Build DAHDI and Asterisk
166166
run: |
167167
./phreaknet.sh make
168-
phreaknet install --fast --dahdi --drivers --sip --testsuite
168+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --sip --testsuite
169169
- name: Run tests
170170
run: |
171171
phreaknet runtests
@@ -178,7 +178,7 @@ jobs:
178178
- name: Build DAHDI and Asterisk
179179
run: |
180180
./phreaknet.sh make
181-
phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
181+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
182182
fedora-42:
183183
runs-on: ubuntu-24.04
184184
name: Fedora 42
@@ -188,7 +188,7 @@ jobs:
188188
- name: Build DAHDI and Asterisk
189189
run: |
190190
./phreaknet.sh make
191-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
191+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
192192
alma-9-5:
193193
runs-on: ubuntu-24.04
194194
name: Alma Linux 9.5
@@ -198,7 +198,7 @@ jobs:
198198
- name: Build DAHDI and Asterisk
199199
run: |
200200
./phreaknet.sh make
201-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
201+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
202202
rocky-9:
203203
runs-on: ubuntu-24.04
204204
name: Rocky Linux 9.3
@@ -208,7 +208,7 @@ jobs:
208208
- name: Build DAHDI and Asterisk
209209
run: |
210210
./phreaknet.sh make
211-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
211+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
212212
rocky-8:
213213
runs-on: ubuntu-24.04
214214
name: Rocky Linux 8.9
@@ -218,7 +218,7 @@ jobs:
218218
- name: Build DAHDI and Asterisk
219219
run: |
220220
./phreaknet.sh make
221-
phreaknet install --fast --dahdi --autokvers --drivers --devmode
221+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
222222
opensuse:
223223
runs-on: ubuntu-24.04
224224
name: openSUSE Tumbleweed
@@ -228,7 +228,7 @@ jobs:
228228
- name: Build Asterisk
229229
run: |
230230
./phreaknet.sh make
231-
phreaknet install --fast --devmode --sip
231+
GIT_REPO_PATH=$PWD phreaknet install --fast --devmode --sip
232232
archlinux:
233233
runs-on: ubuntu-24.04
234234
name: Arch Linux
@@ -238,7 +238,7 @@ jobs:
238238
- name: Build DAHDI and Asterisk
239239
run: |
240240
./phreaknet.sh make
241-
phreaknet install --fast --dahdi --drivers --devmode --sip
241+
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --devmode --sip
242242
# FreeBSD CI disabled since libuuid headers can't get installed in CI?
243243
# freebsd-14:
244244
# runs-on: ubuntu-24.04

phreaknet.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,9 +2107,9 @@ install_dahdi() {
21072107

21082108
phreak_tree_module() { # $1 = file to patch, $2 = whether failure is acceptable
21092109
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
2110+
cp "$GIT_REPO_PATH/$1" "$AST_SOURCE_PARENT_DIR/$AST_SRC_DIR/$1"
21112111
if [ $? -ne 0 ]; then
2112-
echoerr "Failed to download module: $1"
2112+
echoerr "Failed to copy module: $1"
21132113
if [ "$2" != "1" ]; then # unless failure is acceptable, abort
21142114
exit 2
21152115
fi
@@ -2118,6 +2118,7 @@ phreak_tree_module() { # $1 = file to patch, $2 = whether failure is acceptable
21182118

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

21552156
phreak_tree_patch() { # $1 = patched file, $2 = patch name
21562157
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
2158+
cp "$GIT_REPO_PATH/patches/$2" "/tmp/$2"
21582159
if [ $? -ne 0 ]; then
2159-
echoerr "Failed to download patch: $2"
2160+
echoerr "Failed to copy patch: $2"
21602161
exit 2
21612162
fi
21622163
patch -u -b "$1" -i "/tmp/$2"
@@ -2243,13 +2244,41 @@ add_experimental() {
22432244
custom_module "res/res_pjsip_sca_body_generator.c" "https://code.phreaknet.org/asterisk/res_pjsip_sca_body_generator.c"
22442245
}
22452246

2247+
# Instantiate an instance of the PhreakScript repository, if not already present
2248+
# This is necessary since this script file is designed to be able to be used standalone,
2249+
# without the rest of the repoistory necessarily being present.
2250+
instantiate_repo() {
2251+
# GitHub no longers allows svn access (which was useful to download a subset of a repo)
2252+
# Settle for using a shallow clone
2253+
# At this point, this is more efficient than individually downloading all of the files
2254+
# used by phreak_tree_module and phreak_tree_patch.
2255+
if [ "$GIT_REPO_PATH" = "" ]; then
2256+
cd /tmp
2257+
if [ ! -d phreakscript ]; then
2258+
printf "GIT_REPO_PATH not already set and not found in /tmp, cloning...\n"
2259+
git clone --depth=1 https://github.com/InterLinked1/phreakscript.git
2260+
else
2261+
printf "GIT_REPO_PATH not already set but found in /tmp, updating...\n"
2262+
cd /tmp/phreakscript
2263+
git checkout master
2264+
git pull
2265+
fi
2266+
GIT_REPO_PATH=/tmp/phreakscript
2267+
else
2268+
printf "GIT_REPO_PATH already provided: %s\n" "$GIT_REPO_PATH"
2269+
fi
2270+
}
2271+
22462272
phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
22472273
### Inject custom PhreakNet patches to add additional functionality and features.
22482274
### If/when/as these are integrated upstream, they will be removed from this function.
22492275

2276+
instantiate_repo
2277+
22502278
cd $AST_SOURCE_PARENT_DIR/$2
22512279

22522280
## Add Standalone PhreakNet Modules
2281+
# XXX In theory, something like cp $GIT_REPO_PATH/apps/*.c apps, etc. would also suffice, rather than enumerating
22532282
phreak_tree_module "apps/app_acts.c"
22542283
phreak_tree_module "apps/app_assert.c"
22552284
phreak_tree_module "apps/app_audichron.c"

0 commit comments

Comments
 (0)