Set blackbox file handler to NULL after closing file
[inav.git] / .github / workflows / dev-builds.yml
blob94492966f79f575cb1cfe80f3384b6d2e092e1ab
1 name: Build pre-release
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   push:
7     branches:
8     - master
9     paths:
10       - 'src/**'
11       - '.github/**'
12       - 'cmake/**'
13       - 'lib/**'
14       - 'docs/Settings.md'
15       - 'CMakeLists.txt'
16       - '*.sh'
18 jobs:
19   build:
20     runs-on: ubuntu-latest
21     strategy:
22         matrix:
23           id: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
25     steps:
26       - uses: actions/checkout@v4
27       - name: Install dependencies
28         run: sudo apt-get update && sudo apt-get -y install ninja-build
29       - name: Setup environment
30         env:
31           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
32         run: |
33           # This is the hash of the commit for the PR
34           # when the action is triggered by PR, empty otherwise
35           COMMIT_ID=${{ github.event.pull_request.head.sha }}
36           # This is the hash of the commit when triggered by push
37           # but the hash of refs/pull/<n>/merge, which is different
38           # from the hash of the latest commit in the PR, that's
39           # why we try github.event.pull_request.head.sha first
40           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
41           BUILD_SUFFIX=dev-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
42           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
43           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
44           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
45       - uses: actions/cache@v4
46         with:
47           path: downloads
48           key: ${{ runner.os }}-downloads-${{ hashFiles('CMakeLists.txt') }}-${{ hashFiles('**/cmake/*')}}
49       - name: Build targets (${{ matrix.id }})
50         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 }} -DVERSION_TYPE=dev -G Ninja .. && ninja ci
51       - name: Upload artifacts
52         uses: actions/upload-artifact@v4
53         with:
54           name: ${{ env.BUILD_NAME }}.${{ matrix.id }}
55           path: ./build/*.hex
57   build-SITL-Linux:
58     runs-on: ubuntu-latest
59     steps:
60       - uses: actions/checkout@v4
61       - name: Install dependencies
62         run: sudo apt-get update && sudo apt-get -y install ninja-build
63       - name: Setup environment
64         env:
65           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
66         run: |
67           # This is the hash of the commit for the PR
68           # when the action is triggered by PR, empty otherwise
69           COMMIT_ID=${{ github.event.pull_request.head.sha }}
70           # This is the hash of the commit when triggered by push
71           # but the hash of refs/pull/<n>/merge, which is different
72           # from the hash of the latest commit in the PR, that's
73           # why we try github.event.pull_request.head.sha first
74           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
75           BUILD_SUFFIX=dev-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
76           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/[ \t\)]+/, "", $2); print $2 }')
77           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
78           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
79       - name: Build SITL
80         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -G Ninja -DVERSION_TYPE=dev .. && ninja
81       - name: Upload artifacts
82         uses: actions/upload-artifact@v4
83         with:
84           name: sitl-${{ env.BUILD_NAME }}-Linux
85           path: ./build_SITL/*_SITL
87   build-SITL-Mac:
88     runs-on: macos-latest
89     steps:
90       - uses: actions/checkout@v4
91       - name: Install dependencies
92         run: |
93           brew install cmake ninja ruby
95       - name: Setup environment
96         env:
97           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
98         run: |
99           # This is the hash of the commit for the PR
100           # when the action is triggered by PR, empty otherwise
101           COMMIT_ID=${{ github.event.pull_request.head.sha }}
102           # This is the hash of the commit when triggered by push
103           # but the hash of refs/pull/<n>/merge, which is different
104           # from the hash of the latest commit in the PR, that's
105           # why we try github.event.pull_request.head.sha first
106           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
107           BUILD_SUFFIX=dev-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
108           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/[ \t\)]+/, "", $2); print $2 }')
109           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
110           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
111       - name: Build SITL
112         run: |
113           mkdir -p build_SITL && cd build_SITL
114           cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" -DVERSION_TYPE=dev -G Ninja ..
115           ninja
117       - name: Upload artifacts
118         uses: actions/upload-artifact@v4
119         with:
120           name: sitl-${{ env.BUILD_NAME }}-MacOS
121           path: ./build_SITL/*_SITL
123   build-SITL-Windows:
124     runs-on: windows-latest
125     defaults:
126       run:
127         shell: C:\tools\cygwin\bin\bash.exe -o igncr '{0}'
128     steps:
129       - uses: actions/checkout@v4
130       - name: Setup Cygwin
131         uses: egor-tensin/setup-cygwin@v4
132         with:
133           packages: cmake ruby ninja gcc-g++
134       - name: Setup environment
135         env:
136           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
137         run: |
138           # This is the hash of the commit for the PR
139           # when the action is triggered by PR, empty otherwise
140           COMMIT_ID=${{ github.event.pull_request.head.sha }}
141           # This is the hash of the commit when triggered by push
142           # but the hash of refs/pull/<n>/merge, which is different
143           # from the hash of the latest commit in the PR, that's
144           # why we try github.event.pull_request.head.sha first
145           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
146           BUILD_SUFFIX=dev-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
147           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/[ \t\)]+/, "", $2); print $2 }')
148           #echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
149           #echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
150           #echo "VERSION_TAG=-$(date '+%Y%m%d')" >> $GITHUB_ENV
151           echo "version=${VERSION}" >> $GITHUB_OUTPUT
152       - name: Build SITL
153         run: mkdir -p build_SITL && cd build_SITL && cmake -DSITL=ON -DWARNINGS_AS_ERRORS=ON -DVERSION_TYPE=dev -G Ninja .. && ninja
154       - name: Upload artifacts
155         uses: actions/upload-artifact@v4
156         with:
157           name: sitl-${{ env.BUILD_NAME }}-WIN
158           path: ./build_SITL/*.exe
161   test:
162     runs-on: ubuntu-latest
163     steps:
164       - uses: actions/checkout@v4
165       - name: Install dependencies
166         run: sudo apt-get update && sudo apt-get -y install ninja-build
167       - name: Run Tests
168         run: mkdir -p build && cd build && cmake -DTOOLCHAIN=none -G Ninja .. && ninja check
170   release:
171     needs: [build, build-SITL-Linux, build-SITL-Mac, build-SITL-Windows, test]
172     runs-on: ubuntu-latest
173     steps:
174       - uses: actions/checkout@v4
175       - name: Get version
176         id: version
177         run: |
178           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/[ \t\)]+/, "", $2); print $2 }')
179           echo "version=${VERSION}" >> $GITHUB_OUTPUT
180       - name: Get current date
181         id: date
182         run: echo "today=$(date '+%Y%m%d')" >> $GITHUB_OUTPUT
183       - name: download artifacts
184         uses: actions/download-artifact@v4
185         with:
186           path: hexes
187           pattern: inav-*
188           merge-multiple: true
189       - name: download sitl linux
190         uses: actions/download-artifact@v4
191         with:
192           path: resources/sitl/linux
193           pattern: sitl-*-Linux
194           merge-multiple: true
195       - name: download sitl windows
196         uses: actions/download-artifact@v4
197         with:
198           path: resources/sitl/windows
199           pattern: sitl-*-WIN
200           merge-multiple: true
201       - name: download sitl mac
202         uses: actions/download-artifact@v4
203         with:
204           path: resources/sitl/macos
205           pattern: sitl-*-MacOS
206           merge-multiple: true
207       - name: Consolidate sitl files
208         run: |
209           zip -r -9 sitl-resources.zip resources/
210       - name: Upload release artifacts
211         uses: softprops/action-gh-release@v2
212         with:
213           name: inav-${{ steps.version.outputs.version }}-dev-${{ steps.date.outputs.today }}-${{ github.run_number }}-${{ github.sha }}
214           tag_name: v${{ steps.version.outputs.version }}-${{ steps.date.outputs.today }}.${{ github.run_number }}
215           # To create release on a different repo, we need a token setup
216           token: ${{ secrets.NIGHTLY_TOKEN }}
217           repository: iNavFlight/inav-nightly
218           prerelease: true
219           draft: false
220           #generate_release_notes: true
221           make_latest: false
222           files: |
223             hexes/*.hex
224             sitl-resources.zip
225           body: |
226             ${{ steps.notes.outputs.notes }}
228             ### Flashing
229             These are nightly builds and configuration settings can be added and removed often. Flashing with Full chip erase is strongly recommended to avoid issues.
230             Firmware related issues should be opened in the iNavflight/inav repository, not in inav-nightly.
232             ### Repository:
233             ${{ github.repository }} ([link](${{ github.event.repository.html_url }}))
235             ### Branch:
236             ${{ github.ref_name }} ([link](${{ github.event.repository.html_url }}/tree/${{ github.ref_name }}))
238             ### Latest changeset:
239             ${{ github.event.head_commit.id }} ([link](${{ github.event.head_commit.url }}))
241             ### Changes:
242             ${{ github.event.head_commit.message }}