Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit f3e0b9b

Browse files
authored
improved generation pipeline yaml and updated infra guide (#405)
1 parent e1e0008 commit f3e0b9b

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

azure-pipelines/templates/infra-generation-pipeline.yml

+23-4
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,40 @@ steps:
7575
set -e
7676
7777
# 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)
7979
echo "Commit Hash: $commit_hash"
8080
8181
# Clone Generated Repo and copy generated components over
8282
echo "Cloning Generated Repo: $GENERATED_REPO"
8383
git clone $GENERATED_REPO
84+
repo_url=$GENERATED_REPO
8485
8586
# Extract repo name from url
86-
repo_url=$GENERATED_REPO
8787
repo=${repo_url##*/}
8888
repo_name=${repo%.*}
8989
9090
cd "$repo_name"
91+
92+
git pull
93+
9194
rsync -rv --exclude=.terraform $HOME/$PROJECT_DIRECTORY-generated .
9295
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+
93112
# Set git identity
94113
git config user.email "[email protected]"
95114
git config user.name "Automated Account"
@@ -101,7 +120,7 @@ steps:
101120
102121
# Format Terraform files
103122
terraform fmt
104-
123+
105124
# Add generated files to repository
106125
git status
107126
git add .
@@ -142,4 +161,4 @@ steps:
142161
fi
143162
env:
144163
ACCESS_TOKEN_SECRET: $(ACCESS_TOKEN_SECRET)
145-
displayName: 'Commit and Push to Generated Repository'
164+
displayName: 'Commit and Push to Generated Repository'

guides/infra/spk-infra-generation-pipeline.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ orchestrator for your Infrastructure Generation workflow using `spk infra`.
66
## Prerequisites
77

88
1. _Permissions_: The ability to create Projects in your Azure DevOps
9-
Organization.
9+
Organization and set security permissions to "Contribute" and "Contribute to
10+
Pull Requests" for git repositories.
1011
2. _High Level Definitions_: Your own infrastructure high level definitions for
1112
your deployment. You can refer to a sample repo
1213
[here](https://github.com/yradsmikham/spk-infra-hld). You should be able to
@@ -28,6 +29,10 @@ two flavors:
2829
- [Azure DevOps](https://github.com/microsoft/bedrock/blob/master/gitops/azure-devops/ADORepos.md)
2930
- [GitHub](https://github.com/microsoft/bedrock/blob/master/gitops/azure-devops/GitHubRepos.md)
3031

32+
**Note**: If your git repos are in different Azure DevOps organizations and/or
33+
pojects, be sure that the generated git repo has "Contribute" and "Contribute to
34+
Pull Requests" permissions configured in the security settings.
35+
3136
### 2. Add Azure Pipeline Build YAML
3237

3338
The SPK repository has a
@@ -65,8 +70,8 @@ If using Azure DevOps repos, be sure to include the additional environment
6570
variables:
6671

6772
```
68-
AZDO_ORG_NAME: Azure DevOps organization url (i.e. https://dev.azure.com/org_name/)
69-
AZDO_PROJECT_NAME: The name of the project in your Azure DevOps organization where the repository is hosted
73+
AZDO_ORG_NAME: Azure DevOps organization url where the generated repo is hosted (i.e. https://dev.azure.com/org_name/)
74+
AZDO_PROJECT_NAME: The name of the project in your Azure DevOps organization where the generated repo is hosted
7075
```
7176

7277
You can use `spk` to create the Azure DevOps Variable Groups by executing

0 commit comments

Comments
 (0)