-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (162 loc) · 5.99 KB
/
Copy pathrelease.yml
File metadata and controls
192 lines (162 loc) · 5.99 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
name: Generate Release and Deploy to Production
on:
push:
branches:
- main
workflow_dispatch: # Allow manual trigger
repository_dispatch: # Allow trigger from other repos (e.g., RavenBrain)
types: [deploy]
jobs:
publish:
if: github.event_name != 'repository_dispatch'
permissions:
contents: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
outputs:
released: ${{ steps.semantic.outputs.new_release_published }}
version: ${{ steps.semantic.outputs.new_release_version }}
tag: ${{ steps.semantic.outputs.new_release_git_tag }}
steps:
- name: Generate release bot token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RELEASE_APP_ID }}
private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }}
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
token: ${{ steps.app-token.outputs.token }}
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Install dependencies
run: npm ci
- name: Check Types
run: npm run typecheck
- name: Build (validation only — rebuilt in build job with correct version)
env:
VITE_API_HOST: ${{ vars.VITE_API_HOST || 'https://ravenbrain.team1310.ca' }}
run: npm run build
- name: Semantic Release
id: semantic
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
node --input-type=module << 'EOF'
import semanticRelease from 'semantic-release';
import { appendFileSync } from 'fs';
const result = await semanticRelease();
const output = process.env.GITHUB_OUTPUT;
if (result) {
appendFileSync(output, `new_release_published=true\n`);
appendFileSync(output, `new_release_version=${result.nextRelease.version}\n`);
appendFileSync(output, `new_release_git_tag=${result.nextRelease.gitTag}\n`);
console.log(`Released ${result.nextRelease.version}`);
} else {
appendFileSync(output, `new_release_published=false\n`);
console.log('No release published');
}
EOF
build:
needs: publish
if: needs.publish.outputs.released == 'true'
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image-name.outputs.image }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ needs.publish.outputs.tag }}
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Install dependencies
run: npm ci
- name: Build
env:
VITE_API_HOST: ${{ vars.VITE_API_HOST || 'https://ravenbrain.team1310.ca' }}
run: npm run build
- name: Set image name
id: image-name
run: echo "image=ghcr.io/${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
- 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: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
platforms: linux/amd64
tags: |
${{ steps.image-name.outputs.image }}:${{ needs.publish.outputs.version }}
${{ steps.image-name.outputs.image }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# Unified deploy job handles both RavenEye builds and external triggers (e.g., RavenBrain)
# External trigger: echo '{"event_type":"deploy","client_payload":{"service":"app"}}' | gh api repos/RunnymedeRobotics1310/RavenEye/dispatches --input -
deploy:
needs: build
if: always() && (needs.build.result == 'success' || github.event_name == 'repository_dispatch')
permissions:
contents: read
packages: read
runs-on: self-hosted
steps:
- name: Determine deployment target
id: target
run: |
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
SERVICE="${{ github.event.client_payload.service || 'app' }}"
if [ "$SERVICE" = "app" ]; then
IMAGE="ghcr.io/runnymederobotics1310/ravenbrain:latest"
else
IMAGE="ghcr.io/runnymederobotics1310/raveneye:latest"
fi
else
SERVICE="nginx"
IMAGE="${{ needs.build.outputs.image }}:latest"
fi
echo "service=$SERVICE" >> $GITHUB_OUTPUT
echo "image=$IMAGE" >> $GITHUB_OUTPUT
echo "Deploying $SERVICE using $IMAGE"
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Pull latest image
run: docker pull ${{ steps.target.outputs.image }}
- name: Deploy service
run: |
RAVENEYE_IMAGE=${{ steps.target.outputs.image }} \
docker compose --env-file /opt/raveneye-config/.env \
-f docker-compose.yml -f docker-compose.prod.yml up -d ${{ steps.target.outputs.service }}
- name: Verify deployment
run: |
echo "Waiting for ${{ steps.target.outputs.service }} to start..."
sleep 10
docker compose --env-file /opt/raveneye-config/.env \
-f docker-compose.yml -f docker-compose.prod.yml ps ${{ steps.target.outputs.service }}
echo "Deployment complete"
- name: Cleanup old images
run: docker image prune -f