-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (140 loc) · 6.32 KB
/
dotnet.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
name: .NET Workflow
on:
push:
branches:
- main
- develop
pull_request:
schedule:
- cron: "0 23 * * *"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
permissions:
packages: write
contents: write
env:
OUTPUT_PATH: 'output'
STAGING_PATH: 'staging'
DOTNET_VERSION: '9.0'
jobs:
dotnet:
name: .NET Workflow
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
persist-credentials: true
lfs: true
fetch-tags: true
- name: Fetch tags
shell: pwsh
run: |
git fetch --prune --unshallow --tags
$global:LASTEXITCODE = 0
- name: Configure Environment
shell: pwsh
run: |
$IS_MAIN = "${{ github.ref }}" -eq "refs/heads/main"
$IS_TAGGED = (git show-ref --tags -d | Out-String).Contains("${{ github.sha }}")
$SHOULD_RELEASE = ($IS_MAIN -AND -NOT $IS_TAGGED)
$USE_DOTNET_SCRIPT = (Get-ChildItem -Recurse -Filter *.csx).Count -gt 0
$PACKAGE_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.nupkg"
$SYMBOLS_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.snupkg"
$APPLICATION_PATTERN = Join-Path -Path "${{ github.workspace }}" -ChildPath "${{ env.STAGING_PATH }}" -AdditionalChildPath "*.zip"
$BUILD_ARGS = ""
$BUILD_ARGS += $USE_DOTNET_SCRIPT ? "-maxCpuCount:1" : ""
"IS_MAIN=$IS_MAIN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"IS_TAGGED=$IS_TAGGED" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"SHOULD_RELEASE=$SHOULD_RELEASE" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"USE_DOTNET_SCRIPT=$USE_DOTNET_SCRIPT" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"PACKAGE_PATTERN=$PACKAGE_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"SYMBOLS_PATTERN=$SYMBOLS_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"APPLICATION_PATTERN=$APPLICATION_PATTERN" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
"BUILD_ARGS=$BUILD_ARGS" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
Write-Host "IS_MAIN: $IS_MAIN"
Write-Host "IS_TAGGED: $IS_TAGGED"
Write-Host "SHOULD_RELEASE: $SHOULD_RELEASE"
Write-Host "USE_DOTNET_SCRIPT: $USE_DOTNET_SCRIPT"
Write-Host "PACKAGE_PATTERN: $PACKAGE_PATTERN"
Write-Host "SYMBOLS_PATTERN: $SYMBOLS_PATTERN"
Write-Host "APPLICATION_PATTERN: $APPLICATION_PATTERN"
Write-Host "BUILD_ARGS: $BUILD_ARGS"
$global:LASTEXITCODE = 0
- name: Make Version
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: scripts/make-version.ps1 "${{ github.sha }}"
- name: Make License
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: scripts/make-license.ps1 "${{ github.server_url }}" "${{ github.repository_owner }}" "${{ github.repository }}"
- name: Make Changelog
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: scripts/make-changelog.ps1 "${{ env.VERSION }}" "${{ github.sha }}"
- name: Commit Metadata
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: scripts/commit-metadata.ps1
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
${{ env.DOTNET_VERSION }}.x
- name: Install dotnet-script
if: ${{ env.USE_DOTNET_SCRIPT == 'True' }}
shell: pwsh
run: dotnet tool install -g dotnet-script
- name: Build
shell: pwsh
run: dotnet build --configuration Release --verbosity normal --no-incremental ${{ env.BUILD_ARGS }}
- name: Test
shell: pwsh
run: dotnet test --configuration Release --verbosity normal --no-build
- name: Detect Dependencies
if: ${{ env.SHOULD_RELEASE == 'True' }}
uses: advanced-security/component-detection-dependency-submission-action@v0.0.2
- name: Package Libraries
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: dotnet pack --configuration Release --output ${{ github.workspace }}/${{ env.STAGING_PATH }}
- name: Package Applications
if: ${{ env.SHOULD_RELEASE == 'True' }}
shell: pwsh
run: |
if (Test-Path ${{ github.workspace }}/${{ env.OUTPUT_PATH }}) {
Remove-Item -Recurse -Force ${{ github.workspace }}/${{ env.OUTPUT_PATH }}
}
Get-ChildItem -Recurse -Filter *.csproj | ForEach-Object {
$csproj = $_
$projName = [System.IO.Path]::GetFileNameWithoutExtension($csproj)
$outDir = "${{ github.workspace }}/${{ env.OUTPUT_PATH }}/$projName"
$stageDir = "${{ github.workspace }}/${{ env.STAGING_PATH }}"
$stageFile = "$stageDir/$projName-${{ env.VERSION }}.zip"
New-Item -Path $outDir -ItemType Directory -Force
New-Item -Path $stageDir -ItemType Directory -Force
dotnet publish $csproj --no-build --configuration Release --framework net${{ env.DOTNET_VERSION }} --output $outDir
Compress-Archive -Path $outDir/* -DestinationPath $stageFile
}
- name: Publish Libraries to GitHub
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }}
shell: pwsh
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.GITHUB_TOKEN }} --source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
- name: Publish Libraries to NuGet
if: ${{ env.SHOULD_RELEASE == 'True' && hashFiles(env.PACKAGE_PATTERN) != '' }}
shell: pwsh
run: dotnet nuget push ${{ env.PACKAGE_PATTERN }} --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Release
if: ${{ env.SHOULD_RELEASE == 'True' }}
uses: ncipollo/release-action@v1
with:
artifacts: "${{ env.PACKAGE_PATTERN }},${{ env.SYMBOLS_PATTERN }},${{ env.APPLICATION_PATTERN }}"
tag: v${{ env.VERSION }}
commit: ${{ env.RELEASE_HASH }}
allowUpdates: false
skipIfReleaseExists: true
omitBody: true
generateReleaseNotes: true
replacesArtifacts: false
makeLatest: true