Skip to content

Commit 760df2f

Browse files
Bot Updating Templated Files
1 parent d4ec6de commit 760df2f

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
@@ -75,6 +75,7 @@ pipeline {
7575
'''
7676
script{
7777
env.EXIT_STATUS = ''
78+
env.CI_TEST_ATTEMPTED = ''
7879
env.LS_RELEASE = sh(
7980
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:ubuntu-mate 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
8081
returnStdout: true).trim()
@@ -806,6 +807,7 @@ pipeline {
806807
script{
807808
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
808809
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
810+
env.CI_TEST_ATTEMPTED = 'true'
809811
}
810812
sh '''#! /bin/bash
811813
set -e
@@ -1008,98 +1010,13 @@ EOF
10081010
) '''
10091011
}
10101012
}
1011-
// If this is a Pull request send the CI link as a comment on it
1012-
stage('Pull Request Comment') {
1013-
when {
1014-
not {environment name: 'CHANGE_ID', value: ''}
1015-
environment name: 'EXIT_STATUS', value: ''
1016-
}
1017-
steps {
1018-
sh '''#! /bin/bash
1019-
# Function to retrieve JSON data from URL
1020-
get_json() {
1021-
local url="$1"
1022-
local response=$(curl -s "$url")
1023-
if [ $? -ne 0 ]; then
1024-
echo "Failed to retrieve JSON data from $url"
1025-
return 1
1026-
fi
1027-
local json=$(echo "$response" | jq .)
1028-
if [ $? -ne 0 ]; then
1029-
echo "Failed to parse JSON data from $url"
1030-
return 1
1031-
fi
1032-
echo "$json"
1033-
}
1034-
1035-
build_table() {
1036-
local data="$1"
1037-
1038-
# Get the keys in the JSON data
1039-
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1040-
1041-
# Check if keys are empty
1042-
if [ -z "$keys" ]; then
1043-
echo "JSON report data does not contain any keys or the report does not exist."
1044-
return 1
1045-
fi
1046-
1047-
# Build table header
1048-
local header="| Tag | Passed |\\n| --- | --- |\\n"
1049-
1050-
# Loop through the JSON data to build the table rows
1051-
local rows=""
1052-
for build in $keys; do
1053-
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1054-
if [ "$status" = "true" ]; then
1055-
status="✅"
1056-
else
1057-
status="❌"
1058-
fi
1059-
local row="| "$build" | "$status" |\\n"
1060-
rows="${rows}${row}"
1061-
done
1062-
1063-
local table="${header}${rows}"
1064-
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1065-
echo "$escaped_table"
1066-
}
1067-
1068-
if [[ "${CI}" = "true" ]]; then
1069-
# Retrieve JSON data from URL
1070-
data=$(get_json "$CI_JSON_URL")
1071-
# Create table from JSON data
1072-
table=$(build_table "$data")
1073-
echo -e "$table"
1074-
1075-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1076-
-H "Accept: application/vnd.github.v3+json" \
1077-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1078-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1079-
else
1080-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1081-
-H "Accept: application/vnd.github.v3+json" \
1082-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1083-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1084-
fi
1085-
'''
1086-
1087-
}
1088-
}
10891013
}
10901014
/* ######################
1091-
Send status to Discord
1015+
Comment on PR and Send status to Discord
10921016
###################### */
10931017
post {
10941018
always {
1095-
sh '''#!/bin/bash
1096-
rm -rf /config/.ssh/id_sign
1097-
rm -rf /config/.ssh/id_sign.pub
1098-
git config --global --unset gpg.format
1099-
git config --global --unset user.signingkey
1100-
git config --global --unset commit.gpgsign
1101-
'''
1102-
script{
1019+
script {
11031020
env.JOB_DATE = sh(
11041021
script: '''date '+%Y-%m-%dT%H:%M:%S%:z' ''',
11051022
returnStdout: true).trim()
@@ -1142,6 +1059,87 @@ EOF
11421059
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
11431060
}
11441061
}
1062+
script {
1063+
if (env.GITHUBIMAGE =~ /lspipepr/){
1064+
if (env.CI_TEST_ATTEMPTED == "true"){
1065+
sh '''#! /bin/bash
1066+
# Function to retrieve JSON data from URL
1067+
get_json() {
1068+
local url="$1"
1069+
local response=$(curl -s "$url")
1070+
if [ $? -ne 0 ]; then
1071+
echo "Failed to retrieve JSON data from $url"
1072+
return 1
1073+
fi
1074+
local json=$(echo "$response" | jq .)
1075+
if [ $? -ne 0 ]; then
1076+
echo "Failed to parse JSON data from $url"
1077+
return 1
1078+
fi
1079+
echo "$json"
1080+
}
1081+
1082+
build_table() {
1083+
local data="$1"
1084+
1085+
# Get the keys in the JSON data
1086+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1087+
1088+
# Check if keys are empty
1089+
if [ -z "$keys" ]; then
1090+
echo "JSON report data does not contain any keys or the report does not exist."
1091+
return 1
1092+
fi
1093+
1094+
# Build table header
1095+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1096+
1097+
# Loop through the JSON data to build the table rows
1098+
local rows=""
1099+
for build in $keys; do
1100+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1101+
if [ "$status" = "true" ]; then
1102+
status="✅"
1103+
else
1104+
status="❌"
1105+
fi
1106+
local row="| "$build" | "$status" |\\n"
1107+
rows="${rows}${row}"
1108+
done
1109+
1110+
local table="${header}${rows}"
1111+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1112+
echo "$escaped_table"
1113+
}
1114+
1115+
if [[ "${CI}" = "true" ]]; then
1116+
# Retrieve JSON data from URL
1117+
data=$(get_json "$CI_JSON_URL")
1118+
# Create table from JSON data
1119+
table=$(build_table "$data")
1120+
echo -e "$table"
1121+
1122+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1123+
-H "Accept: application/vnd.github.v3+json" \
1124+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1125+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1126+
else
1127+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1128+
-H "Accept: application/vnd.github.v3+json" \
1129+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1130+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1131+
fi
1132+
'''
1133+
}
1134+
}
1135+
}
1136+
sh '''#!/bin/bash
1137+
rm -rf /config/.ssh/id_sign
1138+
rm -rf /config/.ssh/id_sign.pub
1139+
git config --global --unset gpg.format
1140+
git config --global --unset user.signingkey
1141+
git config --global --unset commit.gpgsign
1142+
'''
11451143
}
11461144
cleanup {
11471145
sh '''#! /bin/bash

0 commit comments

Comments
 (0)