Skip to content

Commit 582b250

Browse files
Bot Updating Templated Files
1 parent 773c6cb commit 582b250

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

0 commit comments

Comments
 (0)