From 841e39fdb582b321757e4288ce0a084f31a8c298 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Sat, 9 Aug 2025 14:47:01 +0000 Subject: [PATCH] Simplify ci logic --- .gitlab-ci.yml | 138 +++--------------------------------------- .gitlab/ci/build.yml | 54 +++++++++++++++++ .gitlab/ci/check.yml | 11 ++++ .gitlab/ci/update.yml | 55 +++++++++++++++++ 4 files changed, 129 insertions(+), 129 deletions(-) create mode 100644 .gitlab/ci/build.yml create mode 100644 .gitlab/ci/check.yml create mode 100644 .gitlab/ci/update.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f8d49c6..cd0fefa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,129 +1,9 @@ -stages: - - check - - update - - build - - release - -version_update: - stage: update - tags: - - nix - rules: - - if: '$CI_PIPELINE_SOURCE == "web"' - artifacts: - reports: - dotenv: update.env - script: - - nix run ".#update" > update.env - - |- - if git diff --quiet; then - echo "Found changes to make" - git checkout -b "sword-rev/$CI_PIPELINE_IID" - echo "BRANCH=sword-rev/$CI_PIPELINE_IID" >> update.env - git stage . - git commit -m "Automatic update #$CI_PIPELINE_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: update - needs: - - version_update - dependencies: - - version_update - variables: - GIT_STRATEGY: none - GITLAB_PRIVATE_TOKEN: $CI_GIT_TOKEN - rules: - - if: '$CI_PIPELINE_SOURCE == "web"' - script: - - test -z ${DO_UPDATE} && { echo "No updates required. Not crating PR"; exit 0; } - - >- - CREATE_MR=$(gitlab project-merge-request create - --remove-source-branch true - --project-id ${CI_PROJECT_ID} - --source-branch "${BRANCfh}" - --target-branch "main" - --title "Update sword to r$NEW_REV") - - 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" - -check: - stage: check - rules: - - if: '$CI_PIPELINE_SOURCE == "web"' - when: never - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_PIPELINE_SOURCE == "push"' - tags: - - nix - script: - - nix flake check - - TAG=$(date +%Y.%m.%d).$CI_COMMIT_SHORT_SHA - - echo "TAG=$TAG" > variables.env - artifacts: - reports: - dotenv: variables.env - -build: - stage: build - needs: - - job: check - artifacts: true - parallel: - matrix: - - ARCH: [x86, ucrt] - tags: - - nix - rules: - - if: '$CI_PIPELINE_SOURCE == "web"' - when: never - - if: '$CI_PIPELINE_SOURCE == "merge_request_event"' - - if: '$CI_PIPELINE_SOURCE == "push"' - script: - - nix run -L ".#${ARCH}" - - ls -l - - URL=$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/sword-utils/$TAG/sword-${ARCH}-${TAG}.tar.xz - - >- - if [ "$CI_COMMIT_BRANCH" == "main" ]; then - curl -i --fail-with-body --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./sword.tar.xz "${URL}" - fi - - echo "${ARCH}_TARBALL=${URL}" > "build.env.${ARCH}" - artifacts: - reports: - dotenv: build.env.$ARCH - -"Create release": - stage: release - image: registry.gitlab.com/gitlab-org/release-cli:latest - tags: - - docker - rules: - - if: '$CI_PIPELINE_SOURCE == "web"' - when: never - - if: $CI_COMMIT_BRANCH == "main" - when: always - needs: - - job: check - artifacts: true - - job: build - artifacts: true - script: echo "Tagging as released" - release: - name: Release $TAG - tag_name: "$TAG" - description: Automatic SWORD utils build for Windows - assets: - links: - - name: Windows (x86-64) release - url: "${x86_TARBALL}" - - name: Windows (x86-64) release with UCRT - url: "${ucrt_TARBALL}" +include: + - local: .gitlab/ci/update.yml + rules: + - if: '$CI_PIPELINE_SOURCE == "web"' + - local: .gitlab/ci/build.yml + rules: + - if: $CI_PIPELINE_SOURCE == "merge_request_event" + - if: $CI_PIPELINE_SOURCE == "push" + - if: $CI_PIPELINE_SOURCE == "tag" diff --git a/.gitlab/ci/build.yml b/.gitlab/ci/build.yml new file mode 100644 index 0000000..8f15540 --- /dev/null +++ b/.gitlab/ci/build.yml @@ -0,0 +1,54 @@ +stages: + - check + - build + - release + +include: + - local: .gitlab/ci/check.yml + +build: + stage: build + needs: + - job: check + artifacts: true + parallel: + matrix: + - ARCH: [x86, ucrt] + tags: + - nix + script: + - nix run -L ".#${ARCH}" + - ls -l + - URL=$CI_API_V4_URL/projects/$CI_PROJECT_ID/packages/generic/sword-utils/$TAG/sword-${ARCH}-${TAG}.tar.xz + - >- + if [ "$CI_PIPELINE_SOURCE" == "tag" ]; then + curl -i --fail-with-body --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file ./sword.tar.xz "${URL}" + fi + - echo "${ARCH}_TARBALL=${URL}" > "build.env.${ARCH}" + artifacts: + reports: + dotenv: build.env.$ARCH + +"Create release": + stage: release + image: registry.gitlab.com/gitlab-org/release-cli:latest + tags: + - docker + rules: + - if: $CI_PIPELINE_SOURCE == "tag" + needs: + - job: check + artifacts: true + - job: build + artifacts: true + script: echo "Tagging as released" + release: + name: Release $TAG + tag_name: "$TAG" + description: Automatic SWORD utils build for Windows + assets: + links: + - name: Windows (x86-64) release + url: "${x86_TARBALL}" + - name: Windows (x86-64) release with UCRT + url: "${ucrt_TARBALL}" diff --git a/.gitlab/ci/check.yml b/.gitlab/ci/check.yml new file mode 100644 index 0000000..b32bbfa --- /dev/null +++ b/.gitlab/ci/check.yml @@ -0,0 +1,11 @@ +check: + stage: check + tags: + - nix + script: + - nix flake check + - TAG=$(date +%Y.%m.%d).$CI_COMMIT_SHORT_SHA + - echo "TAG=$TAG" > variables.env + artifacts: + reports: + dotenv: variables.env diff --git a/.gitlab/ci/update.yml b/.gitlab/ci/update.yml new file mode 100644 index 0000000..f507bc3 --- /dev/null +++ b/.gitlab/ci/update.yml @@ -0,0 +1,55 @@ +stages: + - update + - merge + +version_update: + stage: update + tags: + - nix + artifacts: + reports: + dotenv: update.env + script: + - nix run ".#update" > update.env + - |- + if git diff --quiet; then + echo "No changes necessary" + else + echo "Found changes to make" + git checkout -b "sword-rev/$CI_PIPELINE_IID" + echo "BRANCH=sword-rev/$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_PIPELINE_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: merge + 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 crating PR"; exit 0; } + - >- + CREATE_MR=$(gitlab project-merge-request create + --remove-source-branch true + --project-id ${CI_PROJECT_ID} + --source-branch "${BRANCfh}" + --target-branch "main" + --title "Update sword to r$NEW_REV") + - 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"