2019-12-26 22:10:19 +05:30
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This script triggers a merge train job to sync an EE stable branch to its
|
|
|
|
# corresponding CE stable branch.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
if [[ "$MERGE_TRAIN_TRIGGER_TOKEN" == '' ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'The variable MERGE_TRAIN_TRIGGER_TOKEN must be set to a non-empty value'
|
|
|
|
exit 1
|
2019-12-26 22:10:19 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$MERGE_TRAIN_TRIGGER_URL" == '' ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'The variable MERGE_TRAIN_TRIGGER_URL must be set to a non-empty value'
|
|
|
|
exit 1
|
2019-12-26 22:10:19 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$CI_COMMIT_REF_NAME" == '' ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'The variable CI_COMMIT_REF_NAME must be set to a non-empty value'
|
|
|
|
exit 1
|
2019-12-26 22:10:19 +05:30
|
|
|
fi
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
if [[ "$SOURCE_PROJECT" == '' ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'The variable SOURCE_PROJECT must be set to a non-empty value'
|
|
|
|
exit 1
|
2020-01-01 13:55:28 +05:30
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$TARGET_PROJECT" == '' ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'The variable TARGET_PROJECT must be set to a non-empty value'
|
|
|
|
exit 1
|
2020-01-01 13:55:28 +05:30
|
|
|
fi
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
if [[ "$TARGET_PROJECT" != "gitlab-org/gitlab-foss" ]]
|
|
|
|
then
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'This is a security FOSS merge train'
|
|
|
|
echo "Checking if $CI_COMMIT_SHA is available on canonical"
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
gitlab_com_commit_status=$(curl -s "https://gitlab.com/api/v4/projects/278964/repository/commits/$CI_COMMIT_SHA" | jq -M .status)
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
if [[ "$gitlab_com_commit_status" != "null" ]]
|
|
|
|
then
|
|
|
|
echo 'Commit available on canonical, skipping merge train'
|
|
|
|
exit 0
|
|
|
|
fi
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
echo 'Commit not available, triggering a merge train'
|
2020-03-13 15:44:24 +05:30
|
|
|
fi
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
curl -f \
|
|
|
|
-X POST \
|
2020-06-23 00:09:42 +05:30
|
|
|
-F token="$MERGE_TRAIN_TRIGGER_TOKEN" \
|
|
|
|
-F ref=master \
|
|
|
|
-F "variables[MERGE_FOSS]=1" \
|
|
|
|
-F "variables[SOURCE_BRANCH]=$CI_COMMIT_REF_NAME" \
|
|
|
|
-F "variables[TARGET_BRANCH]=${CI_COMMIT_REF_NAME/-ee/}" \
|
|
|
|
-F "variables[SOURCE_PROJECT]=$SOURCE_PROJECT" \
|
|
|
|
-F "variables[TARGET_PROJECT]=$TARGET_PROJECT" \
|
|
|
|
"$MERGE_TRAIN_TRIGGER_URL"
|