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