-
Notifications
You must be signed in to change notification settings - Fork 0
118 lines (103 loc) · 4.16 KB
/
build-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
name: Build .NET
on:
push:
paths-ignore:
- 'README.md'
- 'LICENSE'
- '.github/workflows/*.yml'
- '.version/*.json'
- '.gitignore'
- '*.png'
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
runs-on: windows-latest
steps:
- name: Extract repo name
run: |
$repoName = "${{ github.repository }}".Split('/')[1]
echo "REPO_NAME=$repoName" | Out-File -FilePath $env:GITHUB_ENV -Append
shell: pwsh
- uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.BUILD_TOKEN }}
- name: Install .NET SDK
run: |
$url = "https://download.visualstudio.microsoft.com/download/pr/2b2d6133-c4f9-46dd-9ab6-86443a7f5783/340054e2ac7de2bff9eea73ec9d4995a/dotnet-sdk-${{ secrets.DOTNET_VERSION }}-win-x64.zip"
$output = "dotnet-sdk-${{ secrets.DOTNET_VERSION }}-win-x64.zip"
Invoke-WebRequest -Uri $url -OutFile $output
Expand-Archive $output -DestinationPath $Env:ProgramFiles\dotnet -Force
$env:PATH = "$Env:ProgramFiles\dotnet;" + $env:PATH
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, [EnvironmentVariableTarget]::Machine)
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ secrets.DOTNET_VERSION }}
- name: Add GitHub Packages source
run: |
nuget sources Add -Name "GitHub" -Source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" -Username ${{ github.repository_owner }} -Password ${{ secrets.BUILD_TOKEN }}
- name: Restore NuGet packages
run: dotnet restore $env:GITHUB_ENV.sln /p:ServerBuild=true
env:
NUGET_AUTH_TOKEN: ${{ secrets.BUILD_TOKEN }}
- name: Build with version
run: dotnet build $env:GITHUB_ENV.sln /p:BuildNumber=${{ github.run_number }} /p:ServerBuild=true
env:
UsePackageReferences: true
- name: Print Run Number
run: echo "Run number $env:GITHUB_RUN_NUMBER"
shell: pwsh
- name: Check Latest Release
id: latest_release
uses: octokit/[email protected]
with:
route: GET /repos/${{ github.repository }}/releases/latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
- name: Compare with version.json and Write to Script
run: |
$versionFile = ".version/version.json"
$versionJson = Get-Content $versionFile | ConvertFrom-Json
$latestReleaseTag = ""
try {
$latestReleaseResponse = Invoke-RestMethod -Uri "https://api.github.com/repos/${{ github.repository }}/releases/latest" -Headers @{Authorization = "Bearer ${{ secrets.BUILD_TOKEN }}"}
$latestReleaseTag = $latestReleaseResponse.tag_name
} catch {
echo "No latest release found"
}
if ($latestReleaseTag -ne $versionJson.version) {
"`$release_needed='true'" | Out-File -FilePath release-info.ps1 -Encoding UTF8
"`$version='$($versionJson.version)'" | Add-Content -Path release-info.ps1
} else {
"`$release_needed='false'" | Out-File -FilePath release-info.ps1 -Encoding UTF8
}
shell: pwsh
- name: Create Release
run: |
. .\release-info.ps1
if ($release_needed -eq 'true') {
$tag_name = $version
$release_name = "Release $tag_name"
$release_notes = "Release $tag_name"
$uri = "https://api.github.com/repos/${{ github.repository }}/releases"
$headers = @{
Authorization = "Bearer ${{ secrets.BUILD_TOKEN }}"
Accept = "application/vnd.github.v3+json"
}
$body = @{
tag_name = $tag_name
name = $release_name
body = $release_notes
}
echo "uri: $uri"
Invoke-RestMethod -Uri $uri -Headers $headers -Method Post -Body ($body | ConvertTo-Json)
}
shell: pwsh
env:
DOTNET_ROOT: C:\Users\runneradmin\AppData\Local\Microsoft\dotnet