Skip to content

Commit

Permalink
patches: Clone repo once instead of downloading patches individually.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
InterLinked1 committed Jan 25, 2025
1 parent 2e6e503 commit 9ac4543
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
sudo ./phreaknet.sh make
sudo phreaknet install --fast --dahdi --drivers --devmode --sip
GIT_REPO_PATH=$PWD sudo phreaknet install --fast --dahdi --drivers --devmode --sip
ubuntu-stable:
runs-on: ubuntu-22.04
name: Ubuntu 22.04
Expand All @@ -142,7 +142,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
sudo ./phreaknet.sh make
sudo phreaknet install --fast --dahdi --drivers --devmode --sip
GIT_REPO_PATH=$PWD sudo phreaknet install --fast --dahdi --drivers --devmode --sip
debian-stable-asterisk-lts:
runs-on: ubuntu-24.04
name: Debian 12, Asterisk 20
Expand All @@ -152,7 +152,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --sip --testsuite --version=20
- name: Run tests
run: |
phreaknet runtests
Expand All @@ -165,7 +165,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --drivers --sip --testsuite
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --sip --testsuite
- name: Run tests
run: |
phreaknet runtests
Expand All @@ -178,7 +178,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --devmode --sip --vanilla --user=asterisk
fedora-42:
runs-on: ubuntu-24.04
name: Fedora 42
Expand All @@ -188,7 +188,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --autokvers --drivers --devmode
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
alma-9-5:
runs-on: ubuntu-24.04
name: Alma Linux 9.5
Expand All @@ -198,7 +198,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --autokvers --drivers --devmode
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
rocky-9:
runs-on: ubuntu-24.04
name: Rocky Linux 9.3
Expand All @@ -208,7 +208,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --autokvers --drivers --devmode
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
rocky-8:
runs-on: ubuntu-24.04
name: Rocky Linux 8.9
Expand All @@ -218,7 +218,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --autokvers --drivers --devmode
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --autokvers --drivers --devmode
opensuse:
runs-on: ubuntu-24.04
name: openSUSE Tumbleweed
Expand All @@ -228,7 +228,7 @@ jobs:
- name: Build Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --devmode --sip
GIT_REPO_PATH=$PWD phreaknet install --fast --devmode --sip
archlinux:
runs-on: ubuntu-24.04
name: Arch Linux
Expand All @@ -238,7 +238,7 @@ jobs:
- name: Build DAHDI and Asterisk
run: |
./phreaknet.sh make
phreaknet install --fast --dahdi --drivers --devmode --sip
GIT_REPO_PATH=$PWD phreaknet install --fast --dahdi --drivers --devmode --sip
# FreeBSD CI disabled since libuuid headers can't get installed in CI?
# freebsd-14:
# runs-on: ubuntu-24.04
Expand Down
37 changes: 33 additions & 4 deletions phreaknet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2107,9 +2107,9 @@ install_dahdi() {

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

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

phreak_tree_patch() { # $1 = patched file, $2 = patch name
printf "Applying patch %s to %s\n" "$2" "$1"
wget -q "https://raw.githubusercontent.com/InterLinked1/phreakscript/master/patches/$2" -O "/tmp/$2" --no-cache
cp "$GIT_REPO_PATH/patches/$2" "/tmp/$2"
if [ $? -ne 0 ]; then
echoerr "Failed to download patch: $2"
echoerr "Failed to copy patch: $2"
exit 2
fi
patch -u -b "$1" -i "/tmp/$2"
Expand Down Expand Up @@ -2243,13 +2244,41 @@ add_experimental() {
custom_module "res/res_pjsip_sca_body_generator.c" "https://code.phreaknet.org/asterisk/res_pjsip_sca_body_generator.c"
}

# Instantiate an instance of the PhreakScript repository, if not already present
# This is necessary since this script file is designed to be able to be used standalone,
# without the rest of the repoistory necessarily being present.
instantiate_repo() {
# GitHub no longers allows svn access (which was useful to download a subset of a repo)
# Settle for using a shallow clone
# At this point, this is more efficient than individually downloading all of the files
# used by phreak_tree_module and phreak_tree_patch.
if [ "$GIT_REPO_PATH" = "" ]; then
cd /tmp
if [ ! -d phreakscript ]; then
printf "GIT_REPO_PATH not already set and not found in /tmp, cloning...\n"
git clone --depth=1 https://github.com/InterLinked1/phreakscript.git
else
printf "GIT_REPO_PATH not already set but found in /tmp, updating...\n"
cd /tmp/phreakscript
git checkout master
git pull
fi
GIT_REPO_PATH=/tmp/phreakscript
else
printf "GIT_REPO_PATH already provided: %s\n" "$GIT_REPO_PATH"
fi
}

phreak_patches() { # $1 = $PATCH_DIR, $2 = $AST_SRC_DIR
### Inject custom PhreakNet patches to add additional functionality and features.
### If/when/as these are integrated upstream, they will be removed from this function.

instantiate_repo

cd $AST_SOURCE_PARENT_DIR/$2

## Add Standalone PhreakNet Modules
# XXX In theory, something like cp $GIT_REPO_PATH/apps/*.c apps, etc. would also suffice, rather than enumerating
phreak_tree_module "apps/app_acts.c"
phreak_tree_module "apps/app_assert.c"
phreak_tree_module "apps/app_audichron.c"
Expand Down

0 comments on commit 9ac4543

Please sign in to comment.