Skip to content

Commit 0104649

Browse files
Bot Updating Templated Files
1 parent c506cf9 commit 0104649

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

0 commit comments

Comments
 (0)