Allow LR1121 single RF path (#2998)
[ExpressLRS.git] / .github / workflows / build.yml
blob30f43a1b67233f397bbddd95bbb4edc72e451b3d
1 name: Build ExpressLRS
2 on: [push, pull_request]
3 jobs:
4   test:
5     runs-on: ubuntu-latest
6     steps:
8     - name: Inject slug/short variables
9       uses: rlespinasse/github-slug-action@v4
11     - name: Checkout
12       uses: actions/checkout@v4
14     - name: Set up Python
15       uses: actions/setup-python@v5
16       with:
17         python-version: '3.10'
19     - name: Cache pip
20       uses: actions/cache@v4
21       with:
22         path: ~/.cache/pip
23         key: ${{ runner.os }}-pip-${{ matrix.target }}
25     - name: Install PlatformIO
26       run: |
27         python -m pip install --upgrade pip
28         pip install platformio
29         pip install wheel
31     - name: Cache PlatformIO
32       uses: actions/cache@v4
33       with:
34         path: ~/.platformio
35         key: ${{ runner.os }}-platformio
37     - name: Run PlatformIO Tests
38       run: |
39         cd src
40         platformio pkg install --platform native
41         platformio pkg update
42         PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400" pio test -e native
44   targets:
45     runs-on: ubuntu-latest
46     outputs:
47       targets: ${{ steps.set-targets.outputs.targets }}
48     steps:
49     - name: Checkout
50       uses: actions/checkout@v4
51     - id: set-targets
52       run: echo "targets=[$( (grep '\[env:.*UART\]' src/targets/unified.ini ; grep -r '\[env:.*STLINK\]' src/targets/) | sed 's/.*://' | sed s/.$// | egrep "(STLINK|UART)" | grep -v DEPRECATED | tr '\n' ','  | sed 's/,$/"\n/' | sed 's/,/","/'g | sed 's/^/"/')]" >> $GITHUB_OUTPUT
54   build:
55     needs: targets
56     strategy:
57       fail-fast: false
58       matrix:
59         target: ${{fromJSON(needs.targets.outputs.targets)}}
60     runs-on: ubuntu-latest
61     steps:
63     - name: Inject slug/short variables
64       uses: rlespinasse/github-slug-action@v4
66     - name: Checkout
67       uses: actions/checkout@v4
69     - name: Set up Python
70       uses: actions/setup-python@v5
71       with:
72         python-version: '3.10'
74     - name: Cache pip
75       uses: actions/cache@v4
76       with:
77         path: ~/.cache/pip
78         key: ${{ runner.os }}-pip-${{ matrix.target }}
80     - name: Install PlatformIO
81       run: |
82         python -m pip install --upgrade pip
83         pip install platformio
84         pip install wheel
86     - name: Cache PlatformIO
87       uses: actions/cache@v4
88       with:
89         path: ~/.platformio
90         key: ${{ runner.os }}-platformio
92     - name: Run PlatformIO
93       run: |
94         mkdir -p ~/artifacts/firmware
95         cd src
96         platformio pkg install --platform native
97         platformio pkg update
98         case ${{matrix.target}} in
99           *2400* | FM30*)
100             # release builds
101             PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_EU_CE_2400" pio run -e ${{ matrix.target }}
102             OUTDIR=~/artifacts/firmware/LBT/`echo ${{ matrix.target }} | sed s/_via.*//`
103             mkdir -p $OUTDIR
104             mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
106             PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400" pio run -e ${{ matrix.target }}
107             OUTDIR=~/artifacts/firmware/FCC/`echo ${{ matrix.target }} | sed s/_via.*//`
108             mkdir -p $OUTDIR
109             mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
110             ;;
111           *)
112             # release build
113             PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_FCC_915" pio run -e ${{ matrix.target }}
114             OUTDIR=~/artifacts/firmware/FCC/`echo ${{ matrix.target }} | sed s/_via.*//`
115             mkdir -p $OUTDIR
116             mv .pio/build/${{ matrix.target }}/*.{elrs,bin} $OUTDIR >& /dev/null || :
117             ;;
118         esac
120     - name: Store Artifacts
121       uses: actions/upload-artifact@v4
122       with:
123         name: temp-${{ matrix.target }}
124         path: ~/artifacts/**/*
125         retention-days: 1
126       continue-on-error: true
128   firmware:
129     needs: [build, test]
130     runs-on: ubuntu-latest
131     steps:
132       - name: Checkout code
133         uses: actions/checkout@v4
134         with:
135           fetch-depth: 0
137       - name: Checkout targets repo
138         uses: actions/checkout@v4
139         with:
140           repository: ExpressLRS/targets
141           path: src/hardware
143       - name: Get firmware artifacts
144         uses: actions/download-artifact@v4
145         with:
146           path: dist
147           merge-multiple: true
149       - name: Copy hardware files to firmware folder
150         run: |
151           cp -r src/hardware dist/firmware
152           jq 'del(.generic)' src/hardware/targets.json > dist/firmware/hardware/targets.json
154       - name: Copy Lua to to firmware folder
155         run: |
156           mkdir -p dist/firmware/lua
157           cp -r src/lua/elrsV3.lua dist/firmware/lua
159       - name: Copy bootloader files to firmware folder
160         run: cd src ; find bootloader -name \*.bin -o -name \*.frk | grep -v src/ | cpio -pdm ../dist/firmware
162       - name: Set up Python
163         uses: actions/setup-python@v5
164         with:
165           python-version: '3.10'
167       - name: Build flasher "binary" with shiv
168         run: |
169           cd src/python
170           pip install shiv==1.0.6
171           shiv -c flash -o ../../dist/firmware/flasher.pyz pyserial .
173       - name: Update firmware artifact
174         uses: actions/upload-artifact@v4
175         with:
176           name: firmware
177           path: dist/**/*
179       - name: Create firmware zip bundle
180         run: |
181           cd dist
182           zip -r -9 ../firmware.zip ./firmware
184       - name: Upload firmware bundle to ExpressLRS artifactory
185         env:
186           AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
187           AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
188           AWS_ENDPOINT_URL: ${{ secrets.AWS_ENDPOINT_URL }}
189           AWS_REGION: "auto"
190         run: |
191           if [[ -z $AWS_ACCESS_KEY_ID || -z $AWS_SECRET_ACCESS_KEY || -z $AWS_ENDPOINT_URL ]]; then
192             echo "Artifactory credentials are not defined. Most likely action is running from pull request. Not a bug."
193             exit 0
194           fi
196           aws s3api head-object --endpoint-url $AWS_ENDPOINT_URL --bucket expresslrs --key ExpressLRS/$GITHUB_SHA/firmware.zip > /dev/null || ALLOW_UPLOAD=true
197           git describe --tags --exact-match HEAD && ALLOW_UPLOAD=true
198           if [ $ALLOW_UPLOAD ]; then
199             echo "Uploading firmware to artifactory"
200             aws s3 cp --endpoint-url $AWS_ENDPOINT_URL firmware.zip s3://expresslrs/ExpressLRS/$GITHUB_SHA/firmware.zip
202             echo "Generating artifact index"
203             aws s3 ls --endpoint-url $AWS_ENDPOINT_URL s3://expresslrs/ExpressLRS/ | awk '{print $2}' | sed s/\\/// > /tmp/hashes
204             echo '{' > index.json
205             echo '"branches": {' >> index.json
206             git branch --list --remotes --format '"%(refname:short)": "%(objectname)",' | grep origin/ | sed s/origin.// | grep -f /tmp/hashes | head -c-2 >> index.json
207             echo '' >> index.json
208             echo '},' >> index.json
209             echo '"tags": {' >> index.json
210             git tag --list --format '"%(refname:short)": "%(objectname)",' | grep -f /tmp/hashes | head -c-2 >> index.json
211             echo '' >> index.json
212             echo '}' >> index.json
213             echo '}' >> index.json
215             echo "Uploading artifact index"
216             aws s3 cp --endpoint-url $AWS_ENDPOINT_URL index.json s3://expresslrs/ExpressLRS/index.json
217           else
218             echo "Not overwriting already existing artifact at $GITHUB_SHA"
219             exit 1
220           fi