@@ -266,8 +266,15 @@ pipeline {
266
266
set -e
267
267
TEMPDIR=$(mktemp -d)
268
268
docker pull ghcr.io/linuxserver/jenkins-builder:latest
269
- docker run --rm -e CONTAINER_NAME=${CONTAINER_NAME} -e GITHUB_BRANCH=master -v ${TEMPDIR}:/ansible/jenkins ghcr.io/linuxserver/jenkins-builder:latest
270
- # Stage 1 - Jenkinsfile update
269
+ # Cloned repo paths for templating:
270
+ # ${TEMPDIR}/docker-${CONTAINER_NAME}: Cloned branch master of ${LS_USER}/${LS_REPO} for running the jenkins builder on
271
+ # ${TEMPDIR}/repo/${LS_REPO}: Cloned branch master of ${LS_USER}/${LS_REPO} for commiting various templated file changes and pushing back to Github
272
+ # ${TEMPDIR}/docs/docker-documentation: Cloned docs repo for pushing docs updates to Github
273
+ # ${TEMPDIR}/unraid/docker-templates: Cloned docker-templates repo to check for logos
274
+ # ${TEMPDIR}/unraid/templates: Cloned templates repo for commiting unraid template changes and pushing back to Github
275
+ git clone --branch master --depth 1 https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/docker-${CONTAINER_NAME}
276
+ docker run --rm -v ${TEMPDIR}/docker-${CONTAINER_NAME}:/tmp -e LOCAL=true ghcr.io/linuxserver/jenkins-builder:latest
277
+ echo "Starting Stage 1 - Jenkinsfile update"
271
278
if [[ "$(md5sum Jenkinsfile | awk '{ print $1 }')" != "$(md5sum ${TEMPDIR}/docker-${CONTAINER_NAME}/Jenkinsfile | awk '{ print $1 }')" ]]; then
272
279
mkdir -p ${TEMPDIR}/repo
273
280
git clone https://github.com/${LS_USER}/${LS_REPO}.git ${TEMPDIR}/repo/${LS_REPO}
@@ -279,13 +286,13 @@ pipeline {
279
286
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
280
287
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
281
288
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
282
- echo "Updating Jenkinsfile"
289
+ echo "Updating Jenkinsfile and exiting build, new one will trigger based on commit "
283
290
rm -Rf ${TEMPDIR}
284
291
exit 0
285
292
else
286
293
echo "Jenkinsfile is up to date."
287
294
fi
288
- # Stage 2 - Delete old templates
295
+ echo "Starting Stage 2 - Delete old templates"
289
296
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"
290
297
for i in ${OLD_TEMPLATES}; do
291
298
if [[ -f "${i}" ]]; then
@@ -304,13 +311,13 @@ pipeline {
304
311
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
305
312
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
306
313
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
307
- echo "Deleting old and deprecated templates "
314
+ echo "Deleting old/deprecated templates and exiting build, new one will trigger based on commit "
308
315
rm -Rf ${TEMPDIR}
309
316
exit 0
310
317
else
311
318
echo "No templates to delete"
312
319
fi
313
- # Stage 3 - Update templates
320
+ echo "Starting Stage 3 - Update templates"
314
321
CURRENTHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
315
322
cd ${TEMPDIR}/docker-${CONTAINER_NAME}
316
323
NEWHASH=$(grep -hs ^ ${TEMPLATED_FILES} | md5sum | cut -c1-8)
@@ -334,33 +341,50 @@ pipeline {
334
341
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
335
342
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/${LS_USER}/${LS_REPO}.git master
336
343
echo "true" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
344
+ echo "Updating templates and exiting build, new one will trigger based on commit"
345
+ rm -Rf ${TEMPDIR}
346
+ exit 0
337
347
else
338
348
echo "false" > /tmp/${COMMIT_SHA}-${BUILD_NUMBER}
349
+ echo "No templates to update"
339
350
fi
351
+ echo "Starting Stage 4 - External repo updates: Docs, Unraid Template and Readme Sync to Docker Hub"
340
352
mkdir -p ${TEMPDIR}/docs
341
353
git clone https://github.com/linuxserver/docker-documentation.git ${TEMPDIR}/docs/docker-documentation
342
354
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
343
355
cp ${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/docker-${CONTAINER_NAME}.md ${TEMPDIR}/docs/docker-documentation/docs/images/
344
356
cd ${TEMPDIR}/docs/docker-documentation
345
357
GH_DOCS_DEFAULT_BRANCH=$(git remote show origin | grep "HEAD branch:" | sed 's|.*HEAD branch: ||')
346
358
git add docs/images/docker-${CONTAINER_NAME}.md
359
+ echo "Updating docs repo"
347
360
git commit -m 'Bot Updating Documentation'
348
361
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase
349
362
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} || \
350
363
(MAXWAIT="10" && echo "Push to docs failed, trying again in ${MAXWAIT} seconds" && \
351
364
sleep $((RANDOM % MAXWAIT)) && \
352
365
git pull https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH} --rebase && \
353
366
git push https://LinuxServer-CI:${GITHUB_TOKEN}@github.com/linuxserver/docker-documentation.git ${GH_DOCS_DEFAULT_BRANCH})
367
+ else
368
+ echo "Docs update not needed, skipping"
354
369
fi
355
- # Stage 4 - Sync Readme to Docker Hub
356
370
if [[ "${BRANCH_NAME}" == "${GH_DEFAULT_BRANCH}" ]]; then
357
- if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) > 25000 ]]; then
371
+ if [[ $(cat ${TEMPDIR}/docker-${CONTAINER_NAME}/README.md | wc -m) -gt 25000 ]]; then
358
372
echo "Readme is longer than 25,000 characters. Syncing the lite version to Docker Hub"
359
373
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/.jenkins-external/README.lite"
360
374
else
361
375
echo "Syncing readme to Docker Hub"
362
376
DH_README_SYNC_PATH="${TEMPDIR}/docker-${CONTAINER_NAME}/README.md"
363
377
fi
378
+ if curl -s https://hub.docker.com/v2/namespaces/${DOCKERHUB_IMAGE%%/*}/repositories/${DOCKERHUB_IMAGE##*/}/tags | jq -r '.message' | grep -q 404; then
379
+ echo "Docker Hub endpoint doesn't exist. Creating endpoint first."
380
+ 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')
381
+ curl -s \
382
+ -H "Authorization: JWT ${DH_TOKEN}" \
383
+ -H "Content-Type: application/json" \
384
+ -X POST \
385
+ -d '{"name":"'${DOCKERHUB_IMAGE##*/}'", "namespace":"'${DOCKERHUB_IMAGE%%/*}'"}' \
386
+ https://hub.docker.com/v2/repositories/ || :
387
+ fi
364
388
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')
365
389
curl -s \
366
390
-H "Authorization: JWT ${DH_TOKEN}" \
@@ -425,14 +449,16 @@ pipeline {
425
449
}
426
450
steps{
427
451
sh ''' curl -H "Content-Type: application/json" -H "Private-Token: ${GITLAB_TOKEN}" -X POST https://gitlab.com/api/v4/projects \
428
- -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
429
- "name":"'${LS_REPO}'",
430
- "mirror":true,\
431
- "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
432
- "issues_access_level":"disabled",\
433
- "merge_requests_access_level":"disabled",\
434
- "repository_access_level":"enabled",\
435
- "visibility":"public"}' '''
452
+ -d '{"namespace_id":'${GITLAB_NAMESPACE}',\
453
+ "name":"'${LS_REPO}'",
454
+ "mirror":true,\
455
+ "import_url":"https://github.com/linuxserver/'${LS_REPO}'.git",\
456
+ "issues_access_level":"disabled",\
457
+ "merge_requests_access_level":"disabled",\
458
+ "repository_access_level":"enabled",\
459
+ "visibility":"public"}' '''
460
+ sh ''' curl -H "Private-Token: ${GITLAB_TOKEN}" -X PUT "https://gitlab.com/api/v4/projects/Linuxserver.io%2F${LS_REPO}" \
461
+ -d "mirror=true&import_url=https://github.com/linuxserver/${LS_REPO}.git" '''
436
462
}
437
463
}
438
464
/* ###############
0 commit comments