Skip to content

Commit 41f7133

Browse files
Bot Updating Templated Files
1 parent b4c0001 commit 41f7133

File tree

1 file changed

+85
-6
lines changed

1 file changed

+85
-6
lines changed

Jenkinsfile

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ pipeline {
4141
// Setup all the basic environment variables needed for the build
4242
stage("Set ENV Variables base"){
4343
steps{
44+
sh '''docker pull quay.io/skopeo/stable:v1 || : '''
4445
script{
4546
env.EXIT_STATUS = ''
4647
env.LS_RELEASE = sh(
47-
script: '''docker run --rm ghcr.io/linuxserver/alexeiled-skopeo sh -c 'skopeo inspect docker://docker.io/'${DOCKERHUB_IMAGE}':latest 2>/dev/null' | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
48+
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' || : ''',
4849
returnStdout: true).trim()
4950
env.LS_RELEASE_NOTES = sh(
5051
script: '''cat readme-vars.yml | awk -F \\" '/date: "[0-9][0-9].[0-9][0-9].[0-9][0-9]:/ {print $4;exit;}' | sed -E ':a;N;$!ba;s/\\r{0,1}\\n/\\\\n/g' ''',
@@ -229,7 +230,7 @@ pipeline {
229230
script{
230231
env.SHELLCHECK_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/shellcheck-result.xml'
231232
}
232-
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-shellcheck/master/checkrun.sh | /bin/bash'''
233+
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-jenkins-builder/master/checkrun.sh | /bin/bash'''
233234
sh '''#! /bin/bash
234235
docker run --rm \
235236
-v ${WORKSPACE}:/mnt \
@@ -377,6 +378,26 @@ pipeline {
377378
}
378379
}
379380
}
381+
// If this is a master build check the S6 service file perms
382+
stage("Check S6 Service file Permissions"){
383+
when {
384+
branch "master"
385+
environment name: 'CHANGE_ID', value: ''
386+
environment name: 'EXIT_STATUS', value: ''
387+
}
388+
steps {
389+
script{
390+
sh '''#! /bin/bash
391+
WRONG_PERM=$(find ./ -path "./.git" -prune -o \\( -name "run" -o -name "finish" -o -name "check" \\) -not -perm -u=x,g=x,o=x -print)
392+
if [[ -n "${WRONG_PERM}" ]]; then
393+
echo "The following S6 service files are missing the executable bit; canceling the faulty build: ${WRONG_PERM}"
394+
exit 1
395+
else
396+
echo "S6 service file perms look good."
397+
fi '''
398+
}
399+
}
400+
}
380401
/* #######################
381402
GitLab Mirroring
382403
####################### */
@@ -669,6 +690,7 @@ pipeline {
669690
]) {
670691
script{
671692
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
693+
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
672694
}
673695
sh '''#! /bin/bash
674696
set -e
@@ -695,8 +717,6 @@ pipeline {
695717
-e WEB_SCREENSHOT=\"${CI_WEB}\" \
696718
-e WEB_AUTH=\"${CI_AUTH}\" \
697719
-e WEB_PATH=\"${CI_WEBPATH}\" \
698-
-e DO_REGION="ams3" \
699-
-e DO_BUCKET="lsio-ci" \
700720
-t ghcr.io/linuxserver/ci:latest \
701721
python3 test_build.py'''
702722
}
@@ -950,8 +970,67 @@ pipeline {
950970
environment name: 'EXIT_STATUS', value: ''
951971
}
952972
steps {
953-
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/issues/${PULL_REQUEST}/comments \
954-
-d '{"body": "I am a bot, here are the test results for this PR: \\n'${CI_URL}' \\n'${SHELLCHECK_URL}'"}' '''
973+
sh '''#! /bin/bash
974+
# Function to retrieve JSON data from URL
975+
get_json() {
976+
local url="$1"
977+
local response=$(curl -s "$url")
978+
if [ $? -ne 0 ]; then
979+
echo "Failed to retrieve JSON data from $url"
980+
return 1
981+
fi
982+
local json=$(echo "$response" | jq .)
983+
if [ $? -ne 0 ]; then
984+
echo "Failed to parse JSON data from $url"
985+
return 1
986+
fi
987+
echo "$json"
988+
}
989+
990+
build_table() {
991+
local data="$1"
992+
993+
# Get the keys in the JSON data
994+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
995+
996+
# Check if keys are empty
997+
if [ -z "$keys" ]; then
998+
echo "JSON report data does not contain any keys or the report does not exist."
999+
return 1
1000+
fi
1001+
1002+
# Build table header
1003+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1004+
1005+
# Loop through the JSON data to build the table rows
1006+
local rows=""
1007+
for build in $keys; do
1008+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1009+
if [ "$status" = "true" ]; then
1010+
status="✅"
1011+
else
1012+
status="❌"
1013+
fi
1014+
local row="| "$build" | "$status" |\\n"
1015+
rows="${rows}${row}"
1016+
done
1017+
1018+
local table="${header}${rows}"
1019+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1020+
echo "$escaped_table"
1021+
}
1022+
1023+
# Retrieve JSON data from URL
1024+
data=$(get_json "$CI_JSON_URL")
1025+
# Create table from JSON data
1026+
table=$(build_table "$data")
1027+
echo -e "$table"
1028+
1029+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1030+
-H "Accept: application/vnd.github.v3+json" \
1031+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1032+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"'''
1033+
9551034
}
9561035
}
9571036
}

0 commit comments

Comments
 (0)