Skip to content

Commit fabeb1f

Browse files
Bot Updating Templated Files
1 parent b0cf187 commit fabeb1f

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

0 commit comments

Comments
 (0)