-
-
Notifications
You must be signed in to change notification settings - Fork 26
339 lines (309 loc) · 12.4 KB
/
main.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
name: Build
env:
Config: Release
Debug: ${{ false }}
SkipReleaseNotes: ${{ true }}
on:
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
Build:
runs-on: windows-latest
env:
TFSCMDLETS_ACCESS_TOKEN: ${{ secrets.TFSCMDLETS_TOKEN }}
TFSCMDLETS_COLLECTION_URL: 'https://dev.azure.com/tfscmdlets'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: csharp
- name: Build module
id: build_module
shell: pwsh
run: |
./Build.ps1 -Targets Package -Config ${{ env.Config }} -Verbose:$${{ env.Debug }} -SkipReleaseNotes:$${{ env.SkipReleaseNotes }}
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/windows@v2
if: always()
with:
files: |
out\TestResults-Pester*.xml
- name: Publish Nuget
uses: actions/upload-artifact@v4
with:
name: nuget
path: "out/Nuget/*.nupkg"
- name: Publish Chocolatey
uses: actions/upload-artifact@v4
with:
name: chocolatey
path: "out/Chocolatey/*.nupkg"
- name: Publish Portable
uses: actions/upload-artifact@v4
with:
name: portable
path: "out/Portable/*.zip"
- name: Publish MSI
uses: actions/upload-artifact@v4
with:
name: msi
path: "out/msi/*"
- name: Publish WinGet
uses: actions/upload-artifact@v4
with:
name: winget
path: "out/winget/**"
- name: Publish Docs
uses: actions/upload-artifact@v4
with:
name: docs
path: "out/docs/*.zip"
- name: Publish Release Notes
uses: actions/upload-artifact@v4
with:
name: releasenotes
path: "docs/ReleaseNotes/**"
outputs:
BUILD_NAME: ${{ steps.build_module.outputs.BUILD_NAME }}
Staging:
runs-on: ubuntu-latest
environment: staging
needs: [ Build ]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_NAME: ${{ needs.Build.outputs.BUILD_NAME }}
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
- name: Extract release notes
id: extract_release_notes
shell: pwsh
run: |
$fileName = (Get-ChildItem [0-9]*.md -Recurse | Sort-Object Name | Select -ExpandProperty FullName -Last 1)
Write-Output $fileName
$releaseNotes = (Get-Content $fileName -Encoding UTF8 | Select-Object -Skip 4)
Write-Output $releaseNotes
Write-Output 'RELEASE_NOTES<<EOF' >> $env:GITHUB_OUTPUT
Write-Output $releaseNotes >> $env:GITHUB_OUTPUT
Write-Output 'EOF' >> $env:GITHUB_OUTPUT
- name: Create Draft Release
id: create_release
shell: pwsh
run: |
# Install module
Install-Module PowerShellForGitHub -Scope CurrentUser -Force
# Connect to GitHub
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository tfscmdlets
$ghCreds = New-Object System.Management.Automation.PSCredential @( "pat",
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force)
)
Set-GitHubAuthentication -Credential $ghCreds -SessionOnly
# Remove stale draft releases
# TODO: Limit scope to this pull request (filter by PR name)
Get-GitHubRelease | Where-Object Draft -eq $true | Remove-GitHubRelease -Force
# Create new draft releases
$release = New-GitHubRelease -Tag 'v${{ env.BUILD_NAME }}' -Name 'Release ${{ env.BUILD_NAME }}' `
-Draft -PreRelease:($env:BUILD_NAME -like '*-*') -commitish '${{ github.sha }}' -Body: @'
${{ steps.extract_release_notes.outputs.RELEASE_NOTES }}
'@
# Upload assets
@('msi/TfsCmdlets*.msi', 'nuget/TfsCmdlets*.nupkg', 'portable/TfsCmdlets*.zip', 'docs/TfsCmdlets*.zip') `
| ForEach-Object { New-GitHubReleaseAsset -Release $release.Id -Path $_ }
outputs:
BUILD_NAME: ${{ needs.Build.outputs.BUILD_NAME }}
RELEASE_NOTES: ${{ steps.extract_release_notes.outputs.RELEASE_NOTES }}
Release:
runs-on: ubuntu-latest
environment: production
needs: [ Staging ]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }}
steps:
- name: Promote release
id: promote_release
shell: pwsh
run: |
# Install module
Install-Module PowerShellForGitHub -Scope CurrentUser -Force
# Connect to GitHub
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository tfscmdlets
Set-GitHubAuthentication -SessionOnly -Credential (New-Object System.Management.Automation.PSCredential @("pat",
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force)))
# Promote release
$rel = Get-GitHubRelease `
| Where-Object { ($_.Draft -eq $true) -and ($_.Name -eq "Release $($env:BUILD_NAME)") }
Set-GitHubRelease -Release $rel.id -Draft:$false
Write-Output "RELEASE_URL=$($rel.html_url)" >> $env:GITHUB_OUTPUT
Write-Output "RELEASE_TAG=$($env:BUILD_NAME.Replace('+', '%2B'))" >> $env:GITHUB_OUTPUT
outputs:
BUILD_NAME: ${{ needs.Staging.outputs.BUILD_NAME }}
RELEASE_NOTES: ${{ needs.Staging.outputs.RELEASE_NOTES }}
RELEASE_URL: ${{ steps.promote_release.outputs.RELEASE_URL }}
RELEASE_TAG: ${{ steps.promote_release.outputs.RELEASE_TAG }}
Site:
runs-on: ubuntu-latest
needs: [ Release ]
env:
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }}
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
path: site
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: docs
- name: Publish site
run: |
cd site && mkdir docs && pushd docs
git checkout --track origin/gh-pages
unzip -o ../../TfsCmdlets-Docs-*.zip
popd
echo build_info: TfsCmdlets v${BUILD_NAME}, released $(date +%F) >> _config.yml
echo >> _config.yml
git config --local user.name "Igor Abade"
git config --local user.email igoravl@gmail.com
git add *
git commit -m "Publish version $BUILD_NAME"
git push
PSGallery:
runs-on: ubuntu-latest
needs: [ Release ]
environment: psgallery
env:
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
PSGALLERY_KEY: ${{ secrets.API_KEY }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: portable
- name: Publish artifact
shell: pwsh
run: |
Install-Module PackageManagement -Scope CurrentUser -Force
Install-Module PowerShellGet -Scope CurrentUser -Force
Expand-Archive TfsCmdlets-Portable*.zip -DestinationPath Module/TfsCmdlets
$releaseNotes = $env:RELEASE_NOTES
Publish-Module -Name Module/TfsCmdlets -NuGetApiKey $env:PSGALLERY_KEY -AllowPreRelease -ReleaseNotes $releaseNotes
Nuget:
runs-on: ubuntu-latest
needs: [ Release ]
environment: nuget
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: nuget
- name: Install Nuget 5.x
uses: nuget/setup-nuget@v2
with:
nuget-api-key: ${{ secrets.API_KEY }}
nuget-version: '5.x'
- name: Push package
run: |
nuget push $(ls TfsCmdlets*.nupkg) -Source https://api.nuget.org/v3/index.json
Chocolatey:
runs-on: windows-latest
needs: [ Release ]
environment: chocolatey
env:
CHOCO_KEY: ${{ secrets.API_KEY }}
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: chocolatey
- name: Install Chocolatey
shell: pwsh
run: |
Set-ExecutionPolicy Bypass -Scope Process -Force
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
- name: Push package
run: |
choco push $(ls TfsCmdlets*.nupkg) --api-key $env:CHOCO_KEY --source='https://push.chocolatey.org/'
WinGet:
runs-on: ubuntu-latest
needs: [ Release ]
environment: winget
env:
GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }}
steps:
- name: Clone winget-pkgs repository
shell: bash
run: |
git clone --single-branch --branch "master" "https://igoravl:$GITHUB_TOKEN@github.com/igoravl/winget-pkgs.git"
cd winget-pkgs
git remote add upstream https://github.com/microsoft/winget-pkgs.git
git fetch upstream
git checkout -b "TfsCmdlets_$BUILD_NAME"
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: winget
path: winget-pkgs
- name: Push to wingets-pkgs repository
shell: bash
run: |
cd winget-pkgs
git config --local user.email "igoravl@gmail.com"
git config --local user.name "Igor Abade"
git add manifests/i/Igoravl/TfsCmdlets/*
git commit -m "Release $BUILD_NAME"
git push -u origin "TfsCmdlets_$BUILD_NAME"
- name: Create pull request to microsoft/winget-pkgs
shell: pwsh
run: |
# Install module
Install-Module PowerShellForGitHub -Scope CurrentUser -Force
# Connect to GitHub
Set-GitHubConfiguration -SuppressTelemetryReminder -DefaultOwnerName igoravl -DefaultRepository winget-pkgs
Set-GitHubAuthentication -SessionOnly -Credential (New-Object System.Management.Automation.PSCredential @("pat",
(ConvertTo-SecureString -String $env:GITHUB_TOKEN -AsPlainText -Force)))
# Create pull request
New-GitHubPullRequest -OwnerName Microsoft -RepositoryName winget-pkgs `
-Title "TfsCmdlets_$env:BUILD_NAME" -Head "igoravl:TfsCmdlets_$env:BUILD_NAME" -base master -Body @'
- [x] Have you signed the [Contributor License Agreement](https://cla.opensource.microsoft.com/microsoft/winget-pkgs)?
- [x] Have you checked that there aren't other open [pull requests](https://github.com/microsoft/winget-pkgs/pulls) for the same manifest update/change?
- [x] Have you validated your manifest locally with `winget validate --manifest <path>`?
- [x] Have you tested your manifest locally with `winget install --manifest <path>`?
- [x] Does your manifest conform to the [1.0 schema](https://github.com/microsoft/winget-cli/blob/master/doc/ManifestSpecv1.0.md)?
Note: `<path>` is the name of the directory containing the manifest you're submitting.
-----
'@
Announcements:
runs-on: ubuntu-latest
needs: [ Release, Nuget, PSGallery, Chocolatey, Site, WinGet ]
environment: announcements
steps:
- name: No-op
shell: bash
run: echo "Announcements are temporarily disabled."
# - name: Tweet
# id: tweet
# uses: snow-actions/tweet@v1.3.0
# env:
# BUILD_NAME: ${{ needs.Release.outputs.BUILD_NAME }}
# CONSUMER_API_KEY: ${{ secrets.TWITTER_CONSUMER_API_KEY }}
# CONSUMER_API_SECRET_KEY: ${{ secrets.TWITTER_CONSUMER_API_SECRET_KEY }}
# ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
# ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
# RELEASE_TAG: ${{ needs.Release.outputs.RELEASE_TAG }}
# with:
# status: |
# TfsCmdlets version ${{ env.BUILD_NAME }} has just been released. Check it out! https://github.com/igoravl/TfsCmdlets/releases/tag/v${{ env.RELEASE_TAG }}