Skip to content

Commit b65e0f3

Browse files
Bot Updating Templated Files
1 parent 0b21aa9 commit b65e0f3

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
@@ -233,22 +233,67 @@ pipeline {
233233
TEMPDIR=$(mktemp -d)
234234
docker pull ghcr.io/linuxserver/jenkins-builder:latest
235235
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
236+
# Stage 1 - Jenkinsfile update
237+
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
238+
mkdir -p ${TEMPDIR}/repo
239+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
240+
cd ${TEMPDIR}/repo/${LS_REPO}
241+
git checkout -f master
242+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
243+
git add Jenkinsfile
244+
git commit -m 'Bot Updating Templated Files'
245+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
246+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
247+
echo "Updating Jenkinsfile"
248+
rm -Rf ${TEMPDIR}
249+
exit 0
250+
else
251+
echo "Jenkinsfile is up to date."
252+
fi
253+
# Stage 2 - Delete old templates
254+
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md"
255+
for i in ${OLD_TEMPLATES}; do
256+
if [[ -f "${i}" ]]; then
257+
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
258+
fi
259+
done
260+
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
261+
mkdir -p ${TEMPDIR}/repo
262+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
263+
cd ${TEMPDIR}/repo/${LS_REPO}
264+
git checkout -f master
265+
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
266+
for i in ${TEMPLATES_TO_DELETE}; do
267+
git rm "${i}"
268+
done
269+
git commit -m 'Bot Updating Templated Files'
270+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
271+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
272+
echo "Deleting old templates"
273+
rm -Rf ${TEMPDIR}
274+
exit 0
275+
else
276+
echo "No templates to delete"
277+
fi
278+
# Stage 3 - Update templates
236279
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
237280
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
238281
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
239-
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]]; then
282+
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
240283
mkdir -p ${TEMPDIR}/repo
241284
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
242285
cd ${TEMPDIR}/repo/${LS_REPO}
243286
git checkout -f master
244287
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
245288
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
246289
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
247-
rm -f ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE.md
248290
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
249291
cd ${TEMPDIR}/repo/${LS_REPO}/
292+
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
293+
echo ".jenkins-external" >> .gitignore
294+
git add .gitignore
295+
fi
250296
git add ${TEMPLATED_FILES}
251-
git rm .github/ISSUE_TEMPLATE.md || :
252297
git commit -m 'Bot Updating Templated Files'
253298
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
254299
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
@@ -257,8 +302,8 @@ pipeline {
257302
fi
258303
mkdir -p ${TEMPDIR}/gitbook
259304
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/gitbook/docker-documentation
260-
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
261-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
305+
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
306+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
262307
cd ${TEMPDIR}/gitbook/docker-documentation/
263308
git add images/docker-${CONTAINER_NAME}.md
264309
git commit -m 'Bot Updating Documentation'
@@ -268,13 +313,13 @@ pipeline {
268313
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
269314
git clone https://github.com/linuxserver/templates.git ${TEMPDIR}/unraid/templates
270315
if [[ -f ${TEMPDIR}/unraid/docker-templates/linuxserver.io/img/${CONTAINER_NAME}-icon.png ]]; then
271-
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
316+
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
272317
fi
273-
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
318+
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
274319
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
275320
echo "Image is on the ignore list, skipping Unraid template upload"
276321
else
277-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
322+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
278323
cd ${TEMPDIR}/unraid/templates/
279324
git add unraid/${CONTAINER_NAME}.xml
280325
git commit -m 'Bot Updating Unraid Template'
@@ -514,7 +559,7 @@ pipeline {
514559
}
515560
sh '''#! /bin/bash
516561
set -e
517-
docker pull ghcr.io/linuxserver/lsiodev-ci:latest
562+
docker pull ghcr.io/linuxserver/ci:latest
518563
if [ "${MULTIARCH}" == "true" ]; then
519564
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm32v7-${COMMIT_SHA}-${BUILD_NUMBER}
520565
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm64v8-${COMMIT_SHA}-${BUILD_NUMBER}
@@ -539,7 +584,7 @@ pipeline {
539584
-e WEB_PATH=\"${CI_WEBPATH}\" \
540585
-e DO_REGION="ams3" \
541586
-e DO_BUCKET="lsio-ci" \
542-
-t ghcr.io/linuxserver/lsiodev-ci:latest \
587+
-t ghcr.io/linuxserver/ci:latest \
543588
python /ci/ci.py'''
544589
}
545590
}
@@ -684,19 +729,19 @@ pipeline {
684729
environment name: 'EXIT_STATUS', value: ''
685730
}
686731
steps {
687-
echo "Pushing New tag for current commit ${EXT_RELEASE_CLEAN}-ls${LS_TAG_NUMBER}"
732+
echo "Pushing New tag for current commit ${META_TAG}"
688733
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/git/tags \
689-
-d '{"tag":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
734+
-d '{"tag":"'${META_TAG}'",\
690735
"object": "'${COMMIT_SHA}'",\
691736
"message": "Tagging Release '${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}' to master",\
692737
"type": "commit",\
693738
"tagger": {"name": "LinuxServer Jenkins","email": "[email protected]","date": "'${GITHUB_DATE}'"}}' '''
694739
echo "Pushing New release for Tag"
695740
sh '''#! /bin/bash
696741
echo "Data change at JSON endpoint ${JSON_URL}" > releasebody.json
697-
echo '{"tag_name":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
742+
echo '{"tag_name":"'${META_TAG}'",\
698743
"target_commitish": "master",\
699-
"name": "'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
744+
"name": "'${META_TAG}'",\
700745
"body": "**LinuxServer Changes:**\\n\\n'${LS_RELEASE_NOTES}'\\n**Remote Changes:**\\n\\n' > start
701746
printf '","draft": false,"prerelease": false}' >> releasebody.json
702747
paste -d'\\0' start releasebody.json > releasebody.json.done
@@ -723,15 +768,15 @@ pipeline {
723768
TEMPDIR=$(mktemp -d)
724769
docker pull ghcr.io/linuxserver/jenkins-builder:latest
725770
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH="${BRANCH_NAME}" -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
726-
docker pull ghcr.io/linuxserver/lsiodev-readme-sync
771+
docker pull ghcr.io/linuxserver/readme-sync
727772
docker run --rm=true \
728773
-e DOCKERHUB_USERNAME=$DOCKERUSER \
729774
-e DOCKERHUB_PASSWORD=$DOCKERPASS \
730775
-e GIT_REPOSITORY=${LS_USER}/${LS_REPO} \
731776
-e DOCKER_REPOSITORY=${IMAGE} \
732777
-e GIT_BRANCH=master \
733778
-v ${TEMPDIR}/docker-${CONTAINER_NAME}:/mnt \
734-
ghcr.io/linuxserver/lsiodev-readme-sync bash -c 'node sync'
779+
ghcr.io/linuxserver/readme-sync bash -c 'node sync'
735780
rm -Rf ${TEMPDIR} '''
736781
}
737782
}

0 commit comments

Comments
 (0)