ci: refactor pipeline for next-release branch and changelog generation

This commit is contained in:
2024-10-02 20:40:53 +02:00
parent bbb18fcf3c
commit 1fefccde27
2 changed files with 21 additions and 8 deletions
+16 -8
View File
@@ -39,13 +39,21 @@ handle_mr:
GIT_STRATEGY: clone # clone entire repo instead of reusing workspace
GIT_DEPTH: 0 # avoid shallow clone to give cliff all the info it needs
before_script:
- 'apk add --no-cache git jq curl'
- 'git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"'
- 'git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"'
script:
- 'git checkout -b next-release'
- 'git add CHANGELOG.md'
- 'git commit -m "ci: prepare release $(git-cliff --bumped-version 2>/dev/null)"'
- 'git push origin next-release --force'
- 'apk add --no-cache jq curl'
script: |
echo "Project: ${CI_PROJECT_ID}"
echo "Token: ${CI_JOB_TOKEN}"
MRS=$(curl -s -H "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/merge_requests?state=opened&source_branch=next-release")
echo "${MRS}"
MR=$(echo "${MRS} | jq ".[].id")
if [ -n "${MR}" ]; then
curl -s -X POST -H "JOB-TOKEN: $CI_JOB_TOKEN" "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/repository/branches?branch=next-release&ref=${CI_DEFAULT_BRANCH}"
fi
BODY="$(jq --null-input -c --arg title "ci: prepare release $(cat VERSION)" --arg content "$(cat CHANGES.md | base64 -w0)" '{"branch": "next-release", "author_email": "releaser@unbound.se", "author_name": "Releaser", "content": $content, "commit_message": $title, "encoding": "base64"}')"
curl -X PUT \
-H "JOB-TOKEN: $CI_JOB_TOKEN" \
-H "Content-Type: application/json" \
--data "${BODY}" \
"https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/repository/files/CHANGELOG%2Emd"
rules:
- if: $CI_DEFAULT_BRANCH == $CI_COMMIT_BRANCH
+5
View File
@@ -0,0 +1,5 @@
# Changelog
All notable changes to this project will be documented in this file.
<!-- generated by git-cliff -->