Skip to content

Commit 8ac28a2

Browse files
committed
Merge branch 'control-station/workflows' into control-station/electron
2 parents 9b4a370 + 4aba59a commit 8ac28a2

9 files changed

Lines changed: 1072 additions & 554 deletions

File tree

File renamed without changes.
File renamed without changes.

.github/ex_workflows/release.yaml

Lines changed: 595 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

.github/workflows/build.yaml

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,319 @@
1+
name: Build Backend and Frontend
2+
3+
on:
4+
push:
5+
branches:
6+
- production
7+
pull_request:
8+
branches:
9+
- production
10+
workflow_dispatch:
11+
inputs:
12+
rebuild-backend:
13+
description: Rebuild backends
14+
type: boolean
15+
default: false
16+
rebuild-control-station:
17+
description: Rebuild control station
18+
type: boolean
19+
default: false
20+
rebuild-ethernet-view:
21+
description: Rebuild ethernet view
22+
type: boolean
23+
default: false
24+
rebuild-common-front:
25+
description: Rebuild common front
26+
type: boolean
27+
default: false
28+
jobs:
29+
# Detect what changed
30+
detect-changes:
31+
name: Detect Changes
32+
runs-on: ubuntu-latest
33+
outputs:
34+
backend_needs_rebuild: ${{ steps.changes.outputs.backend_any_changed == 'true' || github.event.inputs.rebuild-backend == 'true' }}
35+
control-station_needs_rebuild: ${{ steps.changes.outputs.control-station_any_changed == 'true' || github.event.inputs.rebuild-control-station == 'true' }}
36+
ethernet-view_needs_rebuild: ${{ steps.changes.outputs.ethernet-view_any_changed == 'true' || github.event.inputs.rebuild-ethernet-view == 'true' }}
37+
common-front_needs_rebuild: ${{ steps.changes.outputs.common-front_any_changed == 'true' || github.event.inputs.rebuild-common-front == 'true' }}
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
with:
42+
fetch-depth: 0
43+
44+
- name: Detect changed files
45+
id: changes
46+
uses: tj-actions/changed-files@v41
47+
with:
48+
files_yaml: |
49+
backend:
50+
- 'backend/**/*'
51+
control-station:
52+
- 'control-station/**/*'
53+
ethernet-view:
54+
- 'ethernet-view/**/*'
55+
common-front:
56+
- 'common-front/**/*'
57+
58+
- name: Debug changed files
59+
run: |
60+
echo "Changed backend: ${{ steps.changes.outputs.backend_any_changed }}"
61+
echo "Changed control-station: ${{ steps.changes.outputs.control-station_any_changed }}"
62+
echo "Changed ethernet-view: ${{ steps.changes.outputs.ethernet-view_any_changed }}"
63+
echo "Changed common-front: ${{ steps.changes.outputs.common-front_any_changed }}"
64+
65+
# Download backend from previous build if no changes
66+
download-backend:
67+
name: Download Backend - ${{ matrix.platform }}
68+
needs: detect-changes
69+
if: needs.detect-changes.outputs.backend_needs_rebuild != 'true'
70+
runs-on: ubuntu-latest
71+
# Continue on error is necessary because download-backend job can fail if backend artifact is not found
72+
# and it is not necessary to fail the build in this case
73+
continue-on-error: true
74+
outputs:
75+
downloaded: ${{ steps.download.outcome == 'success' }}
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
platform: [linux, windows, macos-intel, macos-arm64]
80+
81+
steps:
82+
- name: Download backend from latest build
83+
id: download
84+
uses: dawidd6/action-download-artifact@v3
85+
with:
86+
workflow: build.yaml
87+
branch: production
88+
workflow_conclusion: success
89+
name: backend-${{ matrix.platform }}
90+
path: backend-artifacts
91+
if_no_artifact_found: fail
92+
93+
- name: Re-upload backend artifact
94+
if: steps.download.outcome == 'success'
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: backend-${{ matrix.platform }}
98+
path: backend-artifacts/*
99+
retention-days: 30
100+
101+
# Build Go backends on native platforms
102+
# only if backend changed or download-backend failed
103+
build-backend:
104+
name: Build Backend - ${{ matrix.platform }}
105+
needs: [detect-changes, download-backend]
106+
# Always is needed to execute this job even if backend download failed
107+
# By default it would be skipped because dependent job failed
108+
if: always() &&
109+
(needs.detect-changes.outputs.backend_needs_rebuild == 'true' ||
110+
needs.download-backend.outputs.downloaded != 'true')
111+
runs-on: ${{ matrix.os }}
112+
strategy:
113+
fail-fast: false
114+
matrix:
115+
include:
116+
- os: ubuntu-latest
117+
platform: linux
118+
binary_name: backend-linux-amd64
119+
120+
- os: windows-latest
121+
platform: windows
122+
binary_name: backend-windows-amd64.exe
123+
124+
- os: macos-latest
125+
platform: macos-intel
126+
binary_name: backend-darwin-amd64
127+
goarch: amd64
128+
129+
- os: macos-latest
130+
platform: macos-arm64
131+
binary_name: backend-darwin-arm64
132+
goarch: arm64
133+
134+
steps:
135+
- name: Checkout repository
136+
uses: actions/checkout@v4
137+
138+
- name: Setup Go
139+
uses: actions/setup-go@v4
140+
with:
141+
go-version: "1.21"
142+
143+
- name: Install Linux dependencies
144+
if: runner.os == 'Linux'
145+
run: sudo apt-get update && sudo apt-get install -y libpcap-dev gcc
146+
147+
- name: Install macOS dependencies
148+
if: runner.os == 'macOS'
149+
run: brew install libpcap
150+
151+
- name: Build backend (Linux)
152+
if: runner.os == 'Linux'
153+
working-directory: backend/cmd
154+
run: |
155+
CGO_ENABLED=1 go build -o ${{ matrix.binary_name }} .
156+
157+
- name: Build backend (Windows)
158+
if: runner.os == 'Windows'
159+
working-directory: backend/cmd
160+
run: |
161+
$env:CGO_ENABLED="1"
162+
go build -o ${{ matrix.binary_name }} .
163+
shell: pwsh
164+
165+
- name: Build backend (macOS)
166+
if: runner.os == 'macOS'
167+
working-directory: backend/cmd
168+
run: |
169+
CGO_ENABLED=1 GOARCH=${{ matrix.goarch }} go build -o ${{ matrix.binary_name }} .
170+
171+
- name: Upload backend binary
172+
uses: actions/upload-artifact@v4
173+
with:
174+
name: backend-${{ matrix.platform }}
175+
path: backend/cmd/${{ matrix.binary_name }}
176+
retention-days: 30
177+
178+
# Download control-station from previous build if no changes
179+
download-control-station:
180+
name: Download Control Station
181+
needs: detect-changes
182+
# The condition checks if control station changed or common front changed
183+
if: needs.detect-changes.outputs.control-station_needs_rebuild != 'true' && needs.detect-changes.outputs.common-front_needs_rebuild != 'true'
184+
runs-on: ubuntu-latest
185+
# Continue on error is necessary because download-control-station job can fail if control station artifact is not found
186+
# and it is not necessary to fail the build in this case
187+
continue-on-error: true
188+
outputs:
189+
downloaded: ${{ steps.download.outcome == 'success' }}
190+
steps:
191+
- name: Download control-station from latest build
192+
id: download
193+
uses: dawidd6/action-download-artifact@v3
194+
with:
195+
workflow: build.yaml
196+
branch: production
197+
workflow_conclusion: success
198+
name: control-station
199+
path: control-station-artifacts
200+
if_no_artifact_found: fail
201+
202+
- name: Re-upload control-station artifact
203+
if: steps.download.outcome == 'success'
204+
uses: actions/upload-artifact@v4
205+
with:
206+
name: control-station
207+
path: control-station-artifacts/**
208+
retention-days: 30
209+
210+
# Build control-station (if control-station or common-front changed)
211+
build-control-station:
212+
name: Build Control Station
213+
needs: [detect-changes, download-control-station]
214+
# Always is needed to execute this job even if control station download failed
215+
# By default it would be skipped because dependent job failed
216+
# The condition checks if control station changed or common front changed or download control station failed
217+
if: always() &&
218+
(needs.detect-changes.outputs.control-station_needs_rebuild == 'true' ||
219+
needs.detect-changes.outputs.common-front_needs_rebuild == 'true' ||
220+
needs.download-control-station.outputs.downloaded != 'true')
221+
runs-on: ubuntu-latest
222+
steps:
223+
- name: Checkout repository
224+
uses: actions/checkout@v4
225+
226+
- name: Setup Node.js
227+
uses: actions/setup-node@v4
228+
with:
229+
node-version: "20"
230+
231+
- name: Build common-front
232+
working-directory: common-front
233+
run: |
234+
npm ci
235+
npm run build
236+
237+
- name: Build control-station
238+
working-directory: control-station
239+
run: |
240+
npm ci
241+
npm run build
242+
243+
- name: Upload control-station artifact
244+
uses: actions/upload-artifact@v4
245+
with:
246+
name: control-station
247+
path: control-station/static/**
248+
retention-days: 30
249+
250+
# Download ethernet-view from previous build if no changes
251+
download-ethernet-view:
252+
name: Download Ethernet View
253+
needs: detect-changes
254+
if: needs.detect-changes.outputs.ethernet-view_needs_rebuild != 'true' && needs.detect-changes.outputs.common-front_needs_rebuild != 'true'
255+
runs-on: ubuntu-latest
256+
# Continue on error is necessary because download-ethernet-view job can fail if ethernet view artifact is not found
257+
# and it is not necessary to fail the build in this case
258+
continue-on-error: true
259+
outputs:
260+
downloaded: ${{ steps.download.outcome == 'success' }}
261+
steps:
262+
- name: Download ethernet-view from latest build
263+
id: download
264+
uses: dawidd6/action-download-artifact@v3
265+
with:
266+
workflow: build.yaml
267+
branch: production
268+
workflow_conclusion: success
269+
name: ethernet-view
270+
path: ethernet-view-artifacts
271+
if_no_artifact_found: fail
272+
273+
- name: Re-upload ethernet-view artifact
274+
if: steps.download.outcome == 'success'
275+
uses: actions/upload-artifact@v4
276+
with:
277+
name: ethernet-view
278+
path: ethernet-view-artifacts/**
279+
retention-days: 30
280+
281+
# Build ethernet-view (if ethernet-view or common-front changed)
282+
build-ethernet-view:
283+
name: Build Ethernet View
284+
needs: [detect-changes, download-ethernet-view]
285+
# Always is needed to execute this job even if ethernet view download failed
286+
# By default it would be skipped because dependent job failed
287+
# The condition checks if ethernet view changed or common front changed or download ethernet view failed
288+
if: always() &&
289+
(needs.detect-changes.outputs.ethernet-view_needs_rebuild == 'true' ||
290+
needs.detect-changes.outputs.common-front_needs_rebuild == 'true' ||
291+
needs.download-ethernet-view.outputs.downloaded != 'true')
292+
runs-on: ubuntu-latest
293+
steps:
294+
- name: Checkout repository
295+
uses: actions/checkout@v4
296+
297+
- name: Setup Node.js
298+
uses: actions/setup-node@v4
299+
with:
300+
node-version: "20"
301+
302+
- name: Build common-front
303+
working-directory: common-front
304+
run: |
305+
npm ci
306+
npm run build
307+
308+
- name: Build ethernet-view
309+
working-directory: ethernet-view
310+
run: |
311+
npm ci
312+
npm run build
313+
314+
- name: Upload ethernet-view artifact
315+
uses: actions/upload-artifact@v4
316+
with:
317+
name: ethernet-view
318+
path: ethernet-view/static/**
319+
retention-days: 30

0 commit comments

Comments
 (0)