Merge pull request #10492 from iNavFlight/MrD_Update-OSD.md-for-8.0
[inav.git] / .github / workflows / ci.yml
blob4d2965b5e8f97762f7913b4b4b5e389d4b96b12d
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]
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           echo "NUM_CORES=$(grep processor /proc/cpuinfo  | wc -l)" >> $GITHUB_ENV
44       - uses: actions/cache@v4
45         with:
46           path: downloads
47           key: ${{ runner.os }}-downloads-${{ hashFiles('CMakeLists.txt') }}-${{ hashFiles('**/cmake/*')}}
48       - name: Build targets (${{ matrix.id }})
49         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 -j${{ env.NUM_CORES }} ci
50       - name: Upload artifacts
51         uses: actions/upload-artifact@v4
52         with:
53           name: matrix-${{ env.BUILD_NAME }}.${{ matrix.id }}
54           path: ./build/*.hex
55           retention-days: 1
57   upload-artifacts:
58     runs-on: ubuntu-latest
59     needs: [build]
60     steps:
61       - uses: actions/checkout@v4
62       - name: Setup environment
63         env:
64           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
65         run: |
66           # This is the hash of the commit for the PR
67           # when the action is triggered by PR, empty otherwise
68           COMMIT_ID=${{ github.event.pull_request.head.sha }}
69           # This is the hash of the commit when triggered by push
70           # but the hash of refs/pull/<n>/merge, which is different
71           # from the hash of the latest commit in the PR, that's
72           # why we try github.event.pull_request.head.sha first
73           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
74           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
75           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
76           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
77           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
78           echo "NUM_CORES=$(grep processor /proc/cpuinfo  | wc -l)" >> $GITHUB_ENV
79       - name: Download artifacts
80         uses: actions/download-artifact@v4
81         with:
82           pattern: matrix-inav-*
83           merge-multiple: true
84           path: binaries
85       - name: Build target list
86         run: |
87           ls -1 binaries/*.hex | cut -d/ -f2 > targets.txt
88       - name: Upload firmware images
89         uses: actions/upload-artifact@v4
90         with:
91           name: ${{ env.BUILD_NAME }}
92           path: binaries/*.hex
93       - name: Upload firmware images
94         uses: actions/upload-artifact@v4
95         with:
96           name: targets
97           path: targets.txt
99   build-SITL-Linux:
100     runs-on: ubuntu-latest
101     steps:
102       - uses: actions/checkout@v4
103       - name: Install dependencies
104         run: sudo apt-get update && sudo apt-get -y install ninja-build
105       - name: Setup environment
106         env:
107           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
108         run: |
109           # This is the hash of the commit for the PR
110           # when the action is triggered by PR, empty otherwise
111           COMMIT_ID=${{ github.event.pull_request.head.sha }}
112           # This is the hash of the commit when triggered by push
113           # but the hash of refs/pull/<n>/merge, which is different
114           # from the hash of the latest commit in the PR, that's
115           # why we try github.event.pull_request.head.sha first
116           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
117           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
118           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
119           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
120           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
121           echo "NUM_CORES=$(grep processor /proc/cpuinfo  | wc -l)" >> $GITHUB_ENV
122       - name: Build SITL
123         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -G Ninja .. && ninja -j${{ env.NUM_CORES }}
124       - name: Upload artifacts
125         uses: actions/upload-artifact@v4
126         with:
127           name: ${{ env.BUILD_NAME }}_SITL-Linux
128           path: ./build_SITL/*_SITL
130   build-SITL-Mac:
131     runs-on: macos-latest
132     steps:
133       - uses: actions/checkout@v4
134       - name: Install dependencies
135         run: |
136           brew install cmake ninja ruby
138       - name: Setup environment
139         env:
140           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
141         run: |
142           # This is the hash of the commit for the PR
143           # when the action is triggered by PR, empty otherwise
144           COMMIT_ID=${{ github.event.pull_request.head.sha }}
145           # This is the hash of the commit when triggered by push
146           # but the hash of refs/pull/<n>/merge, which is different
147           # from the hash of the latest commit in the PR, that's
148           # why we try github.event.pull_request.head.sha first
149           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
150           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
151           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
152           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
153           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
154           echo "NUM_CORES=$(grep processor /proc/cpuinfo  | wc -l)" >> $GITHUB_ENV
155       - name: Build SITL
156         run: |
157           mkdir -p build_SITL && cd build_SITL
158           cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -G Ninja ..
159           ninja -j4
161       - name: Upload artifacts
162         uses: actions/upload-artifact@v4
163         with:
164           name: ${{ env.BUILD_NAME }}_SITL-MacOS
165           path: ./build_SITL/*_SITL
167   build-SITL-Windows:
168     runs-on: windows-latest
169     defaults:
170       run:
171         shell: C:\tools\cygwin\bin\bash.exe -o igncr '{0}'
172     steps:
173       - uses: actions/checkout@v4
174       - name: Setup Cygwin
175         uses: egor-tensin/setup-cygwin@v4
176         with:
177           packages: cmake ruby ninja gcc-g++
178       - name: Setup environment
179         env:
180           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
181         run: |
182           # This is the hash of the commit for the PR
183           # when the action is triggered by PR, empty otherwise
184           COMMIT_ID=${{ github.event.pull_request.head.sha }}
185           # This is the hash of the commit when triggered by push
186           # but the hash of refs/pull/<n>/merge, which is different
187           # from the hash of the latest commit in the PR, that's
188           # why we try github.event.pull_request.head.sha first
189           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
190           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
191           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
192           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
193           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
194           
195       - name: Build SITL
196         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -G Ninja .. && ninja -j4
197       - name: Upload artifacts
198         uses: actions/upload-artifact@v4
199         with:
200           name: ${{ env.BUILD_NAME }}_SITL-WIN
201           path: ./build_SITL/*.exe
204   test:
205     #needs: [build]
206     runs-on: ubuntu-latest
207     steps:
208       - uses: actions/checkout@v4
209       - name: Install dependencies
210         run: sudo apt-get update && sudo apt-get -y install ninja-build
211       - name: Run Tests
212         run: mkdir -p build && cd build && cmake -DTOOLCHAIN=none -G Ninja .. && ninja check