@@ -75,21 +75,40 @@ steps:
75
75
set -e
76
76
77
77
# Retrieve most recent commit hash from HLD repo
78
- commit_hash=$(git rev-parse HEAD)
78
+ commit_hash=$(git rev-parse HEAD | cut -c1-7 )
79
79
echo "Commit Hash: $commit_hash"
80
80
81
81
# Clone Generated Repo and copy generated components over
82
82
echo "Cloning Generated Repo: $GENERATED_REPO"
83
83
git clone $GENERATED_REPO
84
+ repo_url=$GENERATED_REPO
84
85
85
86
# Extract repo name from url
86
- repo_url=$GENERATED_REPO
87
87
repo=${repo_url##*/}
88
88
repo_name=${repo%.*}
89
89
90
90
cd "$repo_name"
91
+
92
+ git pull
93
+
91
94
rsync -rv --exclude=.terraform $HOME/$PROJECT_DIRECTORY-generated .
92
95
96
+ # Check if PR branch already exists:
97
+ pr_list=$(git ls-remote origin)
98
+ if [[ $pr_list == *"pr-$commit_hash"* ]]; then
99
+ echo "PR Branch already exist. Iterating..."
100
+ count=$(git ls-remote origin | grep "pr-$commit_hash" | wc -l | tr -d " ")
101
+ count=$((count + 1))
102
+ PR_BRANCH_NAME=pr-$commit_hash-$count
103
+ echo "PR BRANCH NAME: $PR_BRANCH_NAME"
104
+ git checkout -b $PR_BRANCH_NAME
105
+ else
106
+ echo "PR Branch does not exist. Creating a new PR Branch"
107
+ PR_BRANCH_NAME=pr-$commit_hash-1
108
+ echo "PR BRANCH NAME: $PR_BRANCH_NAME"
109
+ git checkout -b $PR_BRANCH_NAME
110
+ fi
111
+
93
112
# Set git identity
94
113
git config user.email "[email protected] "
95
114
git config user.name "Automated Account"
@@ -101,7 +120,7 @@ steps:
101
120
102
121
# Format Terraform files
103
122
terraform fmt
104
-
123
+
105
124
# Add generated files to repository
106
125
git status
107
126
git add .
@@ -142,4 +161,4 @@ steps:
142
161
fi
143
162
env :
144
163
ACCESS_TOKEN_SECRET : $(ACCESS_TOKEN_SECRET)
145
- displayName : ' Commit and Push to Generated Repository'
164
+ displayName : ' Commit and Push to Generated Repository'
0 commit comments