-
Notifications
You must be signed in to change notification settings - Fork 0
114 lines (96 loc) · 3.53 KB
/
release.yml
File metadata and controls
114 lines (96 loc) · 3.53 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
name: NuGet
on:
release:
types: [published]
jobs:
Build:
env:
BUILD_CONFIG: 'Release'
SOLUTION: 'ServiceInjection.sln'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
- name: Restore dependencies
run: dotnet restore $SOLUTION
- name: Build
run: dotnet build $SOLUTION --configuration Release
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: nuget-package
path: ./ServiceInjection.SourceGenerators/bin/Release/*.nupkg
- name: Run tests
run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal
Publish-Package:
needs: Build
runs-on: ubuntu-latest
steps:
- name: Download NuGet Package
uses: actions/download-artifact@v3
with:
name: nuget-package
path: ./nupkgs
- name: Setup NuGet
uses: NuGet/setup-nuget@v1
- name: Publish NuGet Package
run: nuget push **\*.nupkg -Source 'https://api.nuget.org/v3/index.json' -ApiKey ${{secrets.NUGET_API_KEY}}
Update-Release:
needs: Build
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_URL: "https://api.github.com/repos/${{ github.repository }}/releases"
TAG_NAME: ${{ github.ref }}
steps:
- name: Prepare Environment
run: echo "TAG_NAME=$(echo ${{ env.TAG_NAME }} | sed 's/refs\/tags\///')" >> $GITHUB_ENV
- name: Download NuGet Package Artifact
uses: actions/download-artifact@v3
with:
name: nuget-package
path: ./nupkgs
- name: Get NuGet Package Name
run: echo "NUPKG_NAME=$(basename $(ls ./nupkgs/*.nupkg))" >> $GITHUB_ENV
- name: Get Release Information
run: |
$headers = @{
"Authorization" = "token $env:GITHUB_TOKEN"
"Accept" = "application/vnd.github.v3+json"
}
$tagUrl = "$env:BASE_URL/tags/$env:TAG_NAME"
$releaseInfo = Invoke-RestMethod -Uri $tagUrl -Method Get -Headers $headers
$uploadUrl = $releaseInfo.upload_url -replace "\{\?name,label\}", ""
echo "UPLOAD_URL=$uploadUrl" >> $env:GITHUB_ENV
echo "RELEASE_ID=$($releaseInfo.id)" >> $env:GITHUB_ENV
shell: pwsh
- name: Update Release
run: |
$headers = @{
"Authorization" = "token $env:GITHUB_TOKEN"
"Accept" = "application/vnd.github.v3+json"
}
$releaseData = @{
"tag_name" = $env:TAG_NAME
"name" = "$env:TAG_NAME"
"draft" = $false
"prerelease" = $false
}
$updateUrl = "$env:BASE_URL/$env:RELEASE_ID"
Invoke-RestMethod -Uri $updateUrl -Method Patch -Headers $headers -Body ($releaseData | ConvertTo-Json)
shell: pwsh
- name: Upload NuGet Package as Release Asset
run: |
$filePath = "./nupkgs/${{ env.NUPKG_NAME }}"
$fileName = "${{ env.NUPKG_NAME }}"
$headers = @{
"Authorization" = "token $env:GITHUB_TOKEN"
"Accept" = "application/vnd.github.v3+json"
"Content-Type" = "application/octet-stream"
}
$response = Invoke-RestMethod -Uri "${{ env.UPLOAD_URL }}?name=$fileName" -Method Post -Headers $headers -InFile $filePath
echo "Upload response: $response"
shell: pwsh