From ec0b87cee70c959e9e35166214f4becd4d7fe11d Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 19 Aug 2025 20:26:37 -0500 Subject: [PATCH] First attempt at auto update job --- .gitlab-ci.yml | 6 +++++ .gitlab/update.yml | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .gitlab/update.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 558e58e..abf38dd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -12,10 +12,16 @@ workflow: when: never # Run reduced pipeline for branches - if: $CI_COMMIT_BRANCH + - if: $CI_PIPELINE_SOURCE == "web" include: # Low-effort, we can always do lint checks, validations, and so forth - local: .gitlab/always.yml + rules: + - if: $CI_PIPELINE_SOURCE != "web" + - local: .gitlab/update.yml + rules: + - if: $CI_PIPELINE_SOURCE == "web" # Actual download of ISOs and building of images. This should only be # done some of the time - local: .gitlab/build.yml diff --git a/.gitlab/update.yml b/.gitlab/update.yml new file mode 100644 index 0000000..7902c33 --- /dev/null +++ b/.gitlab/update.yml @@ -0,0 +1,55 @@ +version_update: + stage: generate + image: "alpine/git:latest" + artifacts: + reports: + dotenv: update.env + script: + - |- + set -x + shopt -s globstar + for updater in distros/**/update.sh; do + bash "$updater" + done + - |- + if git diff --quiet; then + echo "No changes necessary" + else + echo "Found updates to make" + git checkout -b "autoupdate/$CI_PIPELINE_IID" + echo "BRANCH=autoupdate/$CI_PIPELINE_IID" >> update.env + git config set user.name "Greg Hellings - automation" + git config set user.email "greg@thehellings.com" + git stage . + git commit -m "Automatic update $CI_PIPEILNE_IID" + git push "https://${GITLAB_USER_LOGIN}:${CI_GIT_TOKEN}@${CI_REPOSITORY_URL#*@}" HEAD + fi + +create_pr: + image: + name: registry.gitlab.com/python-gitlab/python-gitlab:latest + entrypoint: [ '' ] + stage: trigger + needs: + - version_update + dependencies: + - version_update + variables: + GIT_STRATEGY: none + GITLAB_PRIVATE_TOKEN: $CI_GIT_TOKEN + script: + - test -z ${DO_UPDATE} && { echo "No updates required. Not creating PR"; exit 0; } + - >- + CREATE_MR=$(gitlab project-merge-request create + --remote-source-branch true + --project-id ${CI_PROJECT_ID} + --source-branch "${BRANCH}" + --target-branch "main" + --title "Update ISO checksums" + - IID=${CREATE_MR#* } + - >- + gitlab project-merge-request merge + --project-id ${CI_PROJECT_ID} + --iid ${IID} + --merge-when-pipeline-succeeds true + - echo "PR set to auto-merge if build succeeds"