-
Notifications
You must be signed in to change notification settings - Fork 0
485 lines (420 loc) · 15.2 KB
/
release-automation.yml
File metadata and controls
485 lines (420 loc) · 15.2 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
name: "Automated Release & Deployment"
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
release_type:
description: 'Release type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
pre_release:
description: 'Pre-release'
required: false
default: false
type: boolean
permissions:
contents: write
packages: write
deployments: write
actions: read
default: false
type: boolean
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
# Automated version bumping
version-bump:
name: Version Bump
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
permissions:
contents: write
outputs:
new_version: ${{ steps.version.outputs.new_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install semver tool
run: npm install -g semver
- name: Get current version
id: current
run: |
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
- name: Calculate new version
id: version
run: |
CURRENT="${{ steps.current.outputs.current_version }}"
NEW_VERSION=$(semver -i ${{ github.event.inputs.release_type }} $CURRENT)
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version will be: $NEW_VERSION"
- name: Update Cargo.toml
run: |
sed -i 's/^version = ".*"/version = "${{ steps.version.outputs.new_version }}"/' Cargo.toml
- name: Update Go module version
run: |
# Update version in Go files if needed
find . -name "*.go" -exec sed -i 's/Version.*=.*".*"/Version = "${{ steps.version.outputs.new_version }}"/' {} \; || true
- name: Commit version bump
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add Cargo.toml
git commit -m "chore: bump version to ${{ steps.version.outputs.new_version }}"
git tag "v${{ steps.version.outputs.new_version }}"
git push origin main
git push origin "v${{ steps.version.outputs.new_version }}"
# Multi-platform release builds
build-release:
name: Build Release (${{ matrix.target }})
runs-on: ${{ matrix.os }}
needs: version-bump
if: always() && (needs.version-bump.result == 'success' || github.event_name == 'push')
permissions:
contents: read
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: universal-ai-governor-linux-amd64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
name: universal-ai-governor-linux-arm64
- target: x86_64-pc-windows-msvc
os: windows-latest
name: universal-ai-governor-windows-amd64.exe
- target: x86_64-apple-darwin
os: macos-latest
name: universal-ai-governor-macos-amd64
- target: aarch64-apple-darwin
os: macos-latest
name: universal-ai-governor-macos-arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Clear Rust caches
run: |
rm -rf ~/.cargo/registry
rm -rf ~/.cargo/git
- name: Install cross-compilation tools
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-aarch64-linux-gnu
- name: Install system dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
pkg-config \
libssl-dev \
libtss2-dev \
libopencv-dev \
libclang-dev
- name: Install system dependencies (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install pkg-config openssl opencv llvm
- name: Install system dependencies (Windows)
if: matrix.os == 'windows-latest'
run: |
choco install llvm opencv
- name: Cache dependencies
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
- name: Build release binary
run: |
cargo build --release --target ${{ matrix.target }} --all-features
- name: Strip binary (Unix)
if: matrix.os != 'windows-latest'
run: |
strip target/${{ matrix.target }}/release/universal-ai-governor
- name: Create release package
run: |
mkdir -p release-package
# Copy binary
if [ "${{ matrix.os }}" = "windows-latest" ]; then
cp target/${{ matrix.target }}/release/universal-ai-governor.exe release-package/${{ matrix.name }}
else
cp target/${{ matrix.target }}/release/universal-ai-governor release-package/${{ matrix.name }}
fi
# Copy documentation and configs
cp README.md LICENSE CHANGELOG.md release-package/
cp -r config release-package/
cp -r docs release-package/
- name: Create archive
run: |
cd release-package
if [ "${{ matrix.os }}" = "windows-latest" ]; then
7z a ../${{ matrix.name }}.zip *
else
tar -czf ../${{ matrix.name }}.tar.gz *
fi
- name: Upload release artifact
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.name }}
path: |
${{ matrix.name }}.tar.gz
${{ matrix.name }}.zip
# Build and push Docker images
docker-release:
name: Docker Release
runs-on: ubuntu-latest
needs: version-bump
if: always() && (needs.version-bump.result == 'success' || github.event_name == 'push')
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 Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION="${{ needs.version-bump.outputs.new_version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build and push Docker images
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
morningstarxcd/universal-ai-governor:latest
morningstarxcd/universal-ai-governor:${{ steps.version.outputs.version }}
ghcr.io/mstarrobotics/universal-ai-governor:latest
ghcr.io/mstarrobotics/universal-ai-governor:${{ steps.version.outputs.version }}
labels: |
org.opencontainers.image.title=Universal AI Governor
org.opencontainers.image.description=Hardware-backed AI governance platform
org.opencontainers.image.version=${{ steps.version.outputs.version }}
org.opencontainers.image.source=https://github.com/MStarRobotics/Universal-AI-Governor
org.opencontainers.image.licenses=MIT
cache-from: type=gha
cache-to: type=gha,mode=max
# Create GitHub release
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [build-release, docker-release]
if: always() && needs.build-release.result == 'success'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download all release artifacts
uses: actions/download-artifact@v3
with:
path: release-artifacts
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION="${{ needs.version-bump.outputs.new_version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
if [ "${{ github.event_name }}" = "push" ]; then
# Get changes since last tag
LAST_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
CHANGELOG=$(git log --pretty=format:"- %s" $LAST_TAG..HEAD)
else
CHANGELOG=$(git log --pretty=format:"- %s" -10)
fi
else
CHANGELOG="Automated release v${{ steps.version.outputs.version }}"
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.version.outputs.version }}
name: Universal AI Governor v${{ steps.version.outputs.version }}
body: |
## Universal AI Governor v${{ steps.version.outputs.version }}
### Changes
${{ steps.changelog.outputs.CHANGELOG }}
### Installation
**Docker:**
```bash
docker run -p 8080:8080 morningstarxcd/universal-ai-governor:${{ steps.version.outputs.version }}
```
**Binary Download:**
Download the appropriate binary for your platform from the assets below.
**From Source:**
```bash
git clone https://github.com/MStarRobotics/Universal-AI-Governor.git
cd Universal-AI-Governor
git checkout v${{ steps.version.outputs.version }}
./scripts/build.sh --release
```
### Docker Images
- `morningstarxcd/universal-ai-governor:${{ steps.version.outputs.version }}`
- `ghcr.io/mstarrobotics/universal-ai-governor:${{ steps.version.outputs.version }}`
### Checksums
See the checksums.txt file for binary verification.
### Security
This release has been automatically scanned for security vulnerabilities.
All dependencies have been updated to their latest secure versions.
files: release-artifacts/**/*
draft: false
prerelease: ${{ github.event.inputs.pre_release == 'true' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Deploy to staging environment
deploy-staging:
name: Deploy to Staging
runs-on: ubuntu-latest
needs: [create-release]
if: always() && needs.create-release.result == 'success'
environment: staging
permissions:
contents: read
deployments: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to staging
run: |
echo "Deploying to staging environment..."
# Add actual deployment commands here
# This could include:
# - Updating Kubernetes deployments
# - Triggering cloud deployments
# - Running deployment scripts
./scripts/deploy.sh --env staging --type kubernetes || echo "Deployment script not ready"
- name: Run smoke tests
run: |
echo "Running smoke tests against staging..."
# Add smoke test commands here
sleep 30 # Wait for deployment
curl -f http://staging.universal-ai-governor.com/health || echo "Smoke tests not ready"
# Notify stakeholders
notify-release:
name: Notify Release
runs-on: ubuntu-latest
needs: [create-release, deploy-staging]
if: always()
permissions:
contents: read
discussions: write
steps:
- name: Extract version
id: version
run: |
if [ "${{ github.event_name }}" = "push" ]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
VERSION="${{ needs.version-bump.outputs.new_version }}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Notify Slack
if: secrets.SLACK_WEBHOOK
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
channel: '#releases'
webhook_url: ${{ secrets.SLACK_WEBHOOK }}
fields: repo,message,commit,author,action,eventName,ref,workflow
custom_payload: |
{
"text": "Universal AI Governor v${{ steps.version.outputs.version }} Released!",
"attachments": [{
"color": "${{ job.status == 'success' && 'good' || 'danger' }}",
"fields": [{
"title": "Version",
"value": "v${{ steps.version.outputs.version }}",
"short": true
}, {
"title": "Status",
"value": "${{ job.status }}",
"short": true
}, {
"title": "Repository",
"value": "https://github.com/MStarRobotics/Universal-AI-Governor",
"short": false
}]
}]
}
- name: Create GitHub Discussion
uses: actions/github-script@v7
with:
script: |
github.rest.teams.addOrUpdateRepoPermissionsInOrg({
org: context.repo.owner,
team_slug: 'developers',
owner: context.repo.owner,
repo: context.repo.repo,
permission: 'push'
});
// Create a discussion about the release
const discussion = await github.rest.repos.createDiscussion({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Universal AI Governor v${{ steps.version.outputs.version }} Released`,
body: `
## New Release Available!
Universal AI Governor v${{ steps.version.outputs.version }} has been released with new features and security improvements.
**What's New:**
- Enhanced security scanning and vulnerability management
- Improved performance and stability
- Updated dependencies with latest security patches
**Download:**
- [GitHub Release](https://github.com/MStarRobotics/Universal-AI-Governor/releases/tag/v${{ steps.version.outputs.version }})
- [Docker Image](https://hub.docker.com/r/morningstarxcd/universal-ai-governor)
**Feedback:**
Please share your feedback and report any issues you encounter.
`,
category_id: 'general'
});
console.log('Created discussion:', discussion.data.html_url);