Skip to content

Commit 2ac7f00

Browse files
Bot Updating Templated Files
1 parent 651cf60 commit 2ac7f00

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
@@ -69,6 +69,7 @@ pipeline {
6969
'''
7070
script{
7171
env.EXIT_STATUS = ''
72+
env.CI_TEST_ATTEMPTED = ''
7273
env.LS_RELEASE = sh(
7374
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' || : ''',
7475
returnStdout: true).trim()
@@ -801,6 +802,7 @@ pipeline {
801802
script{
802803
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
803804
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
805+
env.CI_TEST_ATTEMPTED = 'true'
804806
}
805807
sh '''#! /bin/bash
806808
set -e
@@ -1002,98 +1004,13 @@ EOF
10021004
) '''
10031005
}
10041006
}
1005-
// If this is a Pull request send the CI link as a comment on it
1006-
stage('Pull Request Comment') {
1007-
when {
1008-
not {environment name: 'CHANGE_ID', value: ''}
1009-
environment name: 'EXIT_STATUS', value: ''
1010-
}
1011-
steps {
1012-
sh '''#! /bin/bash
1013-
# Function to retrieve JSON data from URL
1014-
get_json() {
1015-
local url="$1"
1016-
local response=$(curl -s "$url")
1017-
if [ $? -ne 0 ]; then
1018-
echo "Failed to retrieve JSON data from $url"
1019-
return 1
1020-
fi
1021-
local json=$(echo "$response" | jq .)
1022-
if [ $? -ne 0 ]; then
1023-
echo "Failed to parse JSON data from $url"
1024-
return 1
1025-
fi
1026-
echo "$json"
1027-
}
1028-
1029-
build_table() {
1030-
local data="$1"
1031-
1032-
# Get the keys in the JSON data
1033-
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1034-
1035-
# Check if keys are empty
1036-
if [ -z "$keys" ]; then
1037-
echo "JSON report data does not contain any keys or the report does not exist."
1038-
return 1
1039-
fi
1040-
1041-
# Build table header
1042-
local header="| Tag | Passed |\\n| --- | --- |\\n"
1043-
1044-
# Loop through the JSON data to build the table rows
1045-
local rows=""
1046-
for build in $keys; do
1047-
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1048-
if [ "$status" = "true" ]; then
1049-
status="✅"
1050-
else
1051-
status="❌"
1052-
fi
1053-
local row="| "$build" | "$status" |\\n"
1054-
rows="${rows}${row}"
1055-
done
1056-
1057-
local table="${header}${rows}"
1058-
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1059-
echo "$escaped_table"
1060-
}
1061-
1062-
if [[ "${CI}" = "true" ]]; then
1063-
# Retrieve JSON data from URL
1064-
data=$(get_json "$CI_JSON_URL")
1065-
# Create table from JSON data
1066-
table=$(build_table "$data")
1067-
echo -e "$table"
1068-
1069-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1070-
-H "Accept: application/vnd.github.v3+json" \
1071-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1072-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1073-
else
1074-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1075-
-H "Accept: application/vnd.github.v3+json" \
1076-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1077-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1078-
fi
1079-
'''
1080-
1081-
}
1082-
}
10831007
}
10841008
/* ######################
1085-
Send status to Discord
1009+
Comment on PR and Send status to Discord
10861010
###################### */
10871011
post {
10881012
always {
1089-
sh '''#!/bin/bash
1090-
rm -rf /config/.ssh/id_sign
1091-
rm -rf /config/.ssh/id_sign.pub
1092-
git config --global --unset gpg.format
1093-
git config --global --unset user.signingkey
1094-
git config --global --unset commit.gpgsign
1095-
'''
1096-
script{
1013+
script {
10971014
env.JOB_DATE = sh(
10981015
script: '''date '+%Y-%m-%dT%H:%M:%S%:z' ''',
10991016
returnStdout: true).trim()
@@ -1136,6 +1053,87 @@ EOF
11361053
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
11371054
}
11381055
}
1056+
script {
1057+
if (env.GITHUBIMAGE =~ /lspipepr/){
1058+
if (env.CI_TEST_ATTEMPTED == "true"){
1059+
sh '''#! /bin/bash
1060+
# Function to retrieve JSON data from URL
1061+
get_json() {
1062+
local url="$1"
1063+
local response=$(curl -s "$url")
1064+
if [ $? -ne 0 ]; then
1065+
echo "Failed to retrieve JSON data from $url"
1066+
return 1
1067+
fi
1068+
local json=$(echo "$response" | jq .)
1069+
if [ $? -ne 0 ]; then
1070+
echo "Failed to parse JSON data from $url"
1071+
return 1
1072+
fi
1073+
echo "$json"
1074+
}
1075+
1076+
build_table() {
1077+
local data="$1"
1078+
1079+
# Get the keys in the JSON data
1080+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1081+
1082+
# Check if keys are empty
1083+
if [ -z "$keys" ]; then
1084+
echo "JSON report data does not contain any keys or the report does not exist."
1085+
return 1
1086+
fi
1087+
1088+
# Build table header
1089+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1090+
1091+
# Loop through the JSON data to build the table rows
1092+
local rows=""
1093+
for build in $keys; do
1094+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1095+
if [ "$status" = "true" ]; then
1096+
status="✅"
1097+
else
1098+
status="❌"
1099+
fi
1100+
local row="| "$build" | "$status" |\\n"
1101+
rows="${rows}${row}"
1102+
done
1103+
1104+
local table="${header}${rows}"
1105+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1106+
echo "$escaped_table"
1107+
}
1108+
1109+
if [[ "${CI}" = "true" ]]; then
1110+
# Retrieve JSON data from URL
1111+
data=$(get_json "$CI_JSON_URL")
1112+
# Create table from JSON data
1113+
table=$(build_table "$data")
1114+
echo -e "$table"
1115+
1116+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1117+
-H "Accept: application/vnd.github.v3+json" \
1118+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1119+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1120+
else
1121+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1122+
-H "Accept: application/vnd.github.v3+json" \
1123+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1124+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1125+
fi
1126+
'''
1127+
}
1128+
}
1129+
}
1130+
sh '''#!/bin/bash
1131+
rm -rf /config/.ssh/id_sign
1132+
rm -rf /config/.ssh/id_sign.pub
1133+
git config --global --unset gpg.format
1134+
git config --global --unset user.signingkey
1135+
git config --global --unset commit.gpgsign
1136+
'''
11391137
}
11401138
cleanup {
11411139
sh '''#! /bin/bash

0 commit comments

Comments
 (0)