Skip to content

Commit 8af2a73

Browse files
committed
Fixed by comments.
1 parent 078746e commit 8af2a73

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,39 @@ compare_files() {
5656
}
5757

5858
update_git_repository() {
59-
log_subsection "Commit and push changes"
59+
# Chech the parameters.
60+
if [[ $# -lt 2 ]]; then
61+
echo "Usage: $0 <src_file> <dst_file>"
62+
exit 1
63+
fi
64+
6065
local src_file=$1
6166
local dst_file=$2
6267
local git_ci_branch="ci-release-${CI_PIPELINE_ID}"
6368
local date_now=$(date +"%Y-%m-%d %H:%M:%S")
6469
local commit_message="Automatic update by pipeline ${CI_PIPELINE_ID} ${date_now}"
6570

66-
cp -v ${src_file} ${dst_file}
67-
68-
# Check the branch exists ot not.
71+
# Check the branch exists or not.
6972
if git -C ${GIT_LOCAL_PATH} ls-remote --exit-code --heads origin "$git_ci_branch" > /dev/null 2>&1; then
7073
# Skip commit
7174
echo "Skip commit, branch '$git_ci_branch' already exists."
7275
else
73-
git -C ${GIT_LOCAL_PATH} checkout -b "$git_ci_branch"
76+
log_subsection "Commit and push changes"
77+
cp -v ${src_file} ${dst_file}
7478

79+
git -C ${GIT_LOCAL_PATH} checkout -b "$git_ci_branch"
7580
git -C ${GIT_LOCAL_PATH} add ${dst_file}
7681
git -C ${GIT_LOCAL_PATH} commit -am "${commit_message}"
7782
# will use credential helper, no need to specify again credentials
7883
git -C ${GIT_LOCAL_PATH} push
7984
fi
8085
}
8186

87+
cleanup() {
88+
rm -rf "${GIT_LOCAL_PATH:-}"
89+
}
90+
trap cleanup EXIT
91+
8292
log_section "Configure and check"
8393
configure_and_check
8494

0 commit comments

Comments
 (0)