Skip to content

Commit 9c3e987

Browse files
Bot Updating Templated Files
1 parent c30ce08 commit 9c3e987

1 file changed

Lines changed: 105 additions & 89 deletions

File tree

Jenkinsfile

Lines changed: 105 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pipeline {
7575
'''
7676
script{
7777
env.EXIT_STATUS = ''
78+
env.CI_TEST_ATTEMPTED = ''
79+
env.PUSH_ATTEMPTED = ''
7880
env.LS_RELEASE = sh(
7981
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:alpine322 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
8082
returnStdout: true).trim()
@@ -283,7 +285,7 @@ pipeline {
283285
-v ${WORKSPACE}:/mnt \
284286
-e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \
285287
-e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \
286-
ghcr.io/linuxserver/baseimage-alpine:3 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
288+
ghcr.io/linuxserver/baseimage-alpine:3.23 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
287289
apk add --no-cache python3 && \
288290
python3 -m venv /lsiopy && \
289291
pip install --no-cache-dir -U pip && \
@@ -728,6 +730,7 @@ pipeline {
728730
script{
729731
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
730732
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
733+
env.CI_TEST_ATTEMPTED = 'true'
731734
}
732735
sh '''#! /bin/bash
733736
set -e
@@ -780,6 +783,9 @@ pipeline {
780783
environment name: 'EXIT_STATUS', value: ''
781784
}
782785
steps {
786+
script{
787+
env.PUSH_ATTEMPTED = 'true'
788+
}
783789
retry_backoff(5,5) {
784790
sh '''#! /bin/bash
785791
set -e
@@ -809,11 +815,18 @@ pipeline {
809815
environment name: 'EXIT_STATUS', value: ''
810816
}
811817
steps {
818+
script{
819+
env.PUSH_ATTEMPTED = 'true'
820+
}
812821
retry_backoff(5,5) {
813822
sh '''#! /bin/bash
814823
set -e
815824
for MANIFESTIMAGE in "${IMAGE}" "${GITLABIMAGE}" "${GITHUBIMAGE}" "${QUAYIMAGE}"; do
816-
[[ ${MANIFESTIMAGE%%/*} =~ \\. ]] && MANIFESTIMAGEPLUS="${MANIFESTIMAGE}" || MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
825+
if [[ "${MANIFESTIMAGE%%/*}" =~ \\. ]]; then
826+
MANIFESTIMAGEPLUS="${MANIFESTIMAGE}"
827+
else
828+
MANIFESTIMAGEPLUS="docker.io/${MANIFESTIMAGE}"
829+
fi
817830
IFS=',' read -ra CACHE <<< "$BUILDCACHE"
818831
for i in "${CACHE[@]}"; do
819832
if [[ "${MANIFESTIMAGEPLUS}" == "$(cut -d "/" -f1 <<< ${i})"* ]]; then
@@ -930,98 +943,13 @@ EOF
930943
) '''
931944
}
932945
}
933-
// If this is a Pull request send the CI link as a comment on it
934-
stage('Pull Request Comment') {
935-
when {
936-
not {environment name: 'CHANGE_ID', value: ''}
937-
environment name: 'EXIT_STATUS', value: ''
938-
}
939-
steps {
940-
sh '''#! /bin/bash
941-
# Function to retrieve JSON data from URL
942-
get_json() {
943-
local url="$1"
944-
local response=$(curl -s "$url")
945-
if [ $? -ne 0 ]; then
946-
echo "Failed to retrieve JSON data from $url"
947-
return 1
948-
fi
949-
local json=$(echo "$response" | jq .)
950-
if [ $? -ne 0 ]; then
951-
echo "Failed to parse JSON data from $url"
952-
return 1
953-
fi
954-
echo "$json"
955-
}
956-
957-
build_table() {
958-
local data="$1"
959-
960-
# Get the keys in the JSON data
961-
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
962-
963-
# Check if keys are empty
964-
if [ -z "$keys" ]; then
965-
echo "JSON report data does not contain any keys or the report does not exist."
966-
return 1
967-
fi
968-
969-
# Build table header
970-
local header="| Tag | Passed |\\n| --- | --- |\\n"
971-
972-
# Loop through the JSON data to build the table rows
973-
local rows=""
974-
for build in $keys; do
975-
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
976-
if [ "$status" = "true" ]; then
977-
status="✅"
978-
else
979-
status="❌"
980-
fi
981-
local row="| "$build" | "$status" |\\n"
982-
rows="${rows}${row}"
983-
done
984-
985-
local table="${header}${rows}"
986-
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
987-
echo "$escaped_table"
988-
}
989-
990-
if [[ "${CI}" = "true" ]]; then
991-
# Retrieve JSON data from URL
992-
data=$(get_json "$CI_JSON_URL")
993-
# Create table from JSON data
994-
table=$(build_table "$data")
995-
echo -e "$table"
996-
997-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
998-
-H "Accept: application/vnd.github.v3+json" \
999-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1000-
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1001-
else
1002-
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1003-
-H "Accept: application/vnd.github.v3+json" \
1004-
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1005-
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR: \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1006-
fi
1007-
'''
1008-
1009-
}
1010-
}
1011946
}
1012947
/* ######################
1013-
Send status to Discord
948+
Comment on PR and Send status to Discord
1014949
###################### */
1015950
post {
1016951
always {
1017-
sh '''#!/bin/bash
1018-
rm -rf /config/.ssh/id_sign
1019-
rm -rf /config/.ssh/id_sign.pub
1020-
git config --global --unset gpg.format
1021-
git config --global --unset user.signingkey
1022-
git config --global --unset commit.gpgsign
1023-
'''
1024-
script{
952+
script {
1025953
env.JOB_DATE = sh(
1026954
script: '''date '+%Y-%m-%dT%H:%M:%S%:z' ''',
1027955
returnStdout: true).trim()
@@ -1064,6 +992,94 @@ EOF
1064992
"username": "Jenkins"}' ${BUILDS_DISCORD} '''
1065993
}
1066994
}
995+
script {
996+
if (env.GITHUBIMAGE =~ /lspipepr/){
997+
if (env.CI_TEST_ATTEMPTED == "true" || env.PUSH_ATTEMPTED == "true"){
998+
sh '''#! /bin/bash
999+
# Function to retrieve JSON data from URL
1000+
get_json() {
1001+
local url="$1"
1002+
local response=$(curl -s "$url")
1003+
if [ $? -ne 0 ]; then
1004+
echo "Failed to retrieve JSON data from $url"
1005+
return 1
1006+
fi
1007+
local json=$(echo "$response" | jq .)
1008+
if [ $? -ne 0 ]; then
1009+
echo "Failed to parse JSON data from $url"
1010+
return 1
1011+
fi
1012+
echo "$json"
1013+
}
1014+
1015+
build_table() {
1016+
local data="$1"
1017+
1018+
# Get the keys in the JSON data
1019+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1020+
1021+
# Check if keys are empty
1022+
if [ -z "$keys" ]; then
1023+
echo "JSON report data does not contain any keys or the report does not exist."
1024+
return 1
1025+
fi
1026+
1027+
# Build table header
1028+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1029+
1030+
# Loop through the JSON data to build the table rows
1031+
local rows=""
1032+
for build in $keys; do
1033+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1034+
if [ "$status" = "true" ]; then
1035+
status="✅"
1036+
else
1037+
status="❌"
1038+
fi
1039+
local row="| "$build" | "$status" |\\n"
1040+
rows="${rows}${row}"
1041+
done
1042+
1043+
local table="${header}${rows}"
1044+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1045+
echo "$escaped_table"
1046+
}
1047+
1048+
if [[ "${CI}" = "true" ]]; then
1049+
# Retrieve JSON data from URL
1050+
data=$(get_json "$CI_JSON_URL")
1051+
# Create table from JSON data
1052+
table=$(build_table "$data")
1053+
echo -e "$table"
1054+
1055+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1056+
-H "Accept: application/vnd.github.v3+json" \
1057+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1058+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR for commit ${COMMIT_SHA:0:7} : \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"
1059+
else
1060+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1061+
-H "Accept: application/vnd.github.v3+json" \
1062+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1063+
-d "{\\"body\\": \\"I am a bot, here is the pushed image/manifest for this PR for commit ${COMMIT_SHA:0:7} : \\n\\n\\`${GITHUBIMAGE}:${META_TAG}\\`\\"}"
1064+
fi
1065+
'''
1066+
} else {
1067+
sh '''#! /bin/bash
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, the build for PR commit ${COMMIT_SHA:0:7} failed and as a result no CI test was attempted and no images were pushed.\\"}"
1072+
'''
1073+
}
1074+
}
1075+
}
1076+
sh '''#!/bin/bash
1077+
rm -rf /config/.ssh/id_sign
1078+
rm -rf /config/.ssh/id_sign.pub
1079+
git config --global --unset gpg.format
1080+
git config --global --unset user.signingkey
1081+
git config --global --unset commit.gpgsign
1082+
'''
10671083
}
10681084
cleanup {
10691085
sh '''#! /bin/bash

0 commit comments

Comments
 (0)