Skip to content
Snippets Groups Projects
Commit 0accc344 authored by Richard Glosner's avatar Richard Glosner
Browse files

internal: add stage for automatic change propagation to main

parent b5072ca9
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,14 @@ image: python:3.10-bullseye
variables:
GIT_SUBMODULE_STRATEGY: normal
PREFERRED_BRANCH: "citadel" # Change this to your actual release branch name
MAIN_BRANCH: "main"
stages:
- setup
- build
- deploy
- copy_to_main
default:
tags:
......@@ -41,3 +44,51 @@ pages:
- public
only:
- citadel
copy_to_main:
stage: copy_to_main
variables:
GIT_DEPTH: "0"
script:
- git config --global user.email "ci@gitlab.com"
- git config --global user.name "CI Bot"
- git config pull.rebase true
- export COMMIT_NAME=$(git log --no-merges -1 --pretty=format:%s)
- export COMMIT_HASH=$(git log --no-merges -1 --pretty=format:%h)
- export COPY_BRANCH="COPY-${COMMIT_HASH}"
# Checkout main and create a new branch
- git fetch origin
- git checkout $MAIN_BRANCH
- git pull origin $MAIN_BRANCH
- git checkout -b $COPY_BRANCH
# Cherry-pick the commit that triggered the pipeline
- git cherry-pick -m 1 $COMMIT_HASH || echo "Cherry-pick failed. Manual resolution needed." > cherry_pick_failed
# Push the branch
- git push https://oauth2:${GITLAB_TOKEN}@gitlab.fi.muni.cz/${CI_PROJECT_PATH}.git HEAD:"$COPY_BRANCH"
# Create Merge Request
- |
if [ -f cherry_pick_failed ]; then
DESCRIPTION="**Cherry-pick failed. Manual resolution needed. Commit: ${COMMIT_HASH}**."
else
DESCRIPTION="**Cherry-pick applied successfully. Commit: ${COMMIT_NAME} (hash: ${COMMIT_HASH}) applied to main.**"
fi
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--data "source_branch=$COPY_BRANCH" \
--data "target_branch=$MAIN_BRANCH" \
--data "title=[COPY]-${COMMIT_NAME}" \
--data "description=$DESCRIPTION" \
--data "remove_source_branch=true" \
--data "squash=true" \
"https://gitlab.fi.muni.cz/api/v4/projects/$CI_PROJECT_ID/merge_requests" \
> /dev/null
rules:
- if: $CI_COMMIT_BRANCH == $PREFERRED_BRANCH
when: manual
dependencies:
- build
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment