Set blackbox file handler to NULL after closing file
[inav.git] / .github / workflows / ci.yml
blob4663febe50e5a996d5568bff90b43f3fe757ffc2
1 name: Build firmware
2 # Don't enable CI on push, just on PR. If you
3 # are working on the main repo and want to trigger
4 # a CI build submit a draft PR.
5 on: 
6   pull_request:
7     paths:
8       - 'src/**'
9       - '.github/**'
10       - 'cmake/**'
11       - 'lib/**'
12       - 'docs/Settings.md'
13       - 'CMakeLists.txt'
14       - '*.sh'
16 jobs:
17   build:
18     runs-on: ubuntu-latest
19     strategy:
20         matrix:
21           id: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
23     steps:
24       - uses: actions/checkout@v4
25       - name: Install dependencies
26         run: sudo apt-get update && sudo apt-get -y install ninja-build
27       - name: Setup environment
28         env:
29           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
30         run: |
31           # This is the hash of the commit for the PR
32           # when the action is triggered by PR, empty otherwise
33           COMMIT_ID=${{ github.event.pull_request.head.sha }}
34           # This is the hash of the commit when triggered by push
35           # but the hash of refs/pull/<n>/merge, which is different
36           # from the hash of the latest commit in the PR, that's
37           # why we try github.event.pull_request.head.sha first
38           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
39           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
40           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
41           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
42           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
43       - uses: actions/cache@v4
44         with:
45           path: downloads
46           key: ${{ runner.os }}-downloads-${{ hashFiles('CMakeLists.txt') }}-${{ hashFiles('**/cmake/*')}}
47       - name: Build targets (${{ matrix.id }})
48         run: mkdir -p build && cd build && cmake -DWARNINGS_AS_ERRORS=ON -DCI_JOB_INDEX=${{ matrix.id }} -DCI_JOB_COUNT=${{ strategy.job-total }} -DBUILD_SUFFIX=${{ env.BUILD_SUFFIX }} -DMAIN_COMPILE_OPTIONS=-pipe -G Ninja .. && ninja -j4 ci
49       - name: Upload artifacts
50         uses: actions/upload-artifact@v4
51         with:
52           name: matrix-${{ env.BUILD_NAME }}.${{ matrix.id }}
53           path: ./build/*.hex
54           retention-days: 1
56   upload-artifacts:
57     runs-on: ubuntu-latest
58     needs: [build]
59     steps:
60       - uses: actions/checkout@v4
61       - name: Setup environment
62         env:
63           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
64         run: |
65           # This is the hash of the commit for the PR
66           # when the action is triggered by PR, empty otherwise
67           COMMIT_ID=${{ github.event.pull_request.head.sha }}
68           # This is the hash of the commit when triggered by push
69           # but the hash of refs/pull/<n>/merge, which is different
70           # from the hash of the latest commit in the PR, that's
71           # why we try github.event.pull_request.head.sha first
72           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
73           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
74           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
75           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
76           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
77       - name: Download artifacts
78         uses: actions/download-artifact@v4
79         with:
80           pattern: matrix-inav-*
81           merge-multiple: true
82           path: binaries
83       - name: Build target list
84         run: |
85           ls -1 binaries/*.hex | cut -d/ -f2 > targets.txt
86       - name: Upload firmware images
87         uses: actions/upload-artifact@v4
88         with:
89           name: ${{ env.BUILD_NAME }}
90           path: binaries/*.hex
91       - name: Upload firmware images
92         uses: actions/upload-artifact@v4
93         with:
94           name: targets
95           path: targets.txt
97   build-SITL-Linux:
98     runs-on: ubuntu-latest
99     steps:
100       - uses: actions/checkout@v4
101       - name: Install dependencies
102         run: sudo apt-get update && sudo apt-get -y install ninja-build
103       - name: Setup environment
104         env:
105           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
106         run: |
107           # This is the hash of the commit for the PR
108           # when the action is triggered by PR, empty otherwise
109           COMMIT_ID=${{ github.event.pull_request.head.sha }}
110           # This is the hash of the commit when triggered by push
111           # but the hash of refs/pull/<n>/merge, which is different
112           # from the hash of the latest commit in the PR, that's
113           # why we try github.event.pull_request.head.sha first
114           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
115           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
116           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
117           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
118           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
119       - name: Build SITL
120         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -G Ninja .. && ninja -j4
121       - name: Upload artifacts
122         uses: actions/upload-artifact@v4
123         with:
124           name: ${{ env.BUILD_NAME }}_SITL-Linux
125           path: ./build_SITL/*_SITL
127   build-SITL-Mac:
128     runs-on: macos-latest
129     steps:
130       - uses: actions/checkout@v4
131       - name: Install dependencies
132         run: |
133           brew install cmake ninja ruby
135       - name: Setup environment
136         env:
137           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
138         run: |
139           # This is the hash of the commit for the PR
140           # when the action is triggered by PR, empty otherwise
141           COMMIT_ID=${{ github.event.pull_request.head.sha }}
142           # This is the hash of the commit when triggered by push
143           # but the hash of refs/pull/<n>/merge, which is different
144           # from the hash of the latest commit in the PR, that's
145           # why we try github.event.pull_request.head.sha first
146           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
147           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
148           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
149           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
150           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
151       - name: Build SITL
152         run: |
153           mkdir -p build_SITL && cd build_SITL
154           cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -G Ninja ..
155           ninja -j3
157       - name: Upload artifacts
158         uses: actions/upload-artifact@v4
159         with:
160           name: ${{ env.BUILD_NAME }}_SITL-MacOS
161           path: ./build_SITL/*_SITL
163   build-SITL-Windows:
164     runs-on: windows-latest
165     defaults:
166       run:
167         shell: C:\tools\cygwin\bin\bash.exe -o igncr '{0}'
168     steps:
169       - uses: actions/checkout@v4
170       - name: Setup Cygwin
171         uses: egor-tensin/setup-cygwin@v4
172         with:
173           packages: cmake ruby ninja gcc-g++
174       - name: Setup environment
175         env:
176           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
177         run: |
178           # This is the hash of the commit for the PR
179           # when the action is triggered by PR, empty otherwise
180           COMMIT_ID=${{ github.event.pull_request.head.sha }}
181           # This is the hash of the commit when triggered by push
182           # but the hash of refs/pull/<n>/merge, which is different
183           # from the hash of the latest commit in the PR, that's
184           # why we try github.event.pull_request.head.sha first
185           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
186           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
187           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
188           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
189           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
190       - name: Build SITL
191         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -G Ninja .. && ninja -j4
192       - name: Upload artifacts
193         uses: actions/upload-artifact@v4
194         with:
195           name: ${{ env.BUILD_NAME }}_SITL-WIN
196           path: ./build_SITL/*.exe
199   test:
200     #needs: [build]
201     runs-on: ubuntu-latest
202     steps:
203       - uses: actions/checkout@v4
204       - name: Install dependencies
205         run: sudo apt-get update && sudo apt-get -y install ninja-build
206       - name: Run Tests
207         run: mkdir -p build && cd build && cmake -DTOOLCHAIN=none -G Ninja .. && ninja check