Skip to content
This repository was archived by the owner on Apr 25, 2023. It is now read-only.

Commit 3d73c8a

Browse files
Bot Updating Templated Files
1 parent f97623e commit 3d73c8a

File tree

1 file changed

+118
-7
lines changed

1 file changed

+118
-7
lines changed

Diff for: Jenkinsfile

+118-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ pipeline {
3939
// Setup all the basic environment variables needed for the build
4040
stage("Set ENV Variables base"){
4141
steps{
42+
sh '''docker pull quay.io/skopeo/stable:v1 || : '''
4243
script{
4344
env.EXIT_STATUS = ''
4445
env.LS_RELEASE = sh(
45-
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' || : ''',
46+
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' || : ''',
4647
returnStdout: true).trim()
4748
env.LS_RELEASE_NOTES = sh(
4849
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' ''',
@@ -56,7 +57,7 @@ pipeline {
5657
env.CODE_URL = 'https://github.com/' + env.LS_USER + '/' + env.LS_REPO + '/commit/' + env.GIT_COMMIT
5758
env.DOCKERHUB_LINK = 'https://hub.docker.com/r/' + env.DOCKERHUB_IMAGE + '/tags/'
5859
env.PULL_REQUEST = env.CHANGE_ID
59-
env.TEMPLATED_FILES = 'Jenkinsfile README.md LICENSE .editorconfig ./.github/CONTRIBUTING.md ./.github/FUNDING.yml ./.github/ISSUE_TEMPLATE/config.yml ./.github/ISSUE_TEMPLATE/issue.bug.yml ./.github/ISSUE_TEMPLATE/issue.feature.yml ./.github/PULL_REQUEST_TEMPLATE.md ./.github/workflows/external_trigger_scheduler.yml ./.github/workflows/greetings.yml ./.github/workflows/package_trigger_scheduler.yml ./.github/workflows/call_issue_pr_tracker.yml ./.github/workflows/call_issues_cron.yml ./.github/workflows/permissions.yml ./.github/workflows/external_trigger.yml ./.github/workflows/package_trigger.yml'
60+
env.TEMPLATED_FILES = 'Jenkinsfile README.md LICENSE .editorconfig ./.github/CONTRIBUTING.md ./.github/FUNDING.yml ./.github/ISSUE_TEMPLATE/config.yml ./.github/ISSUE_TEMPLATE/issue.bug.yml ./.github/ISSUE_TEMPLATE/issue.feature.yml ./.github/PULL_REQUEST_TEMPLATE.md ./root/etc/cont-init.d/99-deprecation'
6061
}
6162
script{
6263
env.LS_RELEASE_NUMBER = sh(
@@ -226,7 +227,7 @@ pipeline {
226227
script{
227228
env.SHELLCHECK_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/shellcheck-result.xml'
228229
}
229-
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-shellcheck/master/checkrun.sh | /bin/bash'''
230+
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-jenkins-builder/master/checkrun.sh | /bin/bash'''
230231
sh '''#! /bin/bash
231232
docker run --rm \
232233
-v ${WORKSPACE}:/mnt \
@@ -273,6 +274,7 @@ pipeline {
273274
fi
274275
# Stage 2 - Delete old templates
275276
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md .github/ISSUE_TEMPLATE/issue.bug.md .github/ISSUE_TEMPLATE/issue.feature.md .github/workflows/call_invalid_helper.yml .github/workflows/stale.yml"
277+
OLD_TEMPLATES="${OLD_TEMPLATES} $(echo .github/workflows/{external_trigger,external_trigger_scheduler,package_trigger,package_trigger_scheduler,call_issue_pr_tracker,call_issues_cron}.yml)"
276278
for i in ${OLD_TEMPLATES}; do
277279
if [[ -f "${i}" ]]; then
278280
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
@@ -307,6 +309,14 @@ pipeline {
307309
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
308310
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
309311
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
312+
if [[ -d "${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d" ]]; then
313+
mkdir -p \
314+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/init-deprecate/dependencies.d \
315+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/init-services/dependencies.d \
316+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/user/contents.d
317+
else
318+
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/root/etc/cont-init.d
319+
fi
310320
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
311321
cd ${TEMPDIR}/repo/${LS_REPO}/
312322
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
@@ -337,6 +347,10 @@ pipeline {
337347
fi
338348
if [[ ("${BRANCH_NAME}" == "master") || ("${BRANCH_NAME}" == "main") ]] && [[ (! -f ${TEMPDIR}/unraid/templates/unraid/${CONTAINER_NAME}.xml) || ("$(md5sum ${TEMPDIR}/unraid/templates/unraid/${CONTAINER_NAME}.xml | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml | awk '{ print $1 }')") ]]; then
339349
cd ${TEMPDIR}/unraid/templates/
350+
if ! grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
351+
echo "${CONTAINER_NAME}" >> ${TEMPDIR}/unraid/templates/unraid/ignore.list
352+
git add unraid/ignore.list
353+
fi
340354
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
341355
echo "Image is on the ignore list, marking Unraid template as deprecated"
342356
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
@@ -374,6 +388,26 @@ pipeline {
374388
}
375389
}
376390
}
391+
// If this is a master build check the S6 service file perms
392+
stage("Check S6 Service file Permissions"){
393+
when {
394+
branch "master"
395+
environment name: 'CHANGE_ID', value: ''
396+
environment name: 'EXIT_STATUS', value: ''
397+
}
398+
steps {
399+
script{
400+
sh '''#! /bin/bash
401+
WRONG_PERM=$(find ./ -path "./.git" -prune -o \\( -name "run" -o -name "finish" -o -name "check" \\) -not -perm -u=x,g=x,o=x -print)
402+
if [[ -n "${WRONG_PERM}" ]]; then
403+
echo "The following S6 service files are missing the executable bit; canceling the faulty build: ${WRONG_PERM}"
404+
exit 1
405+
else
406+
echo "S6 service file perms look good."
407+
fi '''
408+
}
409+
}
410+
}
377411
/* #######################
378412
GitLab Mirroring
379413
####################### */
@@ -666,6 +700,7 @@ pipeline {
666700
]) {
667701
script{
668702
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
703+
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
669704
}
670705
sh '''#! /bin/bash
671706
set -e
@@ -692,8 +727,6 @@ pipeline {
692727
-e WEB_SCREENSHOT=\"${CI_WEB}\" \
693728
-e WEB_AUTH=\"${CI_AUTH}\" \
694729
-e WEB_PATH=\"${CI_WEBPATH}\" \
695-
-e DO_REGION="ams3" \
696-
-e DO_BUCKET="lsio-ci" \
697730
-t ghcr.io/linuxserver/ci:latest \
698731
python3 test_build.py'''
699732
}
@@ -947,8 +980,86 @@ pipeline {
947980
environment name: 'EXIT_STATUS', value: ''
948981
}
949982
steps {
950-
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/issues/${PULL_REQUEST}/comments \
951-
-d '{"body": "I am a bot, here are the test results for this PR: \\n'${CI_URL}' \\n'${SHELLCHECK_URL}'"}' '''
983+
sh '''#! /bin/bash
984+
# Function to retrieve JSON data from URL
985+
get_json() {
986+
local url="$1"
987+
local response=$(curl -s "$url")
988+
if [ $? -ne 0 ]; then
989+
echo "Failed to retrieve JSON data from $url"
990+
return 1
991+
fi
992+
local json=$(echo "$response" | jq .)
993+
if [ $? -ne 0 ]; then
994+
echo "Failed to parse JSON data from $url"
995+
return 1
996+
fi
997+
echo "$json"
998+
}
999+
1000+
build_table() {
1001+
local data="$1"
1002+
1003+
# Get the keys in the JSON data
1004+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
1005+
1006+
# Check if keys are empty
1007+
if [ -z "$keys" ]; then
1008+
echo "JSON report data does not contain any keys or the report does not exist."
1009+
return 1
1010+
fi
1011+
1012+
# Build table header
1013+
local header="| Tag | Passed |\\n| --- | --- |\\n"
1014+
1015+
# Loop through the JSON data to build the table rows
1016+
local rows=""
1017+
for build in $keys; do
1018+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
1019+
if [ "$status" = "true" ]; then
1020+
status="✅"
1021+
else
1022+
status="❌"
1023+
fi
1024+
local row="| "$build" | "$status" |\\n"
1025+
rows="${rows}${row}"
1026+
done
1027+
1028+
local table="${header}${rows}"
1029+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
1030+
echo "$escaped_table"
1031+
}
1032+
1033+
# Retrieve JSON data from URL
1034+
data=$(get_json "$CI_JSON_URL")
1035+
# Create table from JSON data
1036+
table=$(build_table "$data")
1037+
echo -e "$table"
1038+
1039+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1040+
-H "Accept: application/vnd.github.v3+json" \
1041+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1042+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"'''
1043+
1044+
}
1045+
}
1046+
stage('Deprecate/Disable Future Builds') {
1047+
when {
1048+
branch "master"
1049+
environment name: 'CHANGE_ID', value: ''
1050+
environment name: 'EXIT_STATUS', value: ''
1051+
}
1052+
steps {
1053+
sh '''#! /bin/bash
1054+
TEMPDIR=$(mktemp -d)
1055+
mkdir -p ${TEMPDIR}/repo
1056+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
1057+
cd ${TEMPDIR}/repo/${LS_REPO}
1058+
git checkout -f master
1059+
git rm Jenkinsfile
1060+
git commit -m 'Disabling future builds'
1061+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
1062+
rm -Rf ${TEMPDIR}'''
9521063
}
9531064
}
9541065
}

0 commit comments

Comments
 (0)