-
Notifications
You must be signed in to change notification settings - Fork 73
270 lines (221 loc) · 5.91 KB
/
pull.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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
---
name: "AzOps - Pull"
on:
#
# Workflow Dispatch
# This is to invoke the action from the GitHub UI
#
workflow_dispatch:
#
# Repository Dispatch
# Invoke this action based on event / webhook, this
# could be from an activity logs when a specific condition
# is met and triggered
#
repository_dispatch:
types:
- "Enterprise-Scale Deployment"
- "Enterprise-Scale Event"
#
# Schedule
# This is an optional trigger to pull the latest Azure
# hierarchy into the Git repository in a recurring
# manner.
#
# Default: Every 6 hours
#
schedule:
- cron: "0 */6 * * *"
#
# Workflow Run
# Triggers this workflow upon the completion of
# the Push action.
#
workflow_run:
workflows: ["AzOps - Push"]
branches: [main]
types:
- completed
#
# Permissions required for the pipeline to interact with repo and federated credentials
#
permissions:
id-token: write
contents: write
pull-requests: write
env:
#
# Credentials
#
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_ENVIRONMENT: ${{ secrets.ARM_ENVIRONMENT }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
AZOPS_MODULE_VERSION: ${{ secrets.AZOPS_MODULE_VERSION }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
APPLICATIONINSIGHTS_CONNECTIONSTRING: ${{ secrets.APPLICATIONINSIGHTS_CONNECTIONSTRING }}
#
# modulesFolder
# To enable caching of PowerShell modules between
# runs, the modules are stored in a modules folder
# that can be cached.
#
modulesFolder: "~/.local/share/powershell/Modules"
#
# Folder Name
# By default we generate the hierachy within the
# 'azops' folder within the root of the repository.
# If this property is modified, the config value within
# the settings.json file - Core.State will also need
# to be changed.
#
# Default: root
#
folder: "root"
#
# Branch Name
# As part of the Pull workflow we check a temporary branch
# this branch was previously know as system, this value can
# be changed if this name is already reserved for other systems
# within the repository.
#
# Default: automated
#
branch: "automated"
#
# Commit Message
# During the Pull workflow, the changes are commited to the
# temporary branch, the message which is applied within the
# Git history can be changed as needed.
#
# Default: Automated commit
#
commit_message: "Automated commit"
#
# Pull Request
# The generated Pull Request for the Pull workflow can be
# modified to help indicate when changes we're merged in the
# Git history.
#
# Default: Automated state
#
pull_request: "Automated State"
jobs:
pull:
#
# Pull
#
name: "Pull"
runs-on: ubuntu-20.04
#
# Environment if using Federated Credentials
# https://github.com/azure/azops/wiki/oidc
#
# environment: prod
#
# Only run Pull after successful Push or on manually triggered/scheduled events
#
if: ${{ github.event.workflow_run.conclusion == 'success' ||
contains(fromJson('["schedule", "workflow_dispatch", "repository_dispatch"]'), github.event_name) }}
steps:
#
# Checkout
# Checks-out the repository
#
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
#
# Shared steps
# Include shared steps from the 'action.yml' file
# to not have to repeat them in every pipeline.
#
- name: 'Shared steps'
uses: ./.github/actions/sharedSteps
#
# Configure
# Set global options
#
- name: "Configure"
shell: bash
run: |
git config user.name github-actions
git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
#
# Checkout
# Switch branches
#
- name: "Checkout"
shell: bash
run: |
git checkout -b ${{ env.branch }}
#
# Initialize
# Generate new state data
#
- name: "Initialize"
shell: pwsh
run: |
Import-PSFConfig -Path settings.json -Schema MetaJson -EnableException
if ($env:ACTION -eq "Enterprise-Scale Deployment") {
Set-PSFConfig -FullName AzOps.Core.SkipResource -Value $false
}
Invoke-AzOpsPull -Rebuild
Get-Job | Remove-Job -Force
env:
ACTION: ${{ github.event.action }}
#
# Status
# Check for data changes
#
- name: "Status"
id: status
shell: bash
run: |
STATUS=$(git status --short)
echo $STATUS
if [ -z "$STATUS" ]
then
echo "state=stop" >> $GITHUB_OUTPUT
else
echo "state=continue" >> $GITHUB_OUTPUT
fi
#
# Add
# Add file content to index
#
- name: "Add"
if: steps.status.outputs.state == 'continue'
run: |
git add "./${{ env.folder }}"
shell: bash
#
# Commit
# Record changes to the repository
#
- name: "Commit"
if: steps.status.outputs.state == 'continue'
shell: bash
run: |
git commit -m "${{ env.commit_message }}"
#
# Push
# Update remote refs along with associated objects
#
- name: "Push"
if: steps.status.outputs.state == 'continue'
shell: bash
run: |
git push origin ${{ env.branch }} -f
#
# Merge
# Automatically merge the head branch into base
#
- name: "Merge"
if: steps.status.outputs.state == 'continue'
shell: bash
run: |
gh pr create --title "${{ env.pull_request }}" --body "-" --base 'main' --head ${{ env.branch }}
gh pr merge "${{ env.branch }}" --squash --delete-branch