Skip to content

Commit fc83870

Browse files
Bot Updating Templated Files
1 parent ce47f74 commit fc83870

File tree

1 file changed

+61
-16
lines changed

1 file changed

+61
-16
lines changed

Jenkinsfile

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,22 +232,67 @@ pipeline {
232232
TEMPDIR=$(mktemp -d)
233233
docker pull ghcr.io/linuxserver/jenkins-builder:latest
234234
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
235+
# Stage 1 - Jenkinsfile update
236+
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
237+
mkdir -p ${TEMPDIR}/repo
238+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
239+
cd ${TEMPDIR}/repo/${LS_REPO}
240+
git checkout -f master
241+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
242+
git add Jenkinsfile
243+
git commit -m 'Bot Updating Templated Files'
244+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
245+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
246+
echo "Updating Jenkinsfile"
247+
rm -Rf ${TEMPDIR}
248+
exit 0
249+
else
250+
echo "Jenkinsfile is up to date."
251+
fi
252+
# Stage 2 - Delete old templates
253+
OLD_TEMPLATES=".github/ISSUE_TEMPLATE.md"
254+
for i in ${OLD_TEMPLATES}; do
255+
if [[ -f "${i}" ]]; then
256+
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
257+
fi
258+
done
259+
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
260+
mkdir -p ${TEMPDIR}/repo
261+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
262+
cd ${TEMPDIR}/repo/${LS_REPO}
263+
git checkout -f master
264+
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
265+
for i in ${TEMPLATES_TO_DELETE}; do
266+
git rm "${i}"
267+
done
268+
git commit -m 'Bot Updating Templated Files'
269+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
270+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
271+
echo "Deleting old templates"
272+
rm -Rf ${TEMPDIR}
273+
exit 0
274+
else
275+
echo "No templates to delete"
276+
fi
277+
# Stage 3 - Update templates
235278
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
236279
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
237280
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
238-
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]]; then
281+
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
239282
mkdir -p ${TEMPDIR}/repo
240283
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
241284
cd ${TEMPDIR}/repo/${LS_REPO}
242285
git checkout -f master
243286
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
244287
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
245288
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
246-
rm -f ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE.md
247289
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
248290
cd ${TEMPDIR}/repo/${LS_REPO}/
291+
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
292+
echo ".jenkins-external" >> .gitignore
293+
git add .gitignore
294+
fi
249295
git add ${TEMPLATED_FILES}
250-
git rm .github/ISSUE_TEMPLATE.md || :
251296
git commit -m 'Bot Updating Templated Files'
252297
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git --all
253298
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
@@ -256,8 +301,8 @@ pipeline {
256301
fi
257302
mkdir -p ${TEMPDIR}/gitbook
258303
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/gitbook/docker-documentation
259-
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
260-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
304+
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
305+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/gitbook/docker-documentation/images/
261306
cd ${TEMPDIR}/gitbook/docker-documentation/
262307
git add images/docker-${CONTAINER_NAME}.md
263308
git commit -m 'Bot Updating Documentation'
@@ -267,13 +312,13 @@ pipeline {
267312
git clone https://github.com/linuxserver/docker-templates.git ${TEMPDIR}/unraid/docker-templates
268313
git clone https://github.com/linuxserver/templates.git ${TEMPDIR}/unraid/templates
269314
if [[ -f ${TEMPDIR}/unraid/docker-templates/linuxserver.io/img/${CONTAINER_NAME}-icon.png ]]; then
270-
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
315+
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
271316
fi
272-
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
317+
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
273318
if grep -wq "${CONTAINER_NAME}" ${TEMPDIR}/unraid/templates/unraid/ignore.list; then
274319
echo "Image is on the ignore list, skipping Unraid template upload"
275320
else
276-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
321+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/${CONTAINER_NAME}.xml ${TEMPDIR}/unraid/templates/unraid/
277322
cd ${TEMPDIR}/unraid/templates/
278323
git add unraid/${CONTAINER_NAME}.xml
279324
git commit -m 'Bot Updating Unraid Template'
@@ -513,7 +558,7 @@ pipeline {
513558
}
514559
sh '''#! /bin/bash
515560
set -e
516-
docker pull ghcr.io/linuxserver/lsiodev-ci:latest
561+
docker pull ghcr.io/linuxserver/ci:latest
517562
if [ "${MULTIARCH}" == "true" ]; then
518563
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm32v7-${COMMIT_SHA}-${BUILD_NUMBER}
519564
docker pull ghcr.io/linuxserver/lsiodev-buildcache:arm64v8-${COMMIT_SHA}-${BUILD_NUMBER}
@@ -538,7 +583,7 @@ pipeline {
538583
-e WEB_PATH=\"${CI_WEBPATH}\" \
539584
-e DO_REGION="ams3" \
540585
-e DO_BUCKET="lsio-ci" \
541-
-t ghcr.io/linuxserver/lsiodev-ci:latest \
586+
-t ghcr.io/linuxserver/ci:latest \
542587
python /ci/ci.py'''
543588
}
544589
}
@@ -683,19 +728,19 @@ pipeline {
683728
environment name: 'EXIT_STATUS', value: ''
684729
}
685730
steps {
686-
echo "Pushing New tag for current commit ${EXT_RELEASE_CLEAN}-ls${LS_TAG_NUMBER}"
731+
echo "Pushing New tag for current commit ${META_TAG}"
687732
sh '''curl -H "Authorization: token ${GITHUB_TOKEN}" -X POST https://api.github.com/repos/${LS_USER}/${LS_REPO}/git/tags \
688-
-d '{"tag":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
733+
-d '{"tag":"'${META_TAG}'",\
689734
"object": "'${COMMIT_SHA}'",\
690735
"message": "Tagging Release '${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}' to master",\
691736
"type": "commit",\
692737
"tagger": {"name": "LinuxServer Jenkins","email": "[email protected]","date": "'${GITHUB_DATE}'"}}' '''
693738
echo "Pushing New release for Tag"
694739
sh '''#! /bin/bash
695740
echo "Updating PIP version of ${EXT_PIP} to ${EXT_RELEASE_CLEAN}" > releasebody.json
696-
echo '{"tag_name":"'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
741+
echo '{"tag_name":"'${META_TAG}'",\
697742
"target_commitish": "master",\
698-
"name": "'${EXT_RELEASE_CLEAN}'-ls'${LS_TAG_NUMBER}'",\
743+
"name": "'${META_TAG}'",\
699744
"body": "**LinuxServer Changes:**\\n\\n'${LS_RELEASE_NOTES}'\\n**PIP Changes:**\\n\\n' > start
700745
printf '","draft": false,"prerelease": false}' >> releasebody.json
701746
paste -d'\\0' start releasebody.json > releasebody.json.done
@@ -722,15 +767,15 @@ pipeline {
722767
TEMPDIR=$(mktemp -d)
723768
docker pull ghcr.io/linuxserver/jenkins-builder:latest
724769
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH="${BRANCH_NAME}" -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
725-
docker pull ghcr.io/linuxserver/lsiodev-readme-sync
770+
docker pull ghcr.io/linuxserver/readme-sync
726771
docker run --rm=true \
727772
-e DOCKERHUB_USERNAME=$DOCKERUSER \
728773
-e DOCKERHUB_PASSWORD=$DOCKERPASS \
729774
-e GIT_REPOSITORY=${LS_USER}/${LS_REPO} \
730775
-e DOCKER_REPOSITORY=${IMAGE} \
731776
-e GIT_BRANCH=master \
732777
-v ${TEMPDIR}/docker-${CONTAINER_NAME}:/mnt \
733-
ghcr.io/linuxserver/lsiodev-readme-sync bash -c 'node sync'
778+
ghcr.io/linuxserver/readme-sync bash -c 'node sync'
734779
rm -Rf ${TEMPDIR} '''
735780
}
736781
}

0 commit comments

Comments
 (0)