Skip to content

Commit 08d518a

Browse files
committed
Add Github CI
Signed-off-by: Karel Blavka <[email protected]>
1 parent 4499196 commit 08d518a

File tree

4 files changed

+439
-0
lines changed

4 files changed

+439
-0
lines changed

.github/gen-applications.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
import yaml
3+
import sys
4+
import json
5+
import os
6+
7+
PREFIX = 'com.hardwario.chester.app.'
8+
9+
if len(sys.argv) != 3:
10+
print("Usage: gen-applications.py <bundle> <type>")
11+
sys.exit(1)
12+
13+
bundle = sys.argv[1]
14+
if not bundle.startswith('com.'):
15+
bundle = f'{PREFIX}{bundle}'
16+
17+
path = os.path.dirname(os.path.realpath(__file__))
18+
filepath = os.path.join(path, '../applications/applications.yaml')
19+
applications = yaml.safe_load(open(filepath))
20+
21+
22+
for a in applications:
23+
if 'fw_bundle' in a and a['fw_bundle'] == bundle:
24+
if sys.argv[2] == 'cmd':
25+
26+
cmd = f'FW_BUNDLE={a["fw_bundle"]}'
27+
28+
if 'fw_name' in a:
29+
cmd += f' FW_NAME="{a["fw_name"]}"'
30+
31+
if 'fw_version' in a:
32+
cmd += f' FW_VERSION={a["fw_version"]}'
33+
34+
cmd += ' west build'
35+
36+
if 'shield' in a or 'extra_args' in a:
37+
cmd += ' --'
38+
39+
if 'shield' in a:
40+
cmd += f' -DSHIELD="{a["shield"]}"'
41+
42+
if 'extra_args' in a:
43+
cmd += f' {a["extra_args"]}'
44+
45+
print(cmd)
46+
47+
sys.exit(0)
48+
49+
elif sys.argv[2] == 'path':
50+
51+
if not 'path' in a:
52+
d = a['fw_bundle'].split('.')[4]
53+
else:
54+
d = a['path']
55+
56+
print(f'chester-sdk/chester/applications/{d}')
57+
58+
sys.exit(0)
59+
60+
elif sys.argv[2] == 'info':
61+
print(json.dumps(a, sort_keys=True))
62+
sys.exit(0)
63+
64+
elif sys.argv[2] == 'fw_bundle':
65+
print(a['fw_bundle'])
66+
sys.exit(0)
67+
68+
else:
69+
print("Unknown type")
70+
sys.exit(1)
71+
else:
72+
print("Bundle not found")
73+
sys.exit(1)

.github/gen-matrix.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
import yaml
3+
import sys
4+
import json
5+
import os
6+
7+
PREFIX = 'com.hardwario.chester.app.'
8+
9+
if len(sys.argv) != 2:
10+
print("Usage: gen-matrix.py <type>")
11+
sys.exit(1)
12+
13+
path = os.path.dirname(os.path.realpath(__file__))
14+
15+
16+
def rmprefix(s):
17+
return s[len(PREFIX):] if s.startswith(PREFIX) else s
18+
19+
20+
if sys.argv[1] == 'applications':
21+
filepath = os.path.join(path, '../applications/applications.yaml')
22+
applications = yaml.safe_load(open(filepath))
23+
applications = [rmprefix(a['fw_bundle'])
24+
for a in applications if 'fw_bundle' in a]
25+
print(json.dumps(applications, sort_keys=True))
26+
27+
elif sys.argv[1] == 'samples':
28+
samples = os.listdir(os.path.join(path, '../samples'))
29+
print(json.dumps([s for s in samples if os.path.isdir(
30+
os.path.join(path, '../samples', s))], sort_keys=True))
31+
32+
else:
33+
print("Unknown type")
34+
sys.exit(1)

