11name : Run Scripts on PVE Node for testing
22permissions :
3- pull-requests : write
3+ pull-requests : write
44on :
55 pull_request_target :
66 branches :
77 - main
88 paths :
9- - ' install/**.sh'
10- - ' ct/**.sh'
9+ - " install/**.sh"
10+ - " ct/**.sh"
1111
1212jobs :
1313 run-install-script :
1414 runs-on : pvenode
15- steps :
15+ steps :
1616 - name : Checkout PR branch
1717 uses : actions/checkout@v4
1818 with :
1919 ref : ${{ github.event.pull_request.head.ref }}
2020 repository : ${{ github.event.pull_request.head.repo.full_name }}
21- fetch-depth : 0
22-
21+ fetch-depth : 0
22+
2323 - name : Add Git safe directory
2424 run : |
2525 git config --global --add safe.directory /__w/ProxmoxVE/ProxmoxVE
26-
26+
2727 - name : Set up GH_TOKEN
2828 env :
2929 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3838 echo "SCRIPT=$CHANGED_FILES" >> $GITHUB_ENV
3939 env :
4040 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
41-
4241
4342 - name : Get scripts
4443 id : check-install-script
@@ -57,108 +56,108 @@ jobs:
5756 ALL_FILES=$(echo "${ALL_FILES[@]}" | xargs)
5857 echo "$ALL_FILES"
5958 echo "ALL_FILES=$ALL_FILES" >> $GITHUB_ENV
60-
59+
6160 - name : Run scripts
6261 id : run-install
6362 continue-on-error : true
6463 run : |
65- set +e
66- #run for each files in /ct
67- for FILE in ${{ env.ALL_FILES }}; do
68- STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
69- echo "Running Test for: $STRIPPED_NAME"
70- if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "$FILE"; then
71- echo "The script contains an interactive prompt. Skipping execution."
64+ set +e
65+ #run for each files in /ct
66+ for FILE in ${{ env.ALL_FILES }}; do
67+ STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
68+ echo "Running Test for: $STRIPPED_NAME"
69+ if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "$FILE"; then
70+ echo "The script contains an interactive prompt. Skipping execution."
71+ continue
72+ fi
73+ if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
74+ CT_SCRIPT="ct/$STRIPPED_NAME.sh"
75+ if [[ ! -f $CT_SCRIPT ]]; then
76+ echo "No CT script found for $STRIPPED_NAME"
77+ ERROR_MSG="No CT script found for $FILE"
78+ echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
7279 continue
7380 fi
74- if [[ $FILE =~ ^install/.*-install\.sh$ ]]; then
75- CT_SCRIPT="ct/$STRIPPED_NAME.sh"
76- if [[ ! -f $CT_SCRIPT ]]; then
77- echo "No CT script found for $STRIPPED_NAME"
78- ERROR_MSG="No CT script found for $FILE"
79- echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
81+ if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "install/$STRIPPED_NAME-install.sh"; then
82+ echo "The script contains an interactive prompt. Skipping execution."
8083 continue
8184 fi
82- if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "install/$STRIPPED_NAME-install.sh"; then
83- echo "The script contains an interactive prompt. Skipping execution."
84- continue
85- fi
86- echo "Found CT script for $STRIPPED_NAME"
87- chmod +x "$CT_SCRIPT"
88- RUNNING_FILE=$CT_SCRIPT
89- elif [[ $FILE =~ ^ct/.*\.sh$ ]]; then
90- INSTALL_SCRIPT="install/$STRIPPED_NAME-install.sh"
91- if [[ ! -f $INSTALL_SCRIPT ]]; then
92- echo "No install script found for $STRIPPED_NAME"
93- ERROR_MSG="No install script found for $FILE"
94- echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
95- continue
96- fi
97- echo "Found install script for $STRIPPED_NAME"
98- chmod +x "$INSTALL_SCRIPT"
99- RUNNING_FILE=$FILE
100- if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "ct/$STRIPPED_NAME.sh"; then
101- echo "The script contains an interactive prompt. Skipping execution."
102- continue
103- fi
104- fi
105- git remote add community-scripts https://github.com/community-scripts/ProxmoxVE.git
106- git fetch community-scripts
107- rm -f .github/workflows/scripts/app-test/pr-build.func || true
108- rm -f .github/workflows/scripts/app-test/pr-install.func || true
109- rm -f .github/workflows/scripts/app-test/pr-alpine-install.func || true
110- rm -f .github/workflows/scripts/app-test/pr-create-lxc.sh || true
111- git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-build.func
112- git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-install.func
113- git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-alpine-install.func
114- git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-create-lxc.sh
115- chmod +x $RUNNING_FILE
116- chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
117- chmod +x .github/workflows/scripts/app-test/pr-install.func
118- chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
119- chmod +x .github/workflows/scripts/app-test/pr-build.func
120- 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"
121- echo "Executing $RUNNING_FILE"
122- ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
123- echo "Finished running $FILE"
124- if [ -n "$ERROR_MSG" ]; then
125- echo "ERROR in $STRIPPED_NAME: $ERROR_MSG"
85+ echo "Found CT script for $STRIPPED_NAME"
86+ chmod +x "$CT_SCRIPT"
87+ RUNNING_FILE=$CT_SCRIPT
88+ elif [[ $FILE =~ ^ct/.*\.sh$ ]]; then
89+ INSTALL_SCRIPT="install/$STRIPPED_NAME-install.sh"
90+ if [[ ! -f $INSTALL_SCRIPT ]]; then
91+ echo "No install script found for $STRIPPED_NAME"
92+ ERROR_MSG="No install script found for $FILE"
12693 echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
127- fi
128- done
129- set -e # Restore exit-on-error
130-
94+ continue
95+ fi
96+ echo "Found install script for $STRIPPED_NAME"
97+ chmod +x "$INSTALL_SCRIPT"
98+ RUNNING_FILE=$FILE
99+ if grep -E -q 'read\s+-r\s+-p\s+".*"\s+\w+' "ct/$STRIPPED_NAME.sh"; then
100+ echo "The script contains an interactive prompt. Skipping execution."
101+ continue
102+ fi
103+ fi
104+ git remote add community-scripts https://github.com/community-scripts/ProxmoxVE.git
105+ git fetch community-scripts
106+ rm -f .github/workflows/scripts/app-test/pr-build.func || true
107+ rm -f .github/workflows/scripts/app-test/pr-install.func || true
108+ rm -f .github/workflows/scripts/app-test/pr-alpine-install.func || true
109+ rm -f .github/workflows/scripts/app-test/pr-create-lxc.sh || true
110+ git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-build.func
111+ git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-install.func
112+ git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-alpine-install.func
113+ git checkout community-scripts/main -- .github/workflows/scripts/app-test/pr-create-lxc.sh
114+ chmod +x $RUNNING_FILE
115+ chmod +x .github/workflows/scripts/app-test/pr-create-lxc.sh
116+ chmod +x .github/workflows/scripts/app-test/pr-install.func
117+ chmod +x .github/workflows/scripts/app-test/pr-alpine-install.func
118+ chmod +x .github/workflows/scripts/app-test/pr-build.func
119+ sed -i 's|source <(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc/build.func)|source .github/workflows/scripts/app-test/pr-build.func|g' "$RUNNING_FILE"
120+ echo "Executing $RUNNING_FILE"
121+ ERROR_MSG=$(./$RUNNING_FILE 2>&1 > /dev/null)
122+ echo "Finished running $FILE"
123+ if [ -n "$ERROR_MSG" ]; then
124+ echo "ERROR in $STRIPPED_NAME: $ERROR_MSG"
125+ echo "$ERROR_MSG" > result_$STRIPPED_NAME.log
126+ fi
127+ done
128+ set -e # Restore exit-on-error
129+
131130 - name : Cleanup PVE Node
132131 run : |
133132 containers=$(pct list | tail -n +2 | awk '{print $0 " " $4}' | awk '{print $1}')
134-
133+
135134 for container_id in $containers; do
136135 status=$(pct status $container_id | awk '{print $2}')
137136 if [[ $status == "running" ]]; then
138137 pct stop $container_id
139138 pct destroy $container_id
140139 fi
141140 done
142-
141+
143142 - name : Post error comments
144143 run : |
145144 ERROR="false"
146145 SEARCH_LINE=".github/workflows/scripts/app-test/pr-build.func: line 255:"
147-
146+
148147 # Get all existing comments on the PR
149148 EXISTING_COMMENTS=$(gh pr view ${{ github.event.pull_request.number }} --repo ${{ github.repository }} --json comments --jq '.comments[].body')
150-
149+
151150 for FILE in ${{ env.ALL_FILES }}; do
152151 STRIPPED_NAME=$(basename "$FILE" | sed 's/-install//' | sed 's/\.sh$//')
153152 if [[ ! -f result_$STRIPPED_NAME.log ]]; then
154153 continue
155154 fi
156155 ERROR_MSG=$(cat result_$STRIPPED_NAME.log)
157-
156+
158157 if [ -n "$ERROR_MSG" ]; then
159158 CLEANED_ERROR_MSG=$(echo "$ERROR_MSG" | sed "s|$SEARCH_LINE.*||")
160159 COMMENT_BODY=":warning: The script _**$FILE**_ failed with the following message: <br> <div><strong>${CLEANED_ERROR_MSG}</strong></div>"
161-
160+
162161 # Check if the comment already exists
163162 if echo "$EXISTING_COMMENTS" | grep -qF "$COMMENT_BODY"; then
164163 echo "Skipping duplicate comment for $FILE"
@@ -171,7 +170,5 @@ jobs:
171170 fi
172171 fi
173172 done
174-
173+
175174 echo "ERROR=$ERROR" >> $GITHUB_ENV
176-
177-
0 commit comments