-
Notifications
You must be signed in to change notification settings - Fork 0
232 lines (193 loc) · 7.15 KB
/
Copy pathrelease.yml
File metadata and controls
232 lines (193 loc) · 7.15 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., 1.0.0)'
required: true
type: string
env:
DOTNET_VERSION: '10.0.x'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
permissions:
contents: write
packages: write
jobs:
build-release:
name: Build Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Extract version from tag
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/v}
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
echo "Release version: ${VERSION}"
- name: Restore dependencies
run: dotnet restore PokManager.sln
- name: Build solution
run: dotnet build PokManager.sln --configuration Release --no-restore /p:Version=${{ steps.get_version.outputs.VERSION }}
- name: Run tests
run: dotnet test PokManager.sln --configuration Release --no-build --verbosity normal
- name: Publish API Service
run: dotnet publish src/Presentation/PokManager.ApiService/PokManager.ApiService.csproj --configuration Release --output ./publish/api --no-build
- name: Publish Web App
run: dotnet publish src/Presentation/PokManager.Web/PokManager.Web.csproj --configuration Release --output ./publish/web --no-build
- name: Create release archive
run: |
cd publish
tar -czf pokmanager-api-v${{ steps.get_version.outputs.VERSION }}-linux-x64.tar.gz api/
tar -czf pokmanager-web-v${{ steps.get_version.outputs.VERSION }}-linux-x64.tar.gz web/
cd ..
- name: Upload release artifacts
uses: actions/upload-artifact@v7
with:
name: release-artifacts
path: publish/*.tar.gz
retention-days: 90
- name: Generate release notes
id: release_notes
run: |
cat > release_notes.md << 'EOF'
## What's Changed
This release includes the following components:
- PokManager API Service
- PokManager Web Application
- Docker images for containerized deployment
### Installation
Download the appropriate archive for your platform and extract it.
### Docker Images
Docker images are available at:
- `ghcr.io/${{ github.repository_owner }}/pokmanager-api:v${{ steps.get_version.outputs.VERSION }}`
- `ghcr.io/${{ github.repository_owner }}/pokmanager-web:v${{ steps.get_version.outputs.VERSION }}`
### Full Changelog
See commit history for detailed changes.
EOF
echo "release_notes_path=release_notes.md" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
if: startsWith(github.ref, 'refs/tags/')
with:
files: publish/*.tar.gz
body_path: ${{ steps.release_notes.outputs.release_notes_path }}
draft: false
prerelease: false
generate_release_notes: true
build-docker:
name: Build & Push Docker Images
needs: build-release
runs-on: ubuntu-latest
strategy:
matrix:
service: [api, web]
include:
- service: api
dockerfile: src/Presentation/PokManager.ApiService/Dockerfile
image-name: pokmanager-api
- service: web
dockerfile: src/Presentation/PokManager.Web/Dockerfile
image-name: pokmanager-web
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Extract version from tag
id: get_version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION=${GITHUB_REF#refs/tags/v}
fi
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v6
with:
images: ghcr.io/${{ github.repository_owner }}/${{ matrix.image-name }}
tags: |
type=semver,pattern={{version}},value=v${{ steps.get_version.outputs.VERSION }}
type=semver,pattern={{major}}.{{minor}},value=v${{ steps.get_version.outputs.VERSION }}
type=semver,pattern={{major}},value=v${{ steps.get_version.outputs.VERSION }}
type=raw,value=latest
- name: Check if Dockerfile exists
id: dockerfile_check
run: |
if [ -f "${{ matrix.dockerfile }}" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Warning: Dockerfile not found at ${{ matrix.dockerfile }}"
fi
- name: Build and push Docker image
if: steps.dockerfile_check.outputs.exists == 'true'
uses: docker/build-push-action@v7
with:
context: .
file: ${{ matrix.dockerfile }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VERSION=${{ steps.get_version.outputs.VERSION }}
publish-nuget:
name: Publish NuGet Packages
needs: build-release
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Extract version from tag
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
- name: Pack Domain library
run: dotnet pack src/Core/PokManager.Domain/PokManager.Domain.csproj --configuration Release --output ./packages /p:Version=${{ steps.get_version.outputs.VERSION }}
- name: Pack Application library
run: dotnet pack src/Core/PokManager.Application/PokManager.Application.csproj --configuration Release --output ./packages /p:Version=${{ steps.get_version.outputs.VERSION }}
- name: Publish to NuGet (if configured)
if: env.NUGET_API_KEY != ''
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
dotnet nuget push ./packages/*.nupkg \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
- name: Publish to GitHub Packages
run: |
dotnet nuget push ./packages/*.nupkg \
--api-key ${{ secrets.GITHUB_TOKEN }} \
--source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" \
--skip-duplicate