-
Notifications
You must be signed in to change notification settings - Fork 96
197 lines (171 loc) · 6.21 KB
/
azure-ipam-build.yml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Azure IPAM Build
run-name: Azure IPAM Production Container Build
on:
push:
branches:
- main
permissions:
id-token: write
contents: write
pull-requests: read
env:
ACR_NAME: ${{ vars.IPAM_PROD_ACR }}
jobs:
version:
name: Update Azure IPAM Version
runs-on: ubuntu-latest
outputs:
ipamVersion: ${{ steps.updateVersion.outputs.ipamVersion }}
prNumber: ${{ fromJson(steps.getPullRequestData.outputs.result).number }}
steps:
- run: echo "Job triggered by a ${{ github.event_name }} event to main."
- name: "Setup NodeJS v18"
id: setupNode
uses: actions/setup-node@v4
with:
node-version: 18
- name: Checkout Azure IPAM Code
uses: actions/checkout@v4
- uses: actions/github-script@v7
id: getPullRequestData
with:
script: |
return (
await github.rest.repos.listPullRequestsAssociatedWithCommit({
commit_sha: context.sha,
owner: context.repo.owner,
repo: context.repo.repo,
})
).data[0];
- name: Configure Git
id: configureGit
run: |
git config --global user.name "IPAM GitHub Actions"
git config --global user.email "[email protected]"
- name: Create Temporary Branch
id: createBranch
env:
prNumber: ${{ fromJson(steps.getPullRequestData.outputs.result).number }}
run: |
git checkout -b ipam-version-${prNumber}
git push origin ipam-version-${prNumber}
- name: "Increment Azure IPAM Version"
id: updateVersion
working-directory: tools
env:
prBody: ${{ fromJson(steps.getPullRequestData.outputs.result).body }}
shell: pwsh
run: |
$version = [regex]::matches($env:prBody, '(?<=\[version:).*(?=])').value
$major = $env:prBody -match '(?<=\[)major(?=])'
$minor = $env:prBody -match '(?<=\[)minor(?=])'
$build = $env:prBody -match '(?<=\[)build(?=])'
try {
$version = [System.Version]$version
$newVersion = "{0}.{1}.{2}" -f $version.Major, $version.Minor, $version.Build
} catch {
$version = $null
}
if ($version) {
./version.ps1 -Version $newVersion
} elseif ($major) {
./version.ps1 -BumpMajor
} elseif ($minor) {
./version.ps1 -BumpMinor
} else {
./version.ps1 -BumpBuild
}
- name: Install NPM Packages
id: installNpmPackages
working-directory: ui
run: |
npm install
- name: "Create Azure IPAM ZIP Asset"
id: buildZipAsset
working-directory: tools
shell: pwsh
run: |
./build.ps1 -Path ../assets/
- name: Commit Updated Azure IPAM Code
id: commitCode
env:
prNumber: ${{ fromJson(steps.getPullRequestData.outputs.result).number }}
run: |
git commit -a -m "Updated Azure IPAM Version"
git push origin ipam-version-${prNumber}
release:
name: Create Azure IPAM Release
runs-on: ubuntu-latest
needs: [ version ]
steps:
- name: Checkout Azure IPAM Code
uses: actions/checkout@v4
with:
sparse-checkout: |
assets
- name: Create and Merge Pull Reuest
id: pullRequest
env:
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
prNumber: ${{ needs.version.outputs.prNumber }}
run: |
gh pr create --base main --head "ipam-version-${prNumber}" --title "Update Azure IPAM Version" --body "-Updated Version to v${{ needs.version.outputs.ipamVersion }}"
gh pr checks "ipam-version-${prNumber}" --watch
gh pr merge "ipam-version-${prNumber}" -t "Merge pull request from Azure/ipam-version-${prNumber} [skip ci]" -m -d
- name: Pull Merged Code from Main Branch
id: pullMainCode
run: |
git pull
- name: Delete Temporary Branch
id: deleteBranch
env:
prNumber: ${{ needs.version.outputs.prNumber }}
run: |
git push origin --delete "ipam-version-${prNumber}"
- name: Publish Azure IPAM Release
id: publishRelease
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tagName: v${{ needs.version.outputs.ipamVersion }}
run: |
gh release create "$tagName" \
--repo="$GITHUB_REPOSITORY" \
--title="$tagName" \
--notes "Azure IPAM Release"
- name: Upload Azure IPAM Release Asset
id: uploadReleaseAsset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tagName: v${{ needs.version.outputs.ipamVersion }}
assetPath: ./assets/ipam.zip
run: |
gh release upload "$tagName" "$assetPath"
build:
name: Build Azure IPAM Containers
runs-on: ubuntu-latest
needs: [ version, release ]
steps:
- name: Azure login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
enable-AzPSSession: true
- name: Checkout Azure IPAM Code
uses: actions/checkout@v4
with:
sparse-checkout: |
engine
ui
lb
- name: Build Azure IPAM Containers
env:
IPAM_VERSION: ${{ needs.version.outputs.ipamVersion }}
run: |
az acr build -r $ACR_NAME -t ipam:$IPAM_VERSION -t ipam:latest -f ./Dockerfile.deb .
az acr build -r $ACR_NAME -t ipamfunc:$IPAM_VERSION -t ipamfunc:latest -f ./Dockerfile.func .
az acr build -r $ACR_NAME -t ipam-engine:$IPAM_VERSION -t ipam-engine:latest -f ./engine/Dockerfile.deb ./engine
az acr build -r $ACR_NAME -t ipam-func:$IPAM_VERSION -t ipam-func:latest -f ./engine/Dockerfile.func ./engine
az acr build -r $ACR_NAME -t ipam-ui:$IPAM_VERSION -t ipam-ui:latest -f ./ui/Dockerfile.deb ./ui
az acr build -r $ACR_NAME -t ipam-lb:$IPAM_VERSION -t ipam-lb:latest -f ./lb/Dockerfile ./lb