Skip to content

Commit 5122de7

Browse files
Publish packages in their own jobs
- Validate the NuGet packages before publishing. - Publish packages to MyGet and NuGet as separate jobs after the build. - Push from `dev*` branches to handle long-lived ASP.NET Core vNext branches. - Recommend the GitHub Actions extension for Visual Studio Code.
1 parent 02931f8 commit 5122de7

File tree

2 files changed

+79
-14
lines changed

2 files changed

+79
-14
lines changed

.github/workflows/build.yml

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@ name: build
22

33
on:
44
push:
5-
branches: [ dev, rel/* ]
5+
branches: [ dev*, rel/* ]
66
tags: [ '*' ]
77
pull_request:
8-
branches: [ dev, rel/* ]
8+
branches: [ dev*, rel/* ]
99
workflow_dispatch:
1010

11+
env:
12+
DOTNET_MULTILEVEL_LOOKUP: 0
13+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
14+
DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION: 1
15+
NUGET_XMLDOC_MODE: skip
16+
TERM: xterm
17+
18+
permissions:
19+
contents: read
20+
1121
jobs:
1222
build:
1323
name: ${{ matrix.os }}
@@ -54,19 +64,11 @@ jobs:
5464
- name: Build, Test and Package
5565
if: ${{ runner.os == 'Windows' }}
5666
run: eng\common\CIBuild.cmd -configuration Release -prepareMachine
57-
env:
58-
DOTNET_MULTILEVEL_LOOKUP: 0
59-
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
60-
NUGET_XMLDOC_MODE: skip
6167

6268
- name: Build, Test and Package
6369
shell: pwsh
6470
if: ${{ runner.os != 'Windows' }}
6571
run: ./eng/common/cibuild.sh -configuration Release -prepareMachine
66-
env:
67-
DOTNET_MULTILEVEL_LOOKUP: 0
68-
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
69-
NUGET_XMLDOC_MODE: skip
7072

7173
- name: Publish logs
7274
uses: actions/upload-artifact@v3
@@ -88,10 +90,72 @@ jobs:
8890
name: testresults-${{ matrix.os_name }}
8991
path: ./artifacts/TestResults/Release
9092

93+
validate-packages:
94+
needs: build
95+
runs-on: ubuntu-latest
96+
steps:
97+
98+
- name: Download packages
99+
uses: actions/download-artifact@v3
100+
with:
101+
name: packages-windows
102+
103+
- name: Setup .NET SDK
104+
uses: actions/setup-dotnet@v3
105+
106+
- name: Validate NuGet packages
107+
shell: pwsh
108+
run: |
109+
dotnet tool install --global dotnet-validate --version 0.0.1-preview.304
110+
$packages = Get-ChildItem -Filter "*.nupkg" | ForEach-Object { $_.FullName }
111+
$invalidPackages = 0
112+
foreach ($package in $packages) {
113+
dotnet validate package local $package
114+
if ($LASTEXITCODE -ne 0) {
115+
$invalidPackages++
116+
}
117+
}
118+
if ($invalidPackages -gt 0) {
119+
Write-Output "::error::$invalidPackages NuGet package(s) failed validation."
120+
}
121+
122+
publish-myget:
123+
needs: validate-packages
124+
runs-on: ubuntu-latest
125+
if: |
126+
github.event.repository.fork == false &&
127+
(github.ref == format('refs/heads/{0}', github.event.repository.default_branch) ||
128+
startsWith(github.ref, 'refs/heads/dev') ||
129+
startsWith(github.ref, 'refs/heads/rel/') ||
130+
startsWith(github.ref, 'refs/tags/'))
131+
steps:
132+
133+
- name: Download packages
134+
uses: actions/download-artifact@v3
135+
with:
136+
name: packages-windows
137+
138+
- name: Setup .NET SDK
139+
uses: actions/setup-dotnet@v3
140+
91141
- name: Push NuGet packages to aspnet-contrib MyGet
92-
if: ${{ github.repository_owner == 'aspnet-contrib' && (github.ref == 'refs/heads/dev' || startsWith(github.ref, 'refs/heads/rel/') || startsWith(github.ref, 'refs/tags/')) && runner.os == 'Windows' }}
93-
run: nuget push "artifacts\packages\Release\Shipping\*.nupkg" -ApiKey ${{ secrets.MYGET_API_KEY }} -SkipDuplicate -Source https://www.myget.org/F/aspnet-contrib/api/v3/index.json
142+
run: nuget push "*.nupkg" -ApiKey ${{ secrets.MYGET_API_KEY }} -SkipDuplicate -Source https://www.myget.org/F/aspnet-contrib/api/v3/index.json
143+
144+
publish-nuget:
145+
needs: validate-packages
146+
runs-on: ubuntu-latest
147+
if: |
148+
github.event.repository.fork == false &&
149+
startsWith(github.ref, 'refs/tags/')
150+
steps:
151+
152+
- name: Download packages
153+
uses: actions/download-artifact@v3
154+
with:
155+
name: packages-windows
156+
157+
- name: Setup .NET SDK
158+
uses: actions/setup-dotnet@v3
94159

95160
- name: Push NuGet packages to NuGet.org
96-
if: ${{ github.repository_owner == 'aspnet-contrib' && startsWith(github.ref, 'refs/tags/') && runner.os == 'Windows' }}
97-
run: nuget push "artifacts\packages\Release\Shipping\*.nupkg" -ApiKey ${{ secrets.NUGET_API_KEY }} -SkipDuplicate -Source https://api.nuget.org/v3/index.json
161+
run: nuget push "*.nupkg" -ApiKey ${{ secrets.NUGET_API_KEY }} -SkipDuplicate -Source https://api.nuget.org/v3/index.json

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"recommendations": [
33
"editorconfig.editorconfig",
4+
"github.vscode-github-actions",
45
"ms-dotnettools.csharp"
56
]
67
}

0 commit comments

Comments
 (0)