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

Commit 0861de1

Browse files
Bot Updating Templated Files
1 parent efff3ab commit 0861de1

File tree

1 file changed

+114
-7
lines changed

1 file changed

+114
-7
lines changed

Jenkinsfile

Lines changed: 114 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ pipeline {
4242
// Setup all the basic environment variables needed for the build
4343
stage("Set ENV Variables base"){
4444
steps{
45+
sh '''docker pull quay.io/skopeo/stable:v1 || : '''
4546
script{
4647
env.EXIT_STATUS = ''
4748
env.LS_RELEASE = sh(
48-
script: '''docker run --rm ghcr.io/linuxserver/alexeiled-skopeo sh -c 'skopeo inspect docker://docker.io/'${DOCKERHUB_IMAGE}':3.17 2>/dev/null' | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
49+
script: '''docker run --rm quay.io/skopeo/stable:v1 inspect docker://ghcr.io/${LS_USER}/${CONTAINER_NAME}:3.17 2>/dev/null | jq -r '.Labels.build_version' | awk '{print $3}' | grep '\\-ls' || : ''',
4950
returnStdout: true).trim()
5051
env.LS_RELEASE_NOTES = sh(
5152
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' ''',
@@ -59,7 +60,7 @@ pipeline {
5960
env.CODE_URL = 'https://github.com/' + env.LS_USER + '/' + env.LS_REPO + '/commit/' + env.GIT_COMMIT
6061
env.DOCKERHUB_LINK = 'https://hub.docker.com/r/' + env.DOCKERHUB_IMAGE + '/tags/'
6162
env.PULL_REQUEST = env.CHANGE_ID
62-
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'
63+
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'
6364
}
6465
script{
6566
env.LS_RELEASE_NUMBER = sh(
@@ -238,7 +239,7 @@ pipeline {
238239
script{
239240
env.SHELLCHECK_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/shellcheck-result.xml'
240241
}
241-
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-shellcheck/master/checkrun.sh | /bin/bash'''
242+
sh '''curl -sL https://raw.githubusercontent.com/linuxserver/docker-jenkins-builder/master/checkrun.sh | /bin/bash'''
242243
sh '''#! /bin/bash
243244
docker run --rm \
244245
-v ${WORKSPACE}:/mnt \
@@ -285,6 +286,7 @@ pipeline {
285286
fi
286287
# Stage 2 - Delete old templates
287288
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"
289+
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)"
288290
for i in ${OLD_TEMPLATES}; do
289291
if [[ -f "${i}" ]]; then
290292
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
@@ -319,6 +321,14 @@ pipeline {
319321
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
320322
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
321323
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
324+
if [[ -d "${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d" ]]; then
325+
mkdir -p \
326+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/init-deprecate/dependencies.d \
327+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/init-services/dependencies.d \
328+
${TEMPDIR}/repo/${LS_REPO}/root/etc/s6-overlay/s6-rc.d/user/contents.d
329+
else
330+
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/root/etc/cont-init.d
331+
fi
322332
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
323333
cd ${TEMPDIR}/repo/${LS_REPO}/
324334
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
@@ -365,6 +375,26 @@ pipeline {
365375
}
366376
}
367377
}
378+
// If this is a 3.17 build check the S6 service file perms
379+
stage("Check S6 Service file Permissions"){
380+
when {
381+
branch "3.17"
382+
environment name: 'CHANGE_ID', value: ''
383+
environment name: 'EXIT_STATUS', value: ''
384+
}
385+
steps {
386+
script{
387+
sh '''#! /bin/bash
388+
WRONG_PERM=$(find ./ -path "./.git" -prune -o \\( -name "run" -o -name "finish" -o -name "check" \\) -not -perm -u=x,g=x,o=x -print)
389+
if [[ -n "${WRONG_PERM}" ]]; then
390+
echo "The following S6 service files are missing the executable bit; canceling the faulty build: ${WRONG_PERM}"
391+
exit 1
392+
else
393+
echo "S6 service file perms look good."
394+
fi '''
395+
}
396+
}
397+
}
368398
/* #######################
369399
GitLab Mirroring
370400
####################### */
@@ -639,6 +669,7 @@ pipeline {
639669
]) {
640670
script{
641671
env.CI_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/index.html'
672+
env.CI_JSON_URL = 'https://ci-tests.linuxserver.io/' + env.IMAGE + '/' + env.META_TAG + '/report.json'
642673
}
643674
sh '''#! /bin/bash
644675
set -e
@@ -665,8 +696,6 @@ pipeline {
665696
-e WEB_SCREENSHOT=\"${CI_WEB}\" \
666697
-e WEB_AUTH=\"${CI_AUTH}\" \
667698
-e WEB_PATH=\"${CI_WEBPATH}\" \
668-
-e DO_REGION="ams3" \
669-
-e DO_BUCKET="lsio-ci" \
670699
-t ghcr.io/linuxserver/ci:latest \
671700
python3 test_build.py'''
672701
}
@@ -916,8 +945,86 @@ pipeline {
916945
environment name: 'EXIT_STATUS', value: ''
917946
}
918947
steps {
919-
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/issues/${PULL_REQUEST}/comments \
920-
-d '{"body": "I am a bot, here are the test results for this PR: \\n'${CI_URL}' \\n'${SHELLCHECK_URL}'"}' '''
948+
sh '''#! /bin/bash
949+
# Function to retrieve JSON data from URL
950+
get_json() {
951+
local url="$1"
952+
local response=$(curl -s "$url")
953+
if [ $? -ne 0 ]; then
954+
echo "Failed to retrieve JSON data from $url"
955+
return 1
956+
fi
957+
local json=$(echo "$response" | jq .)
958+
if [ $? -ne 0 ]; then
959+
echo "Failed to parse JSON data from $url"
960+
return 1
961+
fi
962+
echo "$json"
963+
}
964+
965+
build_table() {
966+
local data="$1"
967+
968+
# Get the keys in the JSON data
969+
local keys=$(echo "$data" | jq -r 'to_entries | map(.key) | .[]')
970+
971+
# Check if keys are empty
972+
if [ -z "$keys" ]; then
973+
echo "JSON report data does not contain any keys or the report does not exist."
974+
return 1
975+
fi
976+
977+
# Build table header
978+
local header="| Tag | Passed |\\n| --- | --- |\\n"
979+
980+
# Loop through the JSON data to build the table rows
981+
local rows=""
982+
for build in $keys; do
983+
local status=$(echo "$data" | jq -r ".[\\"$build\\"].test_success")
984+
if [ "$status" = "true" ]; then
985+
status="✅"
986+
else
987+
status="❌"
988+
fi
989+
local row="| "$build" | "$status" |\\n"
990+
rows="${rows}${row}"
991+
done
992+
993+
local table="${header}${rows}"
994+
local escaped_table=$(echo "$table" | sed 's/\"/\\\\"/g')
995+
echo "$escaped_table"
996+
}
997+
998+
# Retrieve JSON data from URL
999+
data=$(get_json "$CI_JSON_URL")
1000+
# Create table from JSON data
1001+
table=$(build_table "$data")
1002+
echo -e "$table"
1003+
1004+
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
1005+
-H "Accept: application/vnd.github.v3+json" \
1006+
"https://api.github.com/repos/$LS_USER/$LS_REPO/issues/$PULL_REQUEST/comments" \
1007+
-d "{\\"body\\": \\"I am a bot, here are the test results for this PR: \\n${CI_URL}\\n${SHELLCHECK_URL}\\n${table}\\"}"'''
1008+
1009+
}
1010+
}
1011+
stage('Deprecate/Disable Future Builds') {
1012+
when {
1013+
branch "3.17"
1014+
environment name: 'CHANGE_ID', value: ''
1015+
environment name: 'EXIT_STATUS', value: ''
1016+
}
1017+
steps {
1018+
sh '''#! /bin/bash
1019+
TEMPDIR=$(mktemp -d)
1020+
mkdir -p ${TEMPDIR}/repo
1021+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
1022+
cd ${TEMPDIR}/repo/${LS_REPO}
1023+
git checkout -f 3.17
1024+
git rm Jenkinsfile
1025+
git commit -m 'Disabling future builds'
1026+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
1027+
rm -Rf ${TEMPDIR}'''
9211028
}
9221029
}
9231030
}

0 commit comments

Comments
 (0)