Skip to content

Commit cf53766

Browse files
Bot Updating Templated Files
1 parent 1fb9c50 commit cf53766

File tree

1 file changed

+85
-87
lines changed

1 file changed

+85
-87
lines changed

Jenkinsfile

Lines changed: 85 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pipeline {
8080
'''
8181
script{
8282
env.EXIT_STATUS = ''
83+
env.CI_TEST_ATTEMPTED = ''
8384
env.LS_RELEASE = sh(
8485
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:develop 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
8586
returnStdout: true).trim()
@@ -876,6 +877,7 @@ pipeline {
876877
script{
877878
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
878879
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
880+
env.CI_TEST_ATTEMPTED = 'true'
879881
}
880882
sh '''#! /bin/bash
881883
set -e
@@ -1078,98 +1080,13 @@ EOF
10781080
) '''
10791081
}
10801082
}
1081-
// If this is a Pull request send the CI link as a comment on it
1082-
stage('Pull Request Comment') {
1083-
when {
1084-
not {environment name: 'CHANGE_ID', value: ''}
1085-
environment name: 'EXIT_STATUS', value: ''
1086-
}
1087-
steps {
1088-
sh '''#! /bin/bash
1089-
# Function to retrieve JSON data from URL
1090-
get_json() {
1091-
local url="$1"
1092-
local response=$(curl -s "$url")
1093-
if [ $? -ne 0 ]; then
1094-
echo "Failed to retrieve JSON data from $url"
1095-
return 1
1096-
fi
1097-
local json=$(echo "$response" | jq .)
1098-
if [ $? -ne 0 ]; then
1099-
echo "Failed to parse JSON data from $url"
1100-
return 1
1101-
fi
1102-
echo "$json"
1103-
}
1104-
1105-
build_table() {
1106-
local data="$1"
1107-
1108-
# Get the keys in the JSON data
1109-
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1110-
1111-
# Check if keys are empty
1112-
if [ -z "$keys" ]; then
1113-
echo "JSON report data does not contain any keys or the report does not exist."
1114-
return 1
1115-
fi
1116-
1117-
# Build table header
1118-
local header="| Tag | Passed |\\n| --- | --- |\\n"
1119-
1120-
# Loop through the JSON data to build the table rows
1121-
local rows=""
1122-
for build in $keys; do
1123-
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1124-
if [ "$status" = "true" ]; then
1125-
status="✅"
1126-
else
1127-
status="❌"
1128-
fi
1129-
local row="| "$build" | "$status" |\\n"
1130-
rows="${rows}${row}"
1131-
done
1132-
1133-
local table="${header}${rows}"
1134-
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1135-
echo "$escaped_table"
1136-
}
1137-
1138-
if [[ "${CI}" = "true" ]]; then
1139-
# Retrieve JSON data from URL
1140-
data=$(get_json "$CI_JSON_URL")
1141-
# Create table from JSON data
1142-
table=$(build_table "$data")
1143-
echo -e "$table"
1144-
1145-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1146-
-H "Accept: application/vnd.github.v3+json" \
1147-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1148-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1149-
else
1150-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1151-
-H "Accept: application/vnd.github.v3+json" \
1152-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1153-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1154-
fi
1155-
'''
1156-
1157-
}
1158-
}
11591083
}
11601084
/* ######################
1161-
Send status to Discord
1085+
Comment on PR and Send status to Discord
11621086
###################### */
11631087
post {
11641088
always {
1165-
sh '''#!/bin/bash
1166-
rm -rf /config/.ssh/id_sign
1167-
rm -rf /config/.ssh/id_sign.pub
1168-
git config --global --unset gpg.format
1169-
git config --global --unset user.signingkey
1170-
git config --global --unset commit.gpgsign
1171-
'''
1172-
script{
1089+
script {
11731090
env.JOB_DATE = sh(
11741091
script: '''date '+%Y-%m-%dT%H:%M:%S%:z' ''',
11751092
returnStdout: true).trim()
@@ -1212,6 +1129,87 @@ EOF
12121129
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
12131130
}
12141131
}
1132+
script {
1133+
if (env.GITHUBIMAGE =~ /lspipepr/){
1134+
if (env.CI_TEST_ATTEMPTED == "true"){
1135+
sh '''#! /bin/bash
1136+
# Function to retrieve JSON data from URL
1137+
get_json() {
1138+
local url="$1"
1139+
local response=$(curl -s "$url")
1140+
if [ $? -ne 0 ]; then
1141+
echo "Failed to retrieve JSON data from $url"
1142+
return 1
1143+
fi
1144+
local json=$(echo "$response" | jq .)
1145+
if [ $? -ne 0 ]; then
1146+
echo "Failed to parse JSON data from $url"
1147+
return 1
1148+
fi
1149+
echo "$json"
1150+
}
1151+
1152+
build_table() {
1153+
local data="$1"
1154+
1155+
# Get the keys in the JSON data
1156+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1157+
1158+
# Check if keys are empty
1159+
if [ -z "$keys" ]; then
1160+
echo "JSON report data does not contain any keys or the report does not exist."
1161+
return 1
1162+
fi
1163+
1164+
# Build table header
1165+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1166+
1167+
# Loop through the JSON data to build the table rows
1168+
local rows=""
1169+
for build in $keys; do
1170+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1171+
if [ "$status" = "true" ]; then
1172+
status="✅"
1173+
else
1174+
status="❌"
1175+
fi
1176+
local row="| "$build" | "$status" |\\n"
1177+
rows="${rows}${row}"
1178+
done
1179+
1180+
local table="${header}${rows}"
1181+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1182+
echo "$escaped_table"
1183+
}
1184+
1185+
if [[ "${CI}" = "true" ]]; then
1186+
# Retrieve JSON data from URL
1187+
data=$(get_json "$CI_JSON_URL")
1188+
# Create table from JSON data
1189+
table=$(build_table "$data")
1190+
echo -e "$table"
1191+
1192+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1193+
-H "Accept: application/vnd.github.v3+json" \
1194+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1195+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1196+
else
1197+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1198+
-H "Accept: application/vnd.github.v3+json" \
1199+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1200+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1201+
fi
1202+
'''
1203+
}
1204+
}
1205+
}
1206+
sh '''#!/bin/bash
1207+
rm -rf /config/.ssh/id_sign
1208+
rm -rf /config/.ssh/id_sign.pub
1209+
git config --global --unset gpg.format
1210+
git config --global --unset user.signingkey
1211+
git config --global --unset commit.gpgsign
1212+
'''
12151213
}
12161214
cleanup {
12171215
sh '''#! /bin/bash

0 commit comments

Comments
 (0)