Skip to content

Commit b44aab7

Browse files
Bot Updating Templated Files
1 parent daa751b commit b44aab7

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

Jenkinsfile

+61-16
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,67 @@ pipeline {
231231
TEMPDIR=$(mktemp -d)
232232
docker pull ghcr.io/linuxserver/jenkins-builder:latest
233233
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
234+
# Stage 1 - Jenkinsfile update
235+
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
236+
mkdir -p ${TEMPDIR}/repo
237+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
238+
cd ${TEMPDIR}/repo/${LS_REPO}
239+
git checkout -f master
240+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
241+
git add Jenkinsfile
242+
git commit -m 'Bot Updating Templated Files'
243+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
244+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
245+
echo "Updating Jenkinsfile"
246+
rm -Rf ${TEMPDIR}
247+
exit 0
248+
else
249+
echo "Jenkinsfile is up to date."
250+
fi
251+
# Stage 2 - Delete old templates
252+
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md"
253+
for i in ${OLD_TEMPLATES}; do
254+
if [[ -f "${i}" ]]; then
255+
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
256+
fi
257+
done
258+
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
259+
mkdir -p ${TEMPDIR}/repo
260+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
261+
cd ${TEMPDIR}/repo/${LS_REPO}
262+
git checkout -f master
263+
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
264+
for i in ${TEMPLATES_TO_DELETE}; do
265+
git rm "${i}"
266+
done
267+
git commit -m 'Bot Updating Templated Files'
268+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
269+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
270+
echo "Deleting old templates"
271+
rm -Rf ${TEMPDIR}
272+
exit 0
273+
else
274+
echo "No templates to delete"
275+
fi
276+
# Stage 3 - Update templates
234277
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
235278
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
236279
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
237-
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]]; then
280+
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
238281
mkdir -p ${TEMPDIR}/repo
239282
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
240283
cd ${TEMPDIR}/repo/${LS_REPO}
241284
git checkout -f master
242285
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
243286
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
244287
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
245-
rm -f ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE.md
246288
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
247289
cd ${TEMPDIR}/repo/${LS_REPO}/
290+
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
291+
echo ".jenkins-external" >> .gitignore
292+
git add .gitignore
293+
fi
248294
git add ${TEMPLATED_FILES}
249-
git rm .github/ISSUE_TEMPLATE.md || :
250295
git commit -m 'Bot Updating Templated Files'
251296
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
252297
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
@@ -255,8 +300,8 @@ pipeline {
255300
fi
256301
mkdir -p ${TEMPDIR}/gitbook
257302
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/gitbook/docker-documentation
258-
if [[ ("${BRANCH_NAME}" == "master") || ("${BRANCH_NAME}" == "main") ]] && [[ (! -f ${TEMPDIR}/gitbook/docker-documentation/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/gitbook/docker-documentation/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
259-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
303+
if [[ ("${BRANCH_NAME}" == "master") || ("${BRANCH_NAME}" == "main") ]] && [[ (! -f ${TEMPDIR}/gitbook/docker-documentation/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/gitbook/docker-documentation/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
304+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
260305
cd ${TEMPDIR}/gitbook/docker-documentation/
261306
git add images/docker-${CONTAINER_NAME}.md
262307
git commit -m 'Bot Updating Documentation'
@@ -266,13 +311,13 @@ pipeline {
266311
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
267312
git clone https://github.com/linuxserver/templates.git ${TEMPDIR}/unraid/templates
268313
if [[ -f ${TEMPDIR}/unraid/docker-templates/linuxserver.io/img/${CONTAINER_NAME}-icon.png ]]; then
269-
sed -i "s|master/linuxserver.io/img/linuxserver-ls-logo.png|master/linuxserver.io/img/${CONTAINER_NAME}-icon.png|" ${TEMPDIR}/docker-${CONTAINER_NAME}/${CONTAINER_NAME}.xml
314+
sed -i "s|master/linuxserver.io/img/linuxserver-ls-logo.png|master/linuxserver.io/img/${CONTAINER_NAME}-icon.png|" ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml
270315
fi
271-
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}/${CONTAINER_NAME}.xml | awk '{ print $1 }')") ]]; then
316+
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
272317
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
273318
echo "Image is on the ignore list, skipping Unraid template upload"
274319
else
275-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
320+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
276321
cd ${TEMPDIR}/unraid/templates/
277322
git add unraid/${CONTAINER_NAME}.xml
278323
git commit -m 'Bot Updating Unraid Template'
@@ -512,7 +557,7 @@ pipeline {
512557
}
513558
sh '''#! /bin/bash
514559
set -e
515-
docker pull ghcr.io/linuxserver/lsiodev-ci:latest
560+
docker pull ghcr.io/linuxserver/ci:latest
516561
if [ "${MULTIARCH}" == "true" ]; then
517562
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm32v7-${COMMIT_SHA}-${BUILD_NUMBER}
518563
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm64v8-${COMMIT_SHA}-${BUILD_NUMBER}
@@ -537,7 +582,7 @@ pipeline {
537582
-e WEB_PATH=\"${CI_WEBPATH}\" \
538583
-e DO_REGION="ams3" \
539584
-e DO_BUCKET="lsio-ci" \
540-
-t ghcr.io/linuxserver/lsiodev-ci:latest \
585+
-t ghcr.io/linuxserver/ci:latest \
541586
python /ci/ci.py'''
542587
}
543588
}
@@ -682,19 +727,19 @@ pipeline {
682727
environment name: 'EXIT_STATUS', value: ''
683728
}
684729
steps {
685-
echo "Pushing New tag for current commit ${EXT_RELEASE_CLEAN}-ls${LS_TAG_NUMBER}"
730+
echo "Pushing New tag for current commit ${META_TAG}"
686731
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/git/tags \
687-
-d '{"tag":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
732+
-d '{"tag":"'${META_TAG}'",\
688733
"object": "'${COMMIT_SHA}'",\
689734
"message": "Tagging Release '${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}' to master",\
690735
"type": "commit",\
691736
"tagger": {"name": "LinuxServer Jenkins","email": "[email protected]","date": "'${GITHUB_DATE}'"}}' '''
692737
echo "Pushing New release for Tag"
693738
sh '''#! /bin/bash
694739
echo "Updating to ${EXT_RELEASE_CLEAN}" > releasebody.json
695-
echo '{"tag_name":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
740+
echo '{"tag_name":"'${META_TAG}'",\
696741
"target_commitish": "master",\
697-
"name": "'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
742+
"name": "'${META_TAG}'",\
698743
"body": "**LinuxServer Changes:**\\n\\n'${LS_RELEASE_NOTES}'\\n**Remote Changes:**\\n\\n' > start
699744
printf '","draft": false,"prerelease": false}' >> releasebody.json
700745
paste -d'\\0' start releasebody.json > releasebody.json.done
@@ -721,15 +766,15 @@ pipeline {
721766
TEMPDIR=$(mktemp -d)
722767
docker pull ghcr.io/linuxserver/jenkins-builder:latest
723768
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH="${BRANCH_NAME}" -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
724-
docker pull ghcr.io/linuxserver/lsiodev-readme-sync
769+
docker pull ghcr.io/linuxserver/readme-sync
725770
docker run --rm=true \
726771
-e DOCKERHUB_USERNAME=$DOCKERUSER \
727772
-e DOCKERHUB_PASSWORD=$DOCKERPASS \
728773
-e GIT_REPOSITORY=${LS_USER}/${LS_REPO} \
729774
-e DOCKER_REPOSITORY=${IMAGE} \
730775
-e GIT_BRANCH=master \
731776
-v ${TEMPDIR}/docker-${CONTAINER_NAME}:/mnt \
732-
ghcr.io/linuxserver/lsiodev-readme-sync bash -c 'node sync'
777+
ghcr.io/linuxserver/readme-sync bash -c 'node sync'
733778
rm -Rf ${TEMPDIR} '''
734779
}
735780
}

0 commit comments

Comments
 (0)