Bot Updating Templated Files

pull/157/head
LinuxServer-CI 2024-02-27 23:24:05 +00:00
rodzic 3ed856b657
commit f330f5f059
1 zmienionych plików z 116 dodań i 131 usunięć

247
Jenkinsfile vendored
Wyświetl plik

@ -243,9 +243,11 @@ pipeline {
-v ${WORKSPACE}:/mnt \ -v ${WORKSPACE}:/mnt \
-e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \ -e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \
-e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \ -e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \
ghcr.io/linuxserver/baseimage-alpine:3.17 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\ ghcr.io/linuxserver/baseimage-alpine:3.19 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
apk add --no-cache py3-pip && \ apk add --no-cache python3 && \
pip install s3cmd && \ python3 -m venv /lsiopy && \
pip install --no-cache-dir -U pip && \
pip install --no-cache-dir s3cmd && \
s3cmd put --no-preserve --acl-public -m text/xml /mnt/shellcheck-result.xml s3://ci-tests.linuxserver.io/${IMAGE}/${META_TAG}/shellcheck-result.xml" || :''' s3cmd put --no-preserve --acl-public -m text/xml /mnt/shellcheck-result.xml s3://ci-tests.linuxserver.io/${IMAGE}/${META_TAG}/shellcheck-result.xml" || :'''
} }
} }
@ -260,125 +262,120 @@ pipeline {
} }
} }
steps { steps {
withCredentials([ sh '''#! /bin/bash
[ set -e
$class: 'UsernamePasswordMultiBinding', TEMPDIR=$(mktemp -d)
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207', docker pull ghcr.io/linuxserver/jenkins-builder:latest
usernameVariable: 'DOCKERUSER', docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=jammy -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
passwordVariable: 'DOCKERPASS' # Stage 1 - Jenkinsfile update
] if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
]) { mkdir -p ${TEMPDIR}/repo
sh '''#! /bin/bash git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
set -e cd ${TEMPDIR}/repo/${LS_REPO}
TEMPDIR=$(mktemp -d) git checkout -f jammy
docker pull ghcr.io/linuxserver/jenkins-builder:latest cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/
docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=jammy -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest git add Jenkinsfile
# Stage 1 - Jenkinsfile update git commit -m 'Bot Updating Templated Files'
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
mkdir -p ${TEMPDIR}/repo git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO} echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
cd ${TEMPDIR}/repo/${LS_REPO} echo "Updating Jenkinsfile"
git checkout -f jammy rm -Rf ${TEMPDIR}
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile ${TEMPDIR}/repo/${LS_REPO}/ exit 0
git add Jenkinsfile else
git commit -m 'Bot Updating Templated Files' echo "Jenkinsfile is up to date."
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy fi
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy # Stage 2 - Delete old templates
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER} 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"
echo "Updating Jenkinsfile" for i in ${OLD_TEMPLATES}; do
rm -Rf ${TEMPDIR} if [[ -f "${i}" ]]; then
exit 0 TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}"
else
echo "Jenkinsfile is up to date."
fi fi
# Stage 2 - Delete old templates done
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" if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then
for i in ${OLD_TEMPLATES}; do mkdir -p ${TEMPDIR}/repo
if [[ -f "${i}" ]]; then git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
TEMPLATES_TO_DELETE="${i} ${TEMPLATES_TO_DELETE}" cd ${TEMPDIR}/repo/${LS_REPO}
fi git checkout -f jammy
for i in ${TEMPLATES_TO_DELETE}; do
git rm "${i}"
done done
if [[ -n "${TEMPLATES_TO_DELETE}" ]]; then git commit -m 'Bot Updating Templated Files'
mkdir -p ${TEMPDIR}/repo git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO} git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
cd ${TEMPDIR}/repo/${LS_REPO} echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
git checkout -f jammy echo "Deleting old and deprecated templates"
for i in ${TEMPLATES_TO_DELETE}; do rm -Rf ${TEMPDIR}
git rm "${i}" exit 0
done else
git commit -m 'Bot Updating Templated Files' echo "No templates to delete"
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy fi
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy # Stage 3 - Update templates
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER} CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
echo "Deleting old and deprecated templates" cd ${TEMPDIR}/docker-${CONTAINER_NAME}
rm -Rf ${TEMPDIR} NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
exit 0 if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then
else mkdir -p ${TEMPDIR}/repo
echo "No templates to delete" git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
fi cd ${TEMPDIR}/repo/${LS_REPO}
# Stage 3 - Update templates git checkout -f jammy
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
cd ${TEMPDIR}/docker-${CONTAINER_NAME} cd ${TEMPDIR}/docker-${CONTAINER_NAME}
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8) mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows
if [[ "${CURRENTHASH}" != "${NEWHASH}" ]] || ! grep -q '.jenkins-external' "${WORKSPACE}/.gitignore" 2>/dev/null; then mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE
mkdir -p ${TEMPDIR}/repo cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || :
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO} cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || :
cd ${TEMPDIR}/repo/${LS_REPO} cd ${TEMPDIR}/repo/${LS_REPO}/
git checkout -f jammy if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then
cd ${TEMPDIR}/docker-${CONTAINER_NAME} echo ".jenkins-external" >> .gitignore
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/workflows git add .gitignore
mkdir -p ${TEMPDIR}/repo/${LS_REPO}/.github/ISSUE_TEMPLATE fi
cp --parents ${TEMPLATED_FILES} ${TEMPDIR}/repo/${LS_REPO}/ || : git add readme-vars.yml ${TEMPLATED_FILES}
cp --parents readme-vars.yml ${TEMPDIR}/repo/${LS_REPO}/ || : git commit -m 'Bot Updating Templated Files'
cd ${TEMPDIR}/repo/${LS_REPO}/ git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
if ! grep -q '.jenkins-external' .gitignore 2>/dev/null; then git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy
echo ".jenkins-external" >> .gitignore echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
git add .gitignore else
fi echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
git add readme-vars.yml ${TEMPLATED_FILES} fi
git commit -m 'Bot Updating Templated Files' mkdir -p ${TEMPDIR}/docs
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git jammy 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
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER} cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
cd ${TEMPDIR}/docs/docker-documentation
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
git add docs/images/docker-${CONTAINER_NAME}.md
git commit -m 'Bot Updating Documentation'
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
sleep $((RANDOM % MAXWAIT)) && \
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
fi
# Stage 4 - Sync Readme to Docker Hub
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
else else
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER} echo "Syncing readme to Docker Hub"
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
fi fi
mkdir -p ${TEMPDIR}/docs 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')
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation curl -s \
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 -H "Authorization: JWT ${DH_TOKEN}" \
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/ -H "Content-Type: application/json" \
cd ${TEMPDIR}/docs/docker-documentation -X PATCH \
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||') -d "{\\"full_description\\":$(jq -Rsa . ${DH_README_SYNC_PATH})}" \
git add docs/images/docker-${CONTAINER_NAME}.md https://hub.docker.com/v2/repositories/${DOCKERHUB_IMAGE} || :
git commit -m 'Bot Updating Documentation' else
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} echo "Not the default Github branch. Skipping readme sync to Docker Hub."
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} fi
fi rm -Rf ${TEMPDIR}'''
# Stage 4 - Sync Readme to Docker Hub script{
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then env.FILES_UPDATED = sh(
if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then script: '''cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''',
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub" returnStdout: true).trim()
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
else
echo "Syncing readme to Docker Hub"
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
fi
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')
curl -s \
-H "Authorization: JWT ${DH_TOKEN}" \
-H "Content-Type: application/json" \
-X PATCH \
-d "{\\"full_description\\":$(jq -Rsa . ${DH_README_SYNC_PATH})}" \
https://hub.docker.com/v2/repositories/${DOCKERHUB_IMAGE} || :
else
echo "Not the default Github branch. Skipping readme sync to Docker Hub."
fi
rm -Rf ${TEMPDIR}'''
script{
env.FILES_UPDATED = sh(
script: '''cat /tmp/${COMMIT_SHA}-${BUILD_NUMBER}''',
returnStdout: true).trim()
}
} }
} }
} }
@ -673,12 +670,6 @@ pipeline {
} }
steps { steps {
withCredentials([ withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207',
usernameVariable: 'DOCKERUSER',
passwordVariable: 'DOCKERPASS'
],
[ [
$class: 'UsernamePasswordMultiBinding', $class: 'UsernamePasswordMultiBinding',
credentialsId: 'Quay.io-Robot', credentialsId: 'Quay.io-Robot',
@ -689,7 +680,7 @@ pipeline {
retry(5) { retry(5) {
sh '''#! /bin/bash sh '''#! /bin/bash
set -e set -e
echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin echo $DOCKERHUB_TOKEN | docker login -u linuxserverci --password-stdin
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin
echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin
@ -720,12 +711,6 @@ pipeline {
} }
steps { steps {
withCredentials([ withCredentials([
[
$class: 'UsernamePasswordMultiBinding',
credentialsId: '3f9ba4d5-100d-45b0-a3c4-633fd6061207',
usernameVariable: 'DOCKERUSER',
passwordVariable: 'DOCKERPASS'
],
[ [
$class: 'UsernamePasswordMultiBinding', $class: 'UsernamePasswordMultiBinding',
credentialsId: 'Quay.io-Robot', credentialsId: 'Quay.io-Robot',
@ -736,7 +721,7 @@ pipeline {
retry(5) { retry(5) {
sh '''#! /bin/bash sh '''#! /bin/bash
set -e set -e
echo $DOCKERPASS | docker login -u $DOCKERUSER --password-stdin echo $DOCKERHUB_TOKEN | docker login -u linuxserverci --password-stdin
echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin echo $GITHUB_TOKEN | docker login ghcr.io -u LinuxServer-CI --password-stdin
echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin echo $GITLAB_TOKEN | docker login registry.gitlab.com -u LinuxServer.io --password-stdin
echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin echo $QUAYPASS | docker login quay.io -u $QUAYUSER --password-stdin