Skip to content

Commit 1aa37ff

Browse files
Bot Updating Templated Files
1 parent beec72b commit 1aa37ff

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

0 commit comments

Comments
 (0)