.github/workflows/build.yaml

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
paths-ignore:
6+
- '**/README.md'
7+
- '.*'
8+
branches-ignore:
9+
- 'gh-pages'
10+
workflow_dispatch:
11+
12+
jobs:
13+
# ------------------------
14+
prepare:
15+
runs-on: ubuntu-latest
16+
container:
17+
image: hardwario/nrf-connect-sdk-build:v2.5.0-2
18+
outputs:
19+
short_sha: ${{ steps.short-sha.outputs.short-sha }}
20+
samples: ${{ steps.generate-matrix.outputs.samples }}
21+
applications: ${{ steps.generate-matrix.outputs.applications }}
22+
steps:
23+
- name: checkout
24+
uses: actions/checkout@v4
25+
with:
26+
path: 'chester-sdk/chester'
27+
- name: cache
28+
id: cache-chester-sdk
29+
uses: actions/cache@v4
30+
env:
31+
cache-name: cache-chester-sdk
32+
with:
33+
key: chester-sdk-${{ hashFiles('chester-sdk/chester/west.yml') }}
34+
restore-keys: chester-sdk-${{ hashFiles('chester-sdk/chester/west.yml') }}
35+
path: |
36+
chester-sdk/.west
37+
chester-sdk/bootloader
38+
chester-sdk/doxygen-awesome-css
39+
chester-sdk/modules
40+
chester-sdk/nrf
41+
chester-sdk/nrfxlib
42+
chester-sdk/test
43+
chester-sdk/tools
44+
chester-sdk/zephyr
45+
- name: west init and update
46+
if: steps.cache-chester-sdk.outputs.cache-hit != 'true'
47+
run: |
48+
cd chester-sdk
49+
west init -l --mf west.yml chester
50+
west update --narrow
51+
west config build.board chester_nrf52840
52+
- name: short_sha
53+
id: short-sha
54+
run: |
55+
SHORT_SHA=$(git -C chester-sdk/chester rev-parse --short HEAD)
56+
echo short-sha=${SHORT_SHA} >> $GITHUB_OUTPUT
57+
- name: Generate Matrix
58+
id: generate-matrix
59+
working-directory: ./chester-sdk/chester
60+
run: |
61+
SAMPLES=$(python3 .github/gen-matrix.py samples)
62+
echo $SAMPLES
63+
echo samples=${SAMPLES} >> $GITHUB_OUTPUT
64+
APPLICATIONS=$(python3 .github/gen-matrix.py applications)
65+
echo $APPLICATIONS
66+
echo applications=${APPLICATIONS} >> $GITHUB_OUTPUT
67+
68+
# ------------------------
69+
build-sample:
70+
runs-on: ubuntu-latest
71+
container:
72+
image: hardwario/nrf-connect-sdk-build:v2.5.0-2
73+
needs:
74+
- prepare
75+
continue-on-error: true
76+
strategy:
77+
matrix:
78+
sample: ${{ fromJSON(needs.prepare.outputs.samples) }}
79+
steps:
80+
- name: checkout
81+
uses: actions/checkout@v4
82+
with:
83+
path: 'chester-sdk/chester'
84+
- name: restore cache with chester-sdk
85+
id: cache-chester-sdk
86+
uses: actions/cache/restore@v4
87+
env:
88+
cache-name: cache-chester-sdk
89+
with:
90+
fail-on-cache-miss: true
91+
key: chester-sdk-${{ hashFiles('chester-sdk/chester/west.yml') }}
92+
path: |
93+
chester-sdk/.west
94+
chester-sdk/bootloader
95+
chester-sdk/doxygen-awesome-css
96+
chester-sdk/modules
97+
chester-sdk/nrf
98+
chester-sdk/nrfxlib
99+
chester-sdk/test
100+
chester-sdk/tools
101+
chester-sdk/zephyr
102+
- name: build
103+
run: |
104+
cd chester-sdk/chester/samples/${{ matrix.sample }}
105+
west build
106+
# ------------------------
107+
build-app:
108+
runs-on: ubuntu-latest
109+
container:
110+
image: hardwario/nrf-connect-sdk-build:v2.5.0-2
111+
needs:
112+
- prepare
113+
continue-on-error: true
114+
strategy:
115+
matrix:
116+
application: ${{ fromJSON(needs.prepare.outputs.applications) }}
117+
exclude:
118+
- application: _legacy
119+
steps:
120+
- name: checkout
121+
uses: actions/checkout@v4
122+
with:
123+
path: 'chester-sdk/chester'
124+
- name: gen build command
125+
id: build-command
126+
working-directory: ./chester-sdk/chester
127+
run: |
128+
APP_PATH=$(python3 .github/gen-applications.py ${{ matrix.application }} path)
129+
echo $APP_PATH
130+
echo app_path=${APP_PATH} >> $GITHUB_OUTPUT
131+
BUILD_CMD=$(python3 .github/gen-applications.py ${{ matrix.application }} cmd)
132+
echo $BUILD_CMD
133+
echo build_cmd=${BUILD_CMD} >> $GITHUB_OUTPUT
134+
- name: restore cache with chester-sdk
135+
id: cache-chester-sdk
136+
uses: actions/cache/restore@v4
137+
env:
138+
cache-name: cache-chester-sdk
139+
with:
140+
fail-on-cache-miss: true
141+
key: chester-sdk-${{ hashFiles('chester-sdk/chester/west.yml') }}
142+
path: |
143+
chester-sdk/.west
144+
chester-sdk/bootloader
145+
chester-sdk/doxygen-awesome-css
146+
chester-sdk/modules
147+
chester-sdk/nrf
148+
chester-sdk/nrfxlib
149+
chester-sdk/test
150+
chester-sdk/tools
151+
chester-sdk/zephyr
152+
- name: build
153+
working-directory: ${{ steps.build-command.outputs.app_path }}
154+
run: ${{ steps.build-command.outputs.build_cmd }}

0 commit comments

Comments
 (0)