Merge pull request #8911 from iNavFlight/dzikuvx-speedybeef405wing
[inav.git] / .github / workflows / ci.yml
blobdf2a2cc5800a1d385f55b4bf3d9f65b5c4621f9b
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: pull_request
7 jobs:
8   build:
9     runs-on: ubuntu-latest
10     strategy:
11         matrix:
12           id: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
14     steps:
15       - uses: actions/checkout@v3
16       - name: Install dependencies
17         run: sudo apt-get update && sudo apt-get -y install ninja-build
18       - name: Setup environment
19         env:
20           ACTIONS_ALLOW_UNSECURE_COMMANDS: true
21         run: |
22           # This is the hash of the commit for the PR
23           # when the action is triggered by PR, empty otherwise
24           COMMIT_ID=${{ github.event.pull_request.head.sha }}
25           # This is the hash of the commit when triggered by push
26           # but the hash of refs/pull/<n>/merge, which is different
27           # from the hash of the latest commit in the PR, that's
28           # why we try github.event.pull_request.head.sha first
29           COMMIT_ID=${COMMIT_ID:-${{ github.sha }}}
30           BUILD_SUFFIX=ci-$(date '+%Y%m%d')-$(git rev-parse --short ${COMMIT_ID})
31           VERSION=$(grep project CMakeLists.txt|awk -F VERSION '{ gsub(/^[ \t]+|[ \t\)]+$/, "", $2); print $2 }')
32           echo "BUILD_SUFFIX=${BUILD_SUFFIX}" >> $GITHUB_ENV
33           echo "BUILD_NAME=inav-${VERSION}-${BUILD_SUFFIX}" >> $GITHUB_ENV
34       - uses: actions/cache@v1
35         with:
36           path: downloads
37           key: ${{ runner.os }}-downloads-${{ hashFiles('CMakeLists.txt') }}-${{ hashFiles('**/cmake/*')}}
38       - name: Build targets (${{ matrix.id }})
39         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 }} -G Ninja .. && ninja ci
40       - name: Upload artifacts
41         uses: actions/upload-artifact@v2-preview
42         with:
43           name: ${{ env.BUILD_NAME }}.zip
44           path: ./build/*.hex
46   test:
47     needs: [build]
48     runs-on: ubuntu-latest
49     steps:
50       - uses: actions/checkout@v3
51       - name: Install dependencies
52         run: sudo apt-get update && sudo apt-get -y install ninja-build
53       - name: Run Tests
54         run: mkdir -p build && cd build && cmake -DTOOLCHAIN=none -G Ninja .. && ninja check