Skip to content

Commit 7cccfdb

Browse files
Bot Updating Templated Files
1 parent 3ca0a98 commit 7cccfdb

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

0 commit comments

Comments
 (0)