-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneClickBranchMerge.yaml
More file actions
96 lines (82 loc) · 2.4 KB
/
Copy pathOneClickBranchMerge.yaml
File metadata and controls
96 lines (82 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
# set repository URL and branch names
REPO_URL="https://github.com/your-username/your-repo.git"
MASTER_BRANCH="master"
DEVELOP_BRANCH="develop"
# Check if the release branch file exists
if [ -f ".release_branch" ]; then
# Read the release branch name from the file
RELEASE_BRANCH=$(cat .release_branch)
else
# Set the name of the release branch
RELEASE_BRANCH="release"
fi
# create the repository
git clone $REPO_URL
cd your-repo
# check if the branches already exist
if git ls-remote --heads $REPO_URL $MASTER_BRANCH | grep -q $MASTER_BRANCH; then
echo "Master branch already exists"
else
# create the master branch
git init
touch README.md
git add README.md
git commit -m "Initial commit"
git branch $MASTER_BRANCH
git remote add origin $REPO_URL
git push -u origin $MASTER_BRANCH
fi
if git ls-remote --heads $REPO_URL $DEVELOP_BRANCH | grep -q $DEVELOP_BRANCH; then
echo "Develop branch already exists"
else
# create the develop branch
git branch $DEVELOP_BRANCH
git push --set-upstream origin $DEVELOP_BRANCH
fi
if git ls-remote --heads $REPO_URL $RELEASE_BRANCH | grep -q $RELEASE_BRANCH; then
echo "Release branch already exists"
else
# create the release branch
git checkout $DEVELOP_BRANCH
git branch $RELEASE_BRANCH
git push --set-upstream origin $RELEASE_BRANCH
fi
# set up the deployment pipeline
echo "
stages:
- build
- test
- deploy
- release
build:
script:
- echo 'Building the project...'
test:
script:
- echo 'Running tests...'
deploy:
script:
- echo 'Deploying to production...'
release:
script:
# merge the previous release branch into the master branch
PREVIOUS_RELEASE_BRANCH=$(git branch -r | grep origin/$RELEASE_BRANCH | cut -d/ -f2)
if [[ $PREVIOUS_RELEASE_BRANCH ]]; then
git checkout $MASTER_BRANCH
git merge --no-ff origin/$PREVIOUS_RELEASE_BRANCH
# add deployment steps here, for example:
# ssh into the server and pull the latest changes
# run any build steps or migrations
# restart the server
git push origin $MASTER_BRANCH
git checkout $DEVELOP_BRANCH
fi
# create a new release branch from the develop branch
NEW_RELEASE_BRANCH="$RELEASE_BRANCH-$(date +%Y%m%d-%H%M%S)"
git checkout $DEVELOP_BRANCH
git branch $NEW_RELEASE_BRANCH
git push --set-upstream origin $NEW_RELEASE_BRANCH
#Save the name of the new release branch to the file for next time
echo $NEW_RELEASE_BRANCH > .release_branch
" > .gitlab-ci.yml