Skip to content

Commit caa4b7d

Browse files
[GH] Remove unwanted output from script test workflow (#2337)
* Remove unwanted output from workflow * Remove unwanted output from workflow * update .yml so it supports external repos * update .yml so it supports external repos
1 parent b99adb5 commit caa4b7d

File tree

4 files changed

+63
-60
lines changed

4 files changed

+63
-60
lines changed

.github/workflows/script-test.yml

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1-
name: Run Scripts on PVE Node
1+
name: Run Scripts on PVE Node for testing
2+
permissions:
3+
pull-requests: write
24
on:
3-
pull_request:
5+
pull_request_target:
46
branches:
57
- main
68
paths:
7-
- 'install/*.sh'
8-
- 'ct/*.sh'
9+
- 'install/**.sh'
10+
- 'ct/**.sh'
911

1012
jobs:
1113
run-install-script:
1214
runs-on: pvenode
1315
steps:
14-
- name: Checkout PR branch
16+
- name: Checkout PR branch (supports forks)
1517
uses: actions/checkout@v4
1618
with:
1719
ref: ${{ github.event.pull_request.head.ref }}
18-
fetch-depth: 0
20+
repository: ${{ github.event.pull_request.head.repo.full_name }}
21+
fetch-depth: 0
22+
1923
- name: Add Git safe directory
2024
run: |
2125
git config --global --add safe.directory /__w/ProxmoxVE/ProxmoxVE
@@ -26,13 +30,14 @@ jobs:
2630
run: |
2731
echo "GH_TOKEN=${GH_TOKEN}" >> $GITHUB_ENV
2832
29-
- name: Get changed files in PR
30-
id: changed-files
31-
run: |
32-
CHANGED_FILES=$(gh pr diff --name-only ${{ github.event.pull_request.number }})
33-
CHANGED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
34-
echo "Changed files: $CHANGED_FILES"
33+
- name: Get Changed Files
34+
run: |
35+
CHANGED_FILES=$(gh pr diff ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --name-only)
36+
CHANGED_FILES=$(echo "$CHANGED_FILES" | tr '\n' ' ')
37+
echo "Changed files: $CHANGED_FILES"
3538
echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV
39+
env:
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3641

3742
- name: Get scripts
3843
id: check-install-script
@@ -51,21 +56,23 @@ jobs:
5156
ALL_FILES=$(echo "${ALL_FILES[@]}" | xargs)
5257
echo "$ALL_FILES"
5358
echo "ALL_FILES=$ALL_FILES" >> $GITHUB_ENV
54-
59+
5560
- name: Run scripts
5661
id: run-install
5762
continue-on-error: true
5863
run: |
5964
set +e
6065
#run for each files in /ct
6166
for FILE in ${{ env.ALL_FILES }}; do
62-
echo "Running: $FILE"
6367
STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
68+
echo "Running Test for: $STRIPPED_NAME"
6469
if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
6570
CT_SCRIPT="ct/$STRIPPED_NAME.sh"
6671
if [[ ! -f $CT_SCRIPT ]]; then
6772
echo "No CT script found for $STRIPPED_NAME"
68-
exit 1
73+
ERROR_MSG="No CT script found for $FILE"
74+
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
75+
continue
6976
fi
7077
echo "Found CT script for $STRIPPED_NAME"
7178
chmod +x "$CT_SCRIPT"
@@ -74,8 +81,10 @@ jobs:
7481
INSTALL_SCRIPT="install/$STRIPPED_NAME-install.sh"
7582
if [[ ! -f $INSTALL_SCRIPT ]]; then
7683
echo "No install script found for $STRIPPED_NAME"
77-
exit 1
78-
fi
84+
ERROR_MSG="No install script found for $FILE"
85+
echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
86+
continue
87+
fi
7988
echo "Found install script for $STRIPPED_NAME"
8089
chmod +x "$INSTALL_SCRIPT"
8190
RUNNING_FILE=$FILE
@@ -84,13 +93,13 @@ jobs:
8493
git checkout origin/main .github/workflows/scripts/app-test/pr-install.func
8594
git checkout origin/main .github/workflows/scripts/app-test/pr-alpine-install.func
8695
git checkout origin/main .github/workflows/scripts/app-test/pr-create-lxc.sh
87-
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"
8896
chmod +x $RUNNING_FILE
8997
chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
9098
chmod +x .github/workflows/scripts/app-test/pr-install.func
9199
chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
92100
chmod +x .github/workflows/scripts/app-test/pr-build.func
93-
101+
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"
102+
echo "Executing $RUNNING_FILE"
94103
ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
95104
echo "Finished running $FILE"
96105
if [ -n "$ERROR_MSG" ]; then
@@ -110,8 +119,8 @@ jobs:
110119
pct stop $container_id
111120
pct destroy $container_id
112121
fi
113-
done
114-
122+
done
123+
115124
- name: Post error comments
116125
run: |
117126
ERROR="false"
@@ -128,12 +137,17 @@ jobs:
128137
echo "Posting error message for $FILE"
129138
echo ${CLEANED_ERROR_MSG}
130139
gh pr comment ${{ github.event.pull_request.number }} \
140+
--repo ${{ github.repository }} \
131141
--body ":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>"
132142

143+
133144
ERROR="true"
134145
fi
135146
done
136147
echo "ERROR=$ERROR" >> $GITHUB_ENV
148+
env:
149+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
150+
137151
- name: Fail if error
138-
if: ${{ env.ERROR }} == 'true'
152+
if: ${{ env.ERROR == 'true' }}
139153
run: exit 1

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
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
variables() {
7-
NSAPP=$(echo ${APP,,} | tr -d ' ')
8-
var_install="${NSAPP}-install"
9-
7+
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.
8+
var_install="${NSAPP}-install" # sets the var_install variable by appending "-install" to the value of NSAPP.
109
}
1110

1211
NEXTID=$(pvesh get /cluster/nextid)
@@ -16,7 +15,7 @@ header_info(){
1615
}
1716

1817
base_settings() {
19-
18+
# Default Settings
2019
CT_TYPE="1"
2120
DISK_SIZE="4"
2221
CORE_COUNT="1"
@@ -40,14 +39,15 @@ base_settings() {
4039
SSH_AUTHORIZED_KEY=""
4140
TAGS="community-script;"
4241

43-
42+
# Override default settings with variables from ct script
4443
CT_TYPE=${var_unprivileged:-$CT_TYPE}
4544
DISK_SIZE=${var_disk:-$DISK_SIZE}
4645
CORE_COUNT=${var_cpu:-$CORE_COUNT}
4746
RAM_SIZE=${var_ram:-$RAM_SIZE}
4847
VERB=${var_verbose:-$VERBOSE}
4948
TAGS="${TAGS}${var_tags:-}"
5049

50+
# Since these 2 are only defined outside of default_settings function, we add a temporary fallback. TODO: To align everything, we should add these as constant variables (e.g. OSTYPE and OSVERSION), but that would currently require updating the default_settings function for all existing scripts
5151
if [ -z "$var_os" ]; then
5252
var_os="debian"
5353
fi
@@ -112,10 +112,9 @@ error_handler() {
112112
SCRIPT_NAME=$(basename "$0")
113113
local error_message="$SCRIPT_NAME: Failure in line $line_number while executing command $command"
114114
echo -e "\n$error_message"
115-
exit "$error_message"
115+
exit 100
116116
}
117117

118-
119118
msg_info() {
120119
local msg="$1"
121120
echo -ne "${msg}\n"
@@ -136,7 +135,8 @@ start(){
136135
}
137136

138137
build_container() {
139-
138+
# if [ "$VERB" == "yes" ]; then set -x; fi
139+
140140
if [ "$CT_TYPE" == "1" ]; then
141141
FEATURES="keyctl=1,nesting=1"
142142
else

.github/workflows/scripts/app-test/pr-create-lxc.sh

Lines changed: 7 additions & 17 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,6 @@ catch_errors() {
1111
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
1212
}
1313

14-
1514
error_handler() {
1615
local exit_code="$?"
1716
local line_number="$1"
@@ -68,6 +67,7 @@ function select_storage() {
6867
*) false || { msg_error "Invalid storage class."; exit 201; };;
6968
esac
7069

70+
# This Queries all storage locations
7171
local -a MENU
7272
while read -r line; do
7373
local TAG=$(echo $line | awk '{print $1}')
@@ -81,6 +81,7 @@ function select_storage() {
8181
MENU+=("$TAG" "$ITEM" "OFF")
8282
done < <(pvesm status -content $CONTENT | awk 'NR>1')
8383

84+
# Select storage location
8485
if [ $((${#MENU[@]}/3)) -eq 1 ]; then
8586
printf ${MENU[0]}
8687
else
@@ -103,17 +104,12 @@ if pct status $CTID &>/dev/null; then
103104
exit 206
104105
fi
105106

106-
107107
TEMPLATE_STORAGE=$(select_storage template) || exit
108-
msg_ok "Using $TEMPLATE_STORAGE for Template Storage."
109-
110108

111109
CONTAINER_STORAGE=$(select_storage container) || exit
112-
msg_ok "Using $CONTAINER_STORAGE for Container Storage."
113110

114-
msg_info "Updating LXC Template List"
115111
pveam update >/dev/null
116-
msg_ok "Updated LXC Template List"
112+
117113

118114
TEMPLATE_SEARCH=${PCT_OSTYPE}-${PCT_OSVERSION:-}
119115
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V)
@@ -124,35 +120,29 @@ TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
124120

125121
if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then
126122
[[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH"
127-
msg_info "Downloading LXC Template"
128123
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null ||
129124
{ msg_error "A problem occurred while downloading the LXC template."; exit 208; }
130-
msg_ok "Downloaded LXC Template"
131125
fi
132126

133127

134128
grep -q "root:100000:65536" /etc/subuid || echo "root:100000:65536" >> /etc/subuid
135129
grep -q "root:100000:65536" /etc/subgid || echo "root:100000:65536" >> /etc/subgid
136130

137-
138131
PCT_OPTIONS=(${PCT_OPTIONS[@]:-${DEFAULT_PCT_OPTIONS[@]}})
139132
[[ " ${PCT_OPTIONS[@]} " =~ " -rootfs " ]] || PCT_OPTIONS+=(-rootfs "$CONTAINER_STORAGE:${PCT_DISK_SIZE:-8}")
140133

141-
echo "${PCT_OPTIONS[@]}"
142134

143-
144-
msg_info "Creating LXC Container"
145135
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then
146136
[[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH"
147137

148-
msg_ok "Template integrity check completed"
138+
149139
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null ||
150140
{ msg_error "A problem occurred while re-downloading the LXC template."; exit 208; }
151141

152-
msg_ok "Re-downloaded LXC Template"
142+
153143
if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[@]}" &>/dev/null; then
154144
msg_error "A problem occurred while trying to create container after re-downloading template."
155145
exit 200
156146
fi
157147
fi
158-
msg_ok "LXC Container $CTID was successfully created."
148+

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

Lines changed: 11 additions & 12 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,13 +11,14 @@ catch_errors() {
1111
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
1212
}
1313

14+
1415
error_handler() {
1516
local line_number="$1"
1617
local command="$2"
1718
SCRIPT_NAME=$(basename "$0")
1819
local error_message="$SCRIPT_NAME: Failure in line $line_number while executing command $command"
1920
echo -e "\n$error_message"
20-
exit "$error_message"
21+
exit 200
2122
}
2223
verb_ip6() {
2324
STD=""
@@ -39,9 +40,11 @@ msg_error() {
3940
local msg="$1"
4041
echo -e "${msg}\n"
4142
}
42-
RETRY_NUM=10
43-
RETRY_EVERY=3
43+
44+
RETRY_NUM=10
45+
RETRY_EVERY=3
4446
setting_up_container() {
47+
4548
sed -i "/$LANG/ s/\(^# \)//" /etc/locale.gen
4649
locale_line=$(grep -v '^#' /etc/locale.gen | grep -E '^[a-zA-Z]' | awk '{print $1}' | head -n 1)
4750
echo "LANG=${locale_line}" >/etc/default/locale
@@ -54,7 +57,6 @@ setting_up_container() {
5457
if [ "$(hostname -I)" != "" ]; then
5558
break
5659
fi
57-
echo 1>&2 -en "No Network! "
5860
sleep $RETRY_EVERY
5961
done
6062
if [ "$(hostname -I)" = "" ]; then
@@ -64,8 +66,6 @@ setting_up_container() {
6466
fi
6567
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
6668
systemctl disable -q --now systemd-networkd-wait-online.service
67-
msg_ok "Set up Container OS"
68-
msg_ok "Network Connected: $(hostname -I)"
6969
}
7070

7171
network_check() {
@@ -75,11 +75,10 @@ network_check() {
7575
}
7676

7777
update_os() {
78-
msg_info "Updating Container OS"
79-
apt-get update
80-
apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade
81-
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
82-
msg_ok "Updated Container OS"
78+
export DEBIAN_FRONTEND=noninteractive
79+
apt-get update >/dev/null 2>&1
80+
apt-get -o Dpkg::Options::="--force-confold" -y dist-upgrade >/dev/null 2>&1
81+
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
8382
}
8483

8584
motd_ssh() {

0 commit comments

Comments
 (0)