Skip to content

Commit 078746e

Browse files
committed
Removed env variable GIT_BRANCH, no need, since the new branch will created for CI pipeline, if it does not exist.
1 parent fda42dc commit 078746e

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

.gitlab-ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ variables:
397397
GIT_USER_MAIL: ${GIT_USER_NAME}@inverse.ca
398398
#GIT_USER_PASSWORD: provided through environment
399399
GIT_REPO: github.com/akainverse/website-pfcom
400-
GIT_BRANCH: ci-release
401400
SRC_FILE: result/switches.json
402401
DST_FILE: data/switches.json
403402
script:

ci/lib/build/generate-material.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ generate_material() {
4747
-e GIT_USER_MAIL \
4848
-e GIT_USER_PASSWORD \
4949
-e GIT_REPO \
50-
-e GIT_BRANCH \
5150
-e CI_PIPELINE_ID \
5251
-v ${PF_SRC_DIR}/conf:/usr/local/pf/conf \
5352
-v ${PF_SRC_DIR}/addons/dev-helpers/bin:/usr/local/pf/addons/dev-helpers/bin \

ci/lib/release/publish-to-git.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ configure_and_check() {
2020
GIT_REPO=${GIT_REPO:-git.example.com/user/repo.git}
2121
GIT_CLONE_METHOD=${GIT_CLONE_METHOD:-https://}
2222
GIT_LOCAL_PATH=$(mktemp -d)
23-
GIT_BRANCH=${GIT_BRANCH:-main}
2423

2524
GIT_REPO_URL=${GIT_CLONE_METHOD}${GIT_USER_NAME}:${GIT_USER_PASSWORD}@${GIT_REPO}
2625

@@ -33,11 +32,13 @@ generate_git_config() {
3332
git config --global user.email "${GIT_USER_MAIL}"
3433
# to store credentials in memory for a short period of time
3534
git config --global credential.helper cache
35+
# set 'autoSetupRemote' in order to automatically set an upstream tracking branch
36+
git config --global push.autoSetupRemote true
3637
}
3738

3839
clone_git_repository() {
3940
log_subsection "Clone git repository"
40-
git clone -b ${GIT_BRANCH} ${GIT_REPO_URL} ${GIT_LOCAL_PATH}
41+
git clone ${GIT_REPO_URL} ${GIT_LOCAL_PATH}
4142
}
4243

4344
compare_files() {
@@ -58,15 +59,24 @@ update_git_repository() {
5859
log_subsection "Commit and push changes"
5960
local src_file=$1
6061
local dst_file=$2
62+
local git_ci_branch="ci-release-${CI_PIPELINE_ID}"
6163
local date_now=$(date +"%Y-%m-%d %H:%M:%S")
6264
local commit_message="Automatic update by pipeline ${CI_PIPELINE_ID} ${date_now}"
6365

6466
cp -v ${src_file} ${dst_file}
6567

66-
git -C ${GIT_LOCAL_PATH} add ${dst_file}
67-
git -C ${GIT_LOCAL_PATH} commit -am "${commit_message}"
68-
# will use credential helper, no need to specify again credentials
69-
git -C ${GIT_LOCAL_PATH} push
68+
# Check the branch exists ot not.
69+
if git -C ${GIT_LOCAL_PATH} ls-remote --exit-code --heads origin "$git_ci_branch" > /dev/null 2>&1; then
70+
# Skip commit
71+
echo "Skip commit, branch '$git_ci_branch' already exists."
72+
else
73+
git -C ${GIT_LOCAL_PATH} checkout -b "$git_ci_branch"
74+
75+
git -C ${GIT_LOCAL_PATH} add ${dst_file}
76+
git -C ${GIT_LOCAL_PATH} commit -am "${commit_message}"
77+
# will use credential helper, no need to specify again credentials
78+
git -C ${GIT_LOCAL_PATH} push
79+
fi
7080
}
7181

7282
log_section "Configure and check"

0 commit comments

Comments
 (0)