-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (157 loc) · 5.14 KB
/
deploy.yml
File metadata and controls
178 lines (157 loc) · 5.14 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
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
name: Release Pipeline
on:
push:
tags:
- 'v*.*.*'
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_NOLOGO: true
DOTNET_VERSION: |
9.0.x
10.0.x
jobs:
validate-tag:
name: Validate Release Tag
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
is-prerelease: ${{ steps.extract.outputs.is-prerelease }}
steps:
- name: Extract version from tag
id: extract
run: |
TAG=${GITHUB_REF#refs/tags/}
VERSION=${TAG#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::Invalid version format: $VERSION"
exit 1
fi
if [[ $VERSION =~ - ]]; then
echo "is-prerelease=true" >> $GITHUB_OUTPUT
else
echo "is-prerelease=false" >> $GITHUB_OUTPUT
fi
build-and-pack:
name: Build & Pack
runs-on: ubuntu-latest
needs: validate-tag
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install workloads
run: dotnet workload restore
- name: Cache NuGet packages
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: ${{ runner.os }}-nuget-
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Pack NuGet packages
run: |
VERSION=${{ needs.validate-tag.outputs.version }}
PROJECTS=(
"src/TypeGuard.Core/TypeGuard.Core.csproj"
"src/TypeGuard.Console/TypeGuard.Console.csproj"
"src/TypeGuard.Avalonia/TypeGuard.Avalonia.csproj"
"src/TypeGuard.Wpf/TypeGuard.Wpf.csproj"
"src/TypeGuard.Winforms/TypeGuard.Winforms.csproj"
"src/TypeGuard.Maui/TypeGuard.Maui.csproj"
"src/TypeGuard.Blazor/TypeGuard.Blazor.csproj"
"src/TypeGuard.Uno/TypeGuard.Uno.csproj"
)
for project in "${PROJECTS[@]}"; do
dotnet pack "$project" \
--configuration Release \
--no-restore \
--output ./artifacts \
/p:PackageVersion=$VERSION
done
- name: Upload artifacts
uses: actions/upload-artifact@v7
with:
name: nuget-packages-${{ github.sha }}
path: ./artifacts/*.nupkg
retention-days: 7
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [validate-tag, build-and-pack]
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v8
with:
name: nuget-packages-${{ github.sha }}
path: ./artifacts
- name: Generate changelog
id: cliff
uses: orhun/git-cliff-action@v4
with:
config: .github/cliff.toml
args: --verbose --latest --strip header
env:
GITHUB_REPO: ${{ github.repository }}
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ github.ref_name }}
name: ${{ github.ref_name }}
body: ${{ steps.cliff.outputs.content }}
draft: false
prerelease: ${{ needs.validate-tag.outputs.is-prerelease == 'true' }}
files: ./artifacts/*.nupkg
publish:
name: Publish to NuGet
runs-on: ubuntu-latest
needs: [validate-tag, release]
permissions:
contents: write
packages: write
environment:
name: nuget-production
url: https://www.nuget.org/packages/TypeGuard.Core/${{ needs.validate-tag.outputs.version }}
steps:
- name: Download artifacts
uses: actions/download-artifact@v8
with:
name: nuget-packages-${{ github.sha }}
path: ./artifacts
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Publish to NuGet.org
run: |
for package in ./artifacts/*.nupkg; do
dotnet nuget push "$package" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done
- name: Publish to GitHub Packages
run: |
for package in ./artifacts/*.nupkg; do
dotnet nuget push "$package" \
--api-key ${{ secrets.GITHUB_TOKEN }} \
--source https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json \
--skip-duplicate || echo "::warning::Failed to publish $(basename "$package") to GitHub Packages"
done