Skip to content

Commit 40469c5

Browse files
[gh] Update Script Test Workflow (#2599)
* Update Workflow * Update Workflow
1 parent 6827056 commit 40469c5

File tree

5 files changed

+115
-115
lines changed

5 files changed

+115
-115
lines changed

.github/workflows/script-test.yml

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
run-install-script:
1414
runs-on: pvenode
1515
steps:
16-
- name: Checkout PR branch (supports forks)
16+
- name: Checkout PR branch
1717
uses: actions/checkout@v4
1818
with:
1919
ref: ${{ github.event.pull_request.head.ref }}
@@ -37,7 +37,8 @@ jobs:
3737
echo "Changed files: $CHANGED_FILES"
3838
echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV
3939
env:
40-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
4142

4243
- name: Get scripts
4344
id: check-install-script
@@ -68,11 +69,11 @@ jobs:
6869
echo "Running Test for: $STRIPPED_NAME"
6970
if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
7071
CT_SCRIPT="ct/$STRIPPED_NAME.sh"
72+
echo $CT_SCRIPT
7173
if [[ ! -f $CT_SCRIPT ]]; then
7274
echo "No CT script found for $STRIPPED_NAME"
7375
ERROR_MSG="No CT script found for $FILE"
74-
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
75-
continue
76+
RUN=false
7677
fi
7778
echo "Found CT script for $STRIPPED_NAME"
7879
chmod +x "$CT_SCRIPT"
@@ -82,32 +83,19 @@ jobs:
8283
if [[ ! -f $INSTALL_SCRIPT ]]; then
8384
echo "No install script found for $STRIPPED_NAME"
8485
ERROR_MSG="No install script found for $FILE"
85-
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
86-
continue
86+
RUN=false
8787
fi
8888
echo "Found install script for $STRIPPED_NAME"
8989
chmod +x "$INSTALL_SCRIPT"
9090
RUNNING_FILE=$FILE
9191
fi
92-
git remote add community-scripts https://github.com/community-scripts/ProxmoxVE.git
93-
git fetch community-scripts
94-
rm -f .github/workflows/scripts/app-test/pr-build.func || true
95-
rm -f .github/workflows/scripts/app-test/pr-install.func || true
96-
rm -f .github/workflows/scripts/app-test/pr-alpine-install.func || true
97-
rm -f .github/workflows/scripts/app-test/pr-create-lxc.sh || true
98-
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-build.func
99-
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-install.func
100-
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-alpine-install.func
101-
git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-create-lxc.sh
102-
chmod +x $RUNNING_FILE
103-
chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
104-
chmod +x .github/workflows/scripts/app-test/pr-install.func
105-
chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
106-
chmod +x .github/workflows/scripts/app-test/pr-build.func
107-
sed -i 's|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source .github/workflows/scripts/app-test/pr-build.func|g' "$RUNNING_FILE"
108-
echo "Executing $RUNNING_FILE"
109-
ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
110-
echo "Finished running $FILE"
92+
if [[ $RUN != "false" ]]; then
93+
chmod +x $RUNNING_FILE
94+
sed -i 's|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source <(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-build.func)|g' "$RUNNING_FILE"
95+
echo "Executing $RUNNING_FILE"
96+
ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
97+
echo "Finished running $FILE"
98+
fi
11199
if [ -n "$ERROR_MSG" ]; then
112100
echo "ERROR in $STRIPPED_NAME: $ERROR_MSG"
113101
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
@@ -125,12 +113,13 @@ jobs:
125113
pct stop $container_id
126114
pct destroy $container_id
127115
fi
128-
done
116+
done
117+
129118

130119
- name: Post error comments
131120
run: |
132121
ERROR="false"
133-
SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 253:"
122+
SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 255"
134123
for FILE in ${{ env.ALL_FILES }}; do
135124
STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
136125
if [[ ! -f result_$STRIPPED_NAME.log ]]; then
@@ -145,8 +134,6 @@ jobs:
145134
gh pr comment ${{ github.event.pull_request.number }} \
146135
--repo ${{ github.repository }} \
147136
--body ":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>"
148-
149-
150137
ERROR="true"
151138
fi
152139
done
@@ -157,3 +144,5 @@ jobs:
157144
- name: Fail if error
158145
if: ${{ env.ERROR == 'true' }}
159146
run: exit 1
147+
148+

.github/workflows/scripts/app-test/pr-alpine-install.func

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
# Copyright (c) 2021-2025 community-scripts ORG
3-
# Author: michelroegl-brunner
3+
# Author: Michel Roegl-Brunner (michelroegl-brunner)
44
# License: MIT | https://github.com/community-scripts/ProxmoxVE/raw/main/LICENSE
55

66
color() {
@@ -11,7 +11,7 @@ catch_errors() {
1111
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
1212
}
1313

14-
14+
# This function handles errors
1515
error_handler() {
1616
local line_number="$1"
1717
local command="$2"
@@ -21,22 +21,22 @@ error_handler() {
2121
exit 0
2222
}
2323
verb_ip6() {
24-
STD=""
25-
return
24+
STD=""
25+
return
2626
}
2727

2828
msg_info() {
2929
local msg="$1"
3030
echo -ne "${msg}\n"
3131
}
3232

33-
msg_ok() {
33+
msg_ok() {
3434
local msg="$1"
3535
echo -e "${msg}\n"
3636
}
3737

3838
msg_error() {
39-
39+
4040
local msg="$1"
4141
echo -e "${msg}\n"
4242
}
@@ -71,7 +71,7 @@ network_check() {
7171
}
7272

7373
update_os() {
74-
msg_info "Updating Container OS"
74+
msg_info "Updating Container OS"
7575
apk update
7676
apk upgrade
7777
msg_ok "Updated Container OS"
@@ -82,7 +82,5 @@ motd_ssh() {
8282
}
8383

8484
customize() {
85-
return
86-
}
87-
88-
85+
return
86+
}

.github/workflows/scripts/app-test/pr-build.func

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
variables() {
77
NSAPP=$(echo ${APP,,} | tr -d ' ') # This function sets the NSAPP variable by converting the value of the APP variable to lowercase and removing any spaces.
88
var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP.
9+
910
}
1011

1112
NEXTID=$(pvesh get /cluster/nextid)
1213
timezone=$(cat /etc/timezone)
13-
header_info(){
14-
return
14+
header_info() {
15+
return
1516
}
1617

1718
base_settings() {
@@ -20,10 +21,10 @@ base_settings() {
2021
DISK_SIZE="4"
2122
CORE_COUNT="1"
2223
RAM_SIZE="1024"
23-
VERBOSE="${1:-no}"
24+
VERBOSE="no"
2425
PW=""
2526
CT_ID=$NEXTID
26-
HN="Testing"
27+
HN=$NSAPP
2728
BRG="vmbr0"
2829
NET="dhcp"
2930
GATE=""
@@ -106,7 +107,7 @@ catch_errors() {
106107
}
107108

108109
# This function handles errors
109-
error_handler() {
110+
error_handler() {
110111
local line_number="$1"
111112
local command="$2"
112113
SCRIPT_NAME=$(basename "$0")
@@ -120,17 +121,17 @@ msg_info() {
120121
echo -ne "${msg}\n"
121122
}
122123

123-
msg_ok() {
124+
msg_ok() {
124125
local msg="$1"
125126
echo -e "${msg}\n"
126127
}
127128

128129
msg_error() {
129-
130+
130131
local msg="$1"
131132
echo -e "${msg}\n"
132133
}
133-
start(){
134+
start() {
134135
base_settings
135136
return
136137
}
@@ -146,9 +147,9 @@ build_container() {
146147
TEMP_DIR=$(mktemp -d)
147148
pushd $TEMP_DIR >/dev/null
148149
if [ "$var_os" == "alpine" ]; then
149-
export FUNCTIONS_FILE_PATH="$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-alpine-install.func)"
150+
export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-alpine-install.func)"
150151
else
151-
export FUNCTIONS_FILE_PATH="$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-install.func)"
152+
export FUNCTIONS_FILE_PATH="$(curl -s https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-install.func)"
152153
fi
153154

154155
export CACHER="$APT_CACHER"
@@ -182,9 +183,8 @@ build_container() {
182183
"
183184
echo "Container ID: $CTID"
184185

185-
186186
# This executes create_lxc.sh and creates the container and .conf file
187-
bash /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/.github/workflows/scripts/app-test/pr-create-lxc.sh
187+
bash -c "$(wget -qLO - https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/.github/workflows/scripts/app-test/pr-create-lxc.sh)"
188188

189189
LXC_CONFIG=/etc/pve/lxc/${CTID}.conf
190190
if [ "$CT_TYPE" == "0" ]; then
@@ -233,6 +233,7 @@ EOF
233233
fi
234234
fi
235235
fi
236+
236237
# This starts the container and executes <app>-install.sh
237238
msg_info "Starting LXC Container"
238239
pct start "$CTID"
@@ -242,19 +243,18 @@ EOF
242243
msg_error "No install script found for $APP"
243244
exit 1
244245
fi
245-
if [ "$var_os" == "alpine" ]; then
246+
if [ "$var_os" == "alpine" ]; then
246247
sleep 3
247248
pct exec "$CTID" -- /bin/sh -c 'cat <<EOF >/etc/apk/repositories
248249
http://dl-cdn.alpinelinux.org/alpine/latest-stable/main
249250
http://dl-cdn.alpinelinux.org/alpine/latest-stable/community
250251
EOF'
251252
pct exec "$CTID" -- ash -c "apk add bash >/dev/null"
252253
fi
253-
lxc-attach -n "$CTID" -- bash -c "$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)" $var_install.sh
254+
lxc-attach -n "$CTID" -- bash -c "$(cat /root/actions-runner/_work/ProxmoxVE/ProxmoxVE/install/$var_install.sh)"
254255

255256
}
256257

257-
description(){
258-
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
259-
return
260-
}
258+
description() {
259+
IP=$(pct exec "$CTID" ip a s dev eth0 | awk '/inet / {print $2}' | cut -d/ -f1)
260+
}

0 commit comments

Comments
 (0)