Skip to content

Commit a1263d6

Browse files
Bot Updating Templated Files
1 parent 3486338 commit a1263d6

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

0 commit comments

Comments
 (0)