-
Notifications
You must be signed in to change notification settings - Fork 71
136 lines (117 loc) · 4.24 KB
/
build.yml
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
name: Build ExpressLRS Backpack
on: [push, pull_request]
jobs:
targets:
runs-on: ubuntu-latest
outputs:
targets: ${{ steps.set-targets.outputs.targets }}
steps:
- name: Checkout
uses: actions/checkout@v3
- id: set-targets
run: echo "targets=[$(grep -r "\[env:" targets | sed 's/.*://' | sed s/.$// | egrep "UART" | tr '\n' ',' | sed 's/,$/"\n/' | sed 's/,/","/'g | sed 's/^/"/')]" >> $GITHUB_OUTPUT
build:
needs: targets
strategy:
fail-fast: false
matrix:
target: ${{fromJSON(needs.targets.outputs.targets)}}
runs-on: ubuntu-latest
steps:
- name: Inject slug/short variables
uses: rlespinasse/github-slug-action@v4
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.target }}
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio
pip install wheel
- name: Cache PlatformIO
uses: actions/cache@v3
with:
path: ~/.platformio
key: ${{ runner.os }}-platformio
- name: Run PlatformIO
run: |
platformio platform update
platformio platform install native
mkdir -p ~/artifacts/firmware
pio run -e ${{ matrix.target }}
mv .pio/build/${{ matrix.target }} ~/artifacts/firmware/`echo ${{ matrix.target }} | sed s/_via_UART//`
cp -r hardware ~/artifacts/firmware
- name: Store Artifacts
uses: actions/upload-artifact@v3
with:
name: firmware
path: |
~/artifacts/**/*.bin
~/artifacts/**/*.json
continue-on-error: true
firmware:
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Get firmware artifacts
uses: actions/download-artifact@v3
with:
name: firmware
path: dist
- name: Build flasher "binary" with shiv
run: |
cd python
pip install shiv
shiv -c flash -o ../dist/firmware/flasher.pyz pyserial .
- name: Update firmware artifact
uses: actions/upload-artifact@v3
with:
name: firmware
path: dist/**/*
- name: Create firmware zip bundle
run: |
cd dist
zip -r -9 ../firmware.zip .
- name: Upload firmware bundle to ExpressLRS artifactory
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_ENDPOINT_URL: ${{ secrets.AWS_ENDPOINT_URL }}
AWS_REGION: "auto"
run: |
if [[ -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY || -z $AWS_ENDPOINT_URL ]]; then
echo "Artifactory credentials are not defined. Most likely action is running from pull request. Not a bug."
exit 0
fi
echo "Uploading firmware to artifactory"
aws s3 cp --endpoint-url $AWS_ENDPOINT_URL firmware.zip s3://expresslrs/Backpack/$GITHUB_SHA/firmware.zip
echo "Generating artifact index"
aws s3 ls --endpoint-url $AWS_ENDPOINT_URL s3://expresslrs/Backpack/ | awk '{print $2}' | sed s/\\/// > /tmp/hashes
echo '{' > index.json
echo '"branches": {' >> index.json
git branch --list --remotes --format '"%(refname:short)": "%(objectname)",' | grep origin/ | sed s/origin.// | grep -f /tmp/hashes | head -c-2 >> index.json
echo '' >> index.json
echo '},' >> index.json
echo '"tags": {' >> index.json
git tag --list --format '"%(refname:short)": "%(objectname)",' | grep -f /tmp/hashes | head -c-2 >> index.json
echo '' >> index.json
echo '}' >> index.json
echo '}' >> index.json
echo "Uploading artifact index"
aws s3 cp --endpoint-url $AWS_ENDPOINT_URL index.json s3://expresslrs/Backpack/index.json