Simplify ci logic

This commit is contained in:
Greg Hellings
2025-08-09 14:47:01 +00:00
parent b7b096e76f
commit 841e39fdb5
4 changed files with 129 additions and 129 deletions
+6 -126
View File
@@ -1,129 +1,9 @@
stages:
- check
- update
- build
- release
version_update:
stage: update
tags:
- nix
include:
- local: .gitlab/ci/update.yml
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
- local: .gitlab/ci/build.yml
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}"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_PIPELINE_SOURCE == "push"
- if: $CI_PIPELINE_SOURCE == "tag"
+54
View File
@@ -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}"
+11
View File
@@ -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
+55
View File
@@ -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"