-
Notifications
You must be signed in to change notification settings - Fork 1
226 lines (190 loc) · 6.23 KB
/
ci-cd.yml
File metadata and controls
226 lines (190 loc) · 6.23 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
name: CI/CD Pipeline
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
env:
DOTNET_VERSION: '9.0.x'
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore AzureDevOps.MCP.slnx
- name: Build solution
run: dotnet build AzureDevOps.MCP.slnx --configuration Release --no-restore
- name: Run unit tests
run: dotnet test AzureDevOps.MCP.slnx --configuration Release --no-build --verbosity normal
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: '**/TestResults/**/*'
security-scan:
name: Security Scan
runs-on: ubuntu-latest
needs: test
permissions:
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore dependencies
run: dotnet restore AzureDevOps.MCP.slnx
- name: Run .NET security analysis
run: |
# Run built-in .NET security analysis
dotnet build AzureDevOps.MCP.slnx --configuration Release --verbosity normal /p:RunAnalyzersDuringBuild=true
continue-on-error: true
container-security-scan:
name: Container Security Scan
runs-on: ubuntu-latest
needs: [test, security-scan]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image for scanning
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
push: false
tags: local/azuredevops-mcp:scan
load: true
build-args: |
BUILD_CONFIGURATION=Release
VERSION=${{ github.ref_name }}
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: 'local/azuredevops-mcp:scan'
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: 'trivy-results.sarif'
build-and-push-docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [test, security-scan, container-security-scan]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
BUILD_CONFIGURATION=Release
VERSION=${{ github.ref_name }}
create-release:
name: Create Release
runs-on: ubuntu-latest
needs: [test, security-scan, container-security-scan]
if: startsWith(github.ref, 'refs/tags/v')
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build release artifacts
run: |
dotnet publish src/AzureDevOps.MCP/AzureDevOps.MCP.csproj \
--configuration Release \
--runtime linux-x64 \
--self-contained true \
--output ./artifacts/linux-x64
dotnet publish src/AzureDevOps.MCP/AzureDevOps.MCP.csproj \
--configuration Release \
--runtime win-x64 \
--self-contained true \
--output ./artifacts/win-x64
dotnet publish src/AzureDevOps.MCP/AzureDevOps.MCP.csproj \
--configuration Release \
--runtime osx-x64 \
--self-contained true \
--output ./artifacts/osx-x64
- name: Create archives
run: |
cd artifacts
tar -czf ../azuredevops-mcp-linux-x64.tar.gz linux-x64/
zip -r ../azuredevops-mcp-win-x64.zip win-x64/
tar -czf ../azuredevops-mcp-osx-x64.tar.gz osx-x64/
- name: Generate changelog
id: changelog
run: |
echo "## What's Changed" > CHANGELOG.md
git log --pretty=format:"- %s (%h)" $(git describe --tags --abbrev=0)..HEAD >> CHANGELOG.md
echo "changelog<<EOF" >> $GITHUB_OUTPUT
cat CHANGELOG.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: ${{ steps.changelog.outputs.changelog }}
draft: false
prerelease: false
files: |
azuredevops-mcp-linux-x64.tar.gz
azuredevops-mcp-win-x64.zip
azuredevops-mcp-osx-x64.tar.gz