-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathplatform.updateModuleRegistryTables.yml
More file actions
149 lines (129 loc) · 6.11 KB
/
Copy pathplatform.updateModuleRegistryTables.yml
File metadata and controls
149 lines (129 loc) · 6.11 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
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
name: ".Platform - Update module registry tables"
on:
workflow_dispatch:
schedule:
- cron: "0 1 * * *" # Daily Update at 1 am
env:
pipelinePrincipalGitUserName: "AVMPipelinePrincipal"
pipelinePrincipalGitUserEmail: "AVM@noreply.github.com"
branch_name: "update-module-features-table"
pr_title: "Update module features table (automated)"
pr_body: "This is an automated ``pull_request`` containing updates to the module status badges table that is stored at ``docs/content/indexes/bicep/_index.md``, as well as the module features CSV stored at ``docs/static/module-features/bicepFeatures.csv``.\nPlease review the ``files changed`` tab to review changes."
permissions:
id-token: write
contents: write
jobs:
update_status_tables:
name: Update status tables
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
environment: platform
steps:
- name: "Checkout"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout tools repo
uses: actions/checkout@v4
with:
repository: Azure/bicep-registry-modules
path: bicep-registry-modules
fetch-depth: 0
- uses: actions/create-github-app-token@v2
id: generate-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Configure local git
run: |
git config --global user.name '${{ env.pipelinePrincipalGitUserEmail }}'
git config --global user.email '${{ env.pipelinePrincipalGitUserName }}'
- name: Format branch name
shell: pwsh
run: |
$rawBranch = '${{ env.branch_name }}'
$formattedBranch = "{0}_{1}" -f $rawBranch, (Get-Date).ToString('yyyy-MM-dd-HH-mm-ss')
Write-Verbose "Adjusting branch name [$rawBranch] to [$formattedBranch]" -Verbose
('{0}={1}' -f 'branch_name', $formattedBranch) | Out-File -FilePath $env:GITHUB_ENV -Encoding 'utf8' # Overwrite env variable
- name: Create and checkout branch
run: |
BRANCH_URL="repos/${{ github.repository }}/branches"
JQ_FILTER=".[] | select(.name == \"${{ env.branch_name }}\").name"
CHECK_BRANCH_ORIGIN=$(gh api $BRANCH_URL | jq -r "$JQ_FILTER")
if [ -z "$CHECK_BRANCH_ORIGIN" ]
then
echo "Checkout local branch (create new, no origin)..."
git checkout -b ${{ env.branch_name }}
else
echo "Checkout local branch (create new, track from origin)..."
git checkout -b ${{ env.branch_name }} --track origin/${{ env.branch_name }}
git merge origin/main
fi
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: "Update module status table"
shell: pwsh
run: |
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'tools' 'platform' 'Set-BicepModuleStatusBadgesTable.ps1')
$functionInput = @{
MarkdownFilePath = Join-Path $env:GITHUB_WORKSPACE 'docs' 'static' 'includes' 'module-features' 'bicepBadges.md'
ModulesRepoRootPath = Join-Path $env:GITHUB_WORKSPACE 'bicep-registry-modules'
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Set-BicepModuleStatusBadgesTable @functionInput -Verbose
- name: "Update module features csv"
shell: pwsh
run: |
# Load used functions
. (Join-Path $env:GITHUB_WORKSPACE 'utilities' 'tools' 'platform' 'Set-BicepModulesFeatureCSV.ps1')
$functionInput = @{
CSVFilePath = Join-Path $env:GITHUB_WORKSPACE 'docs' 'static' 'includes' 'module-features' 'bicepFeatures.csv'
ModulesRepoRootPath = Join-Path $env:GITHUB_WORKSPACE 'bicep-registry-modules'
}
Write-Verbose "Invoke task with" -Verbose
Write-Verbose ($functionInput | ConvertTo-Json | Out-String) -Verbose
Set-BicepModulesFeatureCSV @functionInput -Verbose
- name: Check for changes
id: git_status
shell: pwsh
run: |
$stats = git diff --stat
$diff = git diff --name-only
if($diff.Count -gt 0) {
Write-Verbose ("Diff found:`n{0}" -f ($stats | Out-String)) -Verbose
Write-Output ('{0}={1}' -f 'changes', $diff) >> $env:GITHUB_OUTPUT
}
- name: Add files, commit and push
if: steps.git_status.outputs.changes != ''
shell: pwsh
run: |
Write-Verbose "Pushing changes to origin..." -Verbose
git add (Join-Path $env:GITHUB_WORKSPACE 'docs' 'static' 'includes' 'module-features' 'bicepBadges.md')
git add (Join-Path $env:GITHUB_WORKSPACE 'docs' 'static' 'includes' 'module-features' 'bicepFeatures.csv')
git commit -m '${{ env.pr_title }}'
git push origin ${{ env.branch_name }}
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}
- name: Create pull request
if: steps.git_status.outputs.changes != ''
run: |
HEAD_LABEL="${{ github.repository_owner }}:${{ env.branch_name }}"
BASE_LABEL="${{ github.repository_owner }}:$(echo '${{ github.ref }}' | sed 's:refs/heads/::')"
PULL_REQUEST_URL="repos/${{ github.repository }}/pulls"
JQ_FILTER=".[] | select(.head.label == \"$HEAD_LABEL\") | select(.base.label == \"$BASE_LABEL\") | .url"
CHECK_PULL_REQUEST_URL=$(gh api $PULL_REQUEST_URL | jq -r "$JQ_FILTER")
if [ -z "$CHECK_PULL_REQUEST_URL" ]
then
CHECK_PULL_REQUEST_URL=$(gh pr create \
--title "${{ env.pr_title }}" \
--body "${{ env.pr_body }}" \
--base "${{ github.ref }}" \
--head "${{ env.branch_name }}")
echo "Created new PR: $CHECK_PULL_REQUEST_URL"
else
echo "Existing PR found: $CHECK_PULL_REQUEST_URL"
fi
env:
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}