Skip to content

Commit baef0f3

Browse files
Bot Updating Templated Files
1 parent 5a9637f commit baef0f3

File tree

1 file changed

+115
-130
lines changed

1 file changed

+115
-130
lines changed

Jenkinsfile

Lines changed: 115 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,11 @@ pipeline {
245245
-v ${WORKSPACE}:/mnt \
246246
-e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \
247247
-e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \
248-
ghcr.io/linuxserver/baseimage-alpine:3.17 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
249-
apk add --no-cache py3-pip && \
250-
pip install s3cmd && \
248+
ghcr.io/linuxserver/baseimage-alpine:3.19 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
249+
apk add --no-cache python3 && \
250+
python3 -m venv /lsiopy && \
251+
pip install --no-cache-dir -U pip && \
252+
pip install --no-cache-dir s3cmd && \
251253
s3cmd put --no-preserve --acl-public -m text/xml /mnt/shellcheck-result.xml s3://ci-tests.linuxserver.io/${IMAGE}/${META_TAG}/shellcheck-result.xml" || :'''
252254
}
253255
}
@@ -262,125 +264,120 @@ pipeline {
262264
}
263265
}
264266
steps {
265-
withCredentials([
266-
[
267-
$class: 'UsernamePasswordMultiBinding',
268-
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207',
269-
usernameVariable: 'DOCKERUSER',
270-
passwordVariable: 'DOCKERPASS'
271-
]
272-
]) {
273-
sh '''#! /bin/bash
274-
set -e
275-
TEMPDIR=$(mktemp -d)
276-
docker pull ghcr.io/linuxserver/jenkins-builder:latest
277-
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=chinese -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
278-
# Stage 1 - Jenkinsfile update
279-
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
280-
mkdir -p ${TEMPDIR}/repo
281-
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
282-
cd ${TEMPDIR}/repo/${LS_REPO}
283-
git checkout -f chinese
284-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
285-
git add Jenkinsfile
286-
git commit -m 'Bot Updating Templated Files'
287-
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
288-
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
289-
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
290-
echo "Updating Jenkinsfile"
291-
rm -Rf ${TEMPDIR}
292-
exit 0
293-
else
294-
echo "Jenkinsfile is up to date."
267+
sh '''#! /bin/bash
268+
set -e
269+
TEMPDIR=$(mktemp -d)
270+
docker pull ghcr.io/linuxserver/jenkins-builder:latest
271+
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=chinese -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
272+
# Stage 1 - Jenkinsfile update
273+
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
274+
mkdir -p ${TEMPDIR}/repo
275+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
276+
cd ${TEMPDIR}/repo/${LS_REPO}
277+
git checkout -f chinese
278+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
279+
git add Jenkinsfile
280+
git commit -m 'Bot Updating Templated Files'
281+
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
282+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
283+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
284+
echo "Updating Jenkinsfile"
285+
rm -Rf ${TEMPDIR}
286+
exit 0
287+
else
288+
echo "Jenkinsfile is up to date."
289+
fi
290+
# Stage 2 - Delete old templates
291+
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 Dockerfile.armhf"
292+
for i in ${OLD_TEMPLATES}; do
293+
if [[ -f "${i}" ]]; then
294+
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
295295
fi
296-
# Stage 2 - Delete old templates
297-
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 Dockerfile.armhf"
298-
for i in ${OLD_TEMPLATES}; do
299-
if [[ -f "${i}" ]]; then
300-
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
301-
fi
296+
done
297+
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
298+
mkdir -p ${TEMPDIR}/repo
299+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
300+
cd ${TEMPDIR}/repo/${LS_REPO}
301+
git checkout -f chinese
302+
for i in ${TEMPLATES_TO_DELETE}; do
303+
git rm "${i}"
302304
done
303-
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
304-
mkdir -p ${TEMPDIR}/repo
305-
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
306-
cd ${TEMPDIR}/repo/${LS_REPO}
307-
git checkout -f chinese
308-
for i in ${TEMPLATES_TO_DELETE}; do
309-
git rm "${i}"
310-
done
311-
git commit -m 'Bot Updating Templated Files'
312-
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
313-
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
314-
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
315-
echo "Deleting old and deprecated templates"
316-
rm -Rf ${TEMPDIR}
317-
exit 0
318-
else
319-
echo "No templates to delete"
320-
fi
321-
# Stage 3 - Update templates
322-
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
305+
git commit -m 'Bot Updating Templated Files'
306+
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
307+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
308+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
309+
echo "Deleting old and deprecated templates"
310+
rm -Rf ${TEMPDIR}
311+
exit 0
312+
else
313+
echo "No templates to delete"
314+
fi
315+
# Stage 3 - Update templates
316+
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
317+
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
318+
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
319+
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
320+
mkdir -p ${TEMPDIR}/repo
321+
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
322+
cd ${TEMPDIR}/repo/${LS_REPO}
323+
git checkout -f chinese
323324
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
324-
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
325-
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
326-
mkdir -p ${TEMPDIR}/repo
327-
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
328-
cd ${TEMPDIR}/repo/${LS_REPO}
329-
git checkout -f chinese
330-
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
331-
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
332-
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
333-
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
334-
cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || :
335-
cd ${TEMPDIR}/repo/${LS_REPO}/
336-
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
337-
echo ".jenkins-external" >> .gitignore
338-
git add .gitignore
339-
fi
340-
git add readme-vars.yml ${TEMPLATED_FILES}
341-
git commit -m 'Bot Updating Templated Files'
342-
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
343-
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
344-
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
345-
else
346-
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
347-
fi
348-
mkdir -p ${TEMPDIR}/docs
349-
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
350-
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]] && [[ (! -f ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
351-
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
352-
cd ${TEMPDIR}/docs/docker-documentation
353-
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
354-
git add docs/images/docker-${CONTAINER_NAME}.md
355-
git commit -m 'Bot Updating Documentation'
356-
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH}
357-
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH}
325+
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
326+
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
327+
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
328+
cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || :
329+
cd ${TEMPDIR}/repo/${LS_REPO}/
330+
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
331+
echo ".jenkins-external" >> .gitignore
332+
git add .gitignore
358333
fi
359-
# Stage 4 - Sync Readme to Docker Hub
360-
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
361-
if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
362-
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
363-
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
364-
else
365-
echo "Syncing readme to Docker Hub"
366-
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
367-
fi
368-
DH_TOKEN=$(curl -d '{"username":"'${DOCKERUSER}'", "password":"'${DOCKERHUB_TOKEN}'"}' -H "Content-Type: application/json" -X POST https://hub.docker.com/v2/users/login | jq -r '.token')
369-
curl -s \
370-
-H "Authorization: JWT ${DH_TOKEN}" \
371-
-H "Content-Type: application/json" \
372-
-X PATCH \
373-
-d "{\\"full_description\\":$(jq -Rsa . ${DH_README_SYNC_PATH})}" \
374-
https://hub.docker.com/v2/repositories/${DOCKERHUB_IMAGE} || :
334+
git add readme-vars.yml ${TEMPLATED_FILES}
335+
git commit -m 'Bot Updating Templated Files'
336+
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
337+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git chinese
338+
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
339+
else
340+
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
341+
fi
342+
mkdir -p ${TEMPDIR}/docs
343+
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
344+
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]] && [[ (! -f ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md) || ("$(md5sum ${TEMPDIR}/docs/docker-documentation/docs/images/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md | awk '{ print $1 }')") ]]; then
345+
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
346+
cd ${TEMPDIR}/docs/docker-documentation
347+
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
348+
git add docs/images/docker-${CONTAINER_NAME}.md
349+
git commit -m 'Bot Updating Documentation'
350+
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
351+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
352+
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
353+
sleep $((RANDOM % MAXWAIT)) && \
354+
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
355+
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
356+
fi
357+
# Stage 4 - Sync Readme to Docker Hub
358+
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
359+
if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
360+
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
361+
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
375362
else
376-
echo "Not the default Github branch. Skipping readme sync to Docker Hub."
363+
echo "Syncing readme to Docker Hub"
364+
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
377365
fi
378-
rm -Rf ${TEMPDIR}'''
379-
script{
380-
env.FILES_UPDATED = sh(
381-
script: '''cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''',
382-
returnStdout: true).trim()
383-
}
366+
DH_TOKEN=$(curl -d '{"username":"linuxserverci", "password":"'${DOCKERHUB_TOKEN}'"}' -H "Content-Type: application/json" -X POST https://hub.docker.com/v2/users/login | jq -r '.token')
367+
curl -s \
368+
-H "Authorization: JWT ${DH_TOKEN}" \
369+
-H "Content-Type: application/json" \
370+
-X PATCH \
371+
-d "{\\"full_description\\":$(jq -Rsa . ${DH_README_SYNC_PATH})}" \
372+
https://hub.docker.com/v2/repositories/${DOCKERHUB_IMAGE} || :
373+
else
374+
echo "Not the default Github branch. Skipping readme sync to Docker Hub."
375+
fi
376+
rm -Rf ${TEMPDIR}'''
377+
script{
378+
env.FILES_UPDATED = sh(
379+
script: '''cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''',
380+
returnStdout: true).trim()
384381
}
385382
}
386383
}
@@ -678,12 +675,6 @@ pipeline {
678675
}
679676
steps {
680677
withCredentials([
681-
[
682-
$class: 'UsernamePasswordMultiBinding',
683-
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207',
684-
usernameVariable: 'DOCKERUSER',
685-
passwordVariable: 'DOCKERPASS'
686-
],
687678
[
688679
$class: 'UsernamePasswordMultiBinding',
689680
credentialsId: 'Quay.io-Robot',
@@ -694,7 +685,7 @@ pipeline {
694685
retry(5) {
695686
sh '''#! /bin/bash
696687
set -e
697-
echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
688+
echo $DOCKERHUB_TOKEN | docker login -u linuxserverci --password-stdin
698689
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
699690
echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin
700691
echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin
@@ -725,12 +716,6 @@ pipeline {
725716
}
726717
steps {
727718
withCredentials([
728-
[
729-
$class: 'UsernamePasswordMultiBinding',
730-
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207',
731-
usernameVariable: 'DOCKERUSER',
732-
passwordVariable: 'DOCKERPASS'
733-
],
734719
[
735720
$class: 'UsernamePasswordMultiBinding',
736721
credentialsId: 'Quay.io-Robot',
@@ -741,7 +726,7 @@ pipeline {
741726
retry(5) {
742727
sh '''#! /bin/bash
743728
set -e
744-
echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin
729+
echo $DOCKERHUB_TOKEN | docker login -u linuxserverci --password-stdin
745730
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
746731
echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin
747732
echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin

0 commit comments

Comments
 (0)