Skip to content

Commit 44141ac

Browse files
Bot Updating Templated Files
1 parent 78a540f commit 44141ac

1 file changed

Lines changed: 85 additions & 87 deletions

File tree

Jenkinsfile

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

0 commit comments

Comments
 (0)