-
Notifications
You must be signed in to change notification settings - Fork 0
292 lines (272 loc) · 12.6 KB
/
Copy pathupdate-nuspec.yml
File metadata and controls
292 lines (272 loc) · 12.6 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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
name: Update nuspec files
on:
workflow_run:
workflows: ["service::event_dispatcher::pull_request::closed::main"]
types:
- completed
workflow_dispatch:
inputs:
force:
description: 'Force update all nuspec files'
required: false
type: boolean
default: false
concurrency:
group: update-nuspec
cancel-in-progress: true
jobs:
validate:
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch'
outputs:
result: ${{ steps.validate.outputs.result }}
steps:
- uses: actions/checkout@v4
- name: Initialize
id: initialize
env:
GH_TOKEN: ${{ secrets.PAT }}
WORKFLOW_EVENT: ${{ github.event.workflow_run.event }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "[workflow_dispatch] Skipping PR validation"
echo "pull_request_merged=true" >> $GITHUB_OUTPUT
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
exit 0
fi
if [ "$WORKFLOW_EVENT" != "pull_request" ]; then
echo "[skip] Not a pull_request event"
echo "pull_request_merged=false" >> $GITHUB_OUTPUT
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
exit 0
fi
PR_JSON=$(gh pr list --repo ${{ github.repository }} --state all --json number,mergeCommit,headRefName,baseRefName,state --search "$HEAD_SHA" --limit 1 --jq '.[0]')
if [ "$(echo "$PR_JSON" | jq '. | length')" -eq 0 ]; then
echo "[skip] No PR found for commit $HEAD_SHA"
echo "pull_request_merged=false" >> $GITHUB_OUTPUT
echo "pull_request_head_ref=" >> $GITHUB_OUTPUT
exit 0
fi
PR_STATE=$(echo "$PR_JSON" | jq -r '.state')
PR_BASE_REF_NAME=$(echo "$PR_JSON" | jq -r '.baseRefName')
PR_HEAD_REF=$(echo "$PR_JSON" | jq -r '.headRefName')
PR_MERGED="$([[ "$PR_STATE" == "MERGED" ]] && echo true || echo false)"
echo "pull_request_merged=$PR_MERGED" >> $GITHUB_OUTPUT
echo "pull_request_head_ref=$PR_HEAD_REF" >> $GITHUB_OUTPUT
echo "pull_request_base_ref_name=$PR_BASE_REF_NAME" >> $GITHUB_OUTPUT
- name: Validate
id: validate
env:
PULL_REQUEST_MERGED: ${{ steps.initialize.outputs.pull_request_merged }}
GITHUB_HEAD_REF: ${{ steps.initialize.outputs.pull_request_head_ref }}
GITHUB_BASE_REF: ${{ steps.initialize.outputs.pull_request_base_ref_name }}
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "result=true" >> $GITHUB_OUTPUT
exit 0
fi
merged="$([[ "$PULL_REQUEST_MERGED" == "true" ]] && echo true || echo false)"
originated_from_feature="$([[ ! "$GITHUB_HEAD_REF" =~ ^bot\/[^\/]+\/update-nuspec$ ]] && echo true || echo false)"
result="$([[ "$merged" == true && "$originated_from_feature" == true ]] && echo true || echo false)"
echo "result=$result" >> $GITHUB_OUTPUT
has-changes:
needs: [validate]
if: needs.validate.outputs.result == 'true'
runs-on: ubuntu-latest
outputs:
module: ${{ steps.finalize.outputs.module }}
aspnetcore: ${{ steps.finalize.outputs.aspnetcore }}
cli: ${{ steps.finalize.outputs.cli }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/has-changes
if: github.event.inputs.force != 'true'
id: has-changes-module
with:
project: EncryptedConfigValue.Module
- uses: ./.github/actions/has-changes
if: github.event.inputs.force != 'true'
id: has-changes-aspnetcore
with:
project: EncryptedConfigValue.AspNetCore
- uses: ./.github/actions/has-changes
if: github.event.inputs.force != 'true'
id: has-changes-cli
with:
project: EncryptedConfigValue.Cli
- name: Finalize
id: finalize
run: |
if [[ "${{ github.event.inputs.force }}" == "true" ]]; then
echo "module=true" >> $GITHUB_OUTPUT
echo "aspnetcore=true" >> $GITHUB_OUTPUT
echo "cli=true" >> $GITHUB_OUTPUT
else
echo "module=${{ steps.has-changes-module.outputs.result }}" >> $GITHUB_OUTPUT
echo "aspnetcore=${{ steps.has-changes-aspnetcore.outputs.result }}" >> $GITHUB_OUTPUT
echo "cli=${{ steps.has-changes-cli.outputs.result }}" >> $GITHUB_OUTPUT
fi
module:
needs: [has-changes]
if: github.event.inputs.force == 'true' || needs.has-changes.outputs.module == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.Module" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=bot/${{ steps.set-project-name.outputs.value }}/update-nuspec" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- name: IsVersionBumpEnabled
id: is-version-bump-enabled
shell: pwsh
run: |
$lastVersionTag = (git tag -l "EncryptedConfigValue.Module/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.Module\EncryptedConfigValue.Module.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
"value=$("$($newestVersion -eq $nuspecVersion)".ToLowerInvariant())" >> $env:GITHUB_OUTPUT
- uses: ./.github/actions/update-nuspec-file
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
project: ${{ steps.set-project-name.outputs.value }}
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
external-dependencies-sources: |
EncryptedConfigValue
additional-files: |
./Readme.md
- uses: ./.github/actions/commit-changes
with:
message: Update ${{ steps.set-project-name.outputs.value }}.nuspec
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- uses: ./.github/actions/put-pull-request
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
title: Update ${{ steps.set-project-name.outputs.value }}.nuspec
body: This PR updates the ${{ steps.set-project-name.outputs.value }}.nuspec file to ensure correct project dependencies, metadata, or versioning. Please review the changes for accuracy and compliance.
from: ${{ steps.set-branch-name.outputs.value }}
into: main
aspnetcore:
needs: [has-changes]
if: github.event.inputs.force == 'true' || needs.has-changes.outputs.aspnetcore == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.AspNetCore" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=bot/${{ steps.set-project-name.outputs.value }}/update-nuspec" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- name: IsVersionBumpEnabled
id: is-version-bump-enabled
shell: pwsh
run: |
$lastVersionTag = (git tag -l "EncryptedConfigValue.AspNetCore/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.AspNetCore\EncryptedConfigValue.AspNetCore.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
"value=$("$($newestVersion -eq $nuspecVersion)".ToLowerInvariant())" >> $env:GITHUB_OUTPUT
- uses: ./.github/actions/update-nuspec-file
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
project: ${{ steps.set-project-name.outputs.value }}
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
additional-files: |
./Readme.md
- uses: ./.github/actions/commit-changes
with:
message: Update ${{ steps.set-project-name.outputs.value }}.nuspec
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- uses: ./.github/actions/put-pull-request
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
title: Update ${{ steps.set-project-name.outputs.value }}.nuspec
body: This PR updates the ${{ steps.set-project-name.outputs.value }}.nuspec file to ensure correct project dependencies, metadata, or versioning. Please review the changes for accuracy and compliance.
from: ${{ steps.set-branch-name.outputs.value }}
into: main
cli:
needs: [has-changes]
if: github.event.inputs.force == 'true' || needs.has-changes.outputs.cli == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
project: ${{ steps.set-project-name.outputs.value }}
branch: ${{ steps.set-branch-name.outputs.value }}
steps:
- uses: actions/checkout@v4
- name: Set project name
id: set-project-name
run: |
echo "value=EncryptedConfigValue.Cli" >> $GITHUB_OUTPUT
- name: Set branch name
id: set-branch-name
run: |
echo "value=bot/${{ steps.set-project-name.outputs.value }}/update-nuspec" >> $GITHUB_OUTPUT
- uses: ./.github/actions/setup-git
with:
branch: ${{ steps.set-branch-name.outputs.value }}
hard-reset: true
- name: IsVersionBumpEnabled
id: is-version-bump-enabled
shell: pwsh
run: |
$lastVersionTag = (git tag -l "EncryptedConfigValue.Cli/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.Cli\EncryptedConfigValue.Cli.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
"value=$("$($newestVersion -eq $nuspecVersion)".ToLowerInvariant())" >> $env:GITHUB_OUTPUT
- uses: ./.github/actions/update-nuspec-file
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
project: ${{ steps.set-project-name.outputs.value }}
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
external-dependencies-sources: |
EncryptedConfigValue
additional-files: |
./Readme.md
- uses: ./.github/actions/commit-changes
with:
message: Update ${{ steps.set-project-name.outputs.value }}.nuspec
- uses: ./.github/actions/push-changes
with:
branch: ${{ steps.set-branch-name.outputs.value }}
force: true
- uses: ./.github/actions/put-pull-request
with:
GITHUB_TOKEN: ${{ secrets.PAT }}
title: Update ${{ steps.set-project-name.outputs.value }}.nuspec
body: This PR updates the ${{ steps.set-project-name.outputs.value }}.nuspec file to ensure correct project dependencies, metadata, or versioning. Please review the changes for accuracy and compliance.
from: ${{ steps.set-branch-name.outputs.value }}
into: main