-
Notifications
You must be signed in to change notification settings - Fork 0
230 lines (207 loc) · 8.61 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#
# Copyright (C) 2019-2021 OpenBikeSensor Contributors
# Contact: https://openbikesensor.org
#
# This file is part of the OpenBikeSensor firmware.
#
# The OpenBikeSensor firmware is free software: you can redistribute it
# and/or modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
#
# OpenBikeSensor firmware is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with the OpenBikeSensor firmware. If not, see
# <http://www.gnu.org/licenses/>.
#
name: OpenBikeSensor - CI
on:
# Trigger when pushing in main or pull requests, and when creating
# a pull request.
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache pip
uses: actions/cache@v3.3.1
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache PlatformIO
uses: actions/cache@v3.3.1
with:
path: ~/.platformio
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Set up Python
uses: actions/setup-python@v4.5.0
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Prepare source
run: |
mkdir bin
echo GITHUB Ref: ${{ github.ref }}
VERSION_STRING=`grep "const char \*VERSION =" src/main.c`
MAJOR=`echo ${VERSION_STRING} | cut -f2 -d\"`
if [ "${{ github.ref }}" = "refs/heads/main" ]
then
PATCH=${GITHUB_RUN_NUMBER}
SEPARATOR=.
PREPARE_RELEASE=true
else
PATCH=RC${GITHUB_RUN_NUMBER}
SEPARATOR=-
PREPARE_RELEASE=false
fi
VERSION=${MAJOR}${SEPARATOR}${PATCH}
echo "OBS_PREPARE_RELEASE=${PREPARE_RELEASE}" >> $GITHUB_ENV
echo "OBS_FLASH_VERSION=${VERSION}" >> $GITHUB_ENV
echo "PROJECT_VER=${VERSION}" >> $GITHUB_ENV
echo "OBS_MAJOR_VERSION=${MAJOR}" >> $GITHUB_ENV
echo $VERSION > VERSION
echo $VERSION > version.txt
echo Building OBS Version: $VERSION
sed -i 's|-DBUILD_NUMBER=\\"-dev\\"|-DPROJECT_VER=${VERSION} -DBUILD_NUMBER=\\"'${SEPARATOR}${PATCH}'\\"|' platformio.ini
echo "SONAR_SCANNER_VERSION=4.6.2.2472" >> $GITHUB_ENV
- name: Cache SonarCloud packages
id: cache-sonar
uses: actions/cache@v3.3.1
with:
path: |
~/.sonar/cache
sonarqube
key: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}-ng
restore-keys: ${{ runner.os }}-sonar-${{ env.SONAR_SCANNER_VERSION }}-ng
- name: Install SonarQube dependencies
if: steps.cache-sonar.outputs.cache-hit != 'true'
run: |
mkdir -p sonarqube
cd sonarqube
wget --no-verbose https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip -qq build-wrapper-linux-x86.zip
rm build-wrapper-linux-x86.zip
wget --no-verbose https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
unzip -qq sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
rm sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
cd ..
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install -qq -y zip
- name: Build flashsd
run: |
mkdir sonarqube-out
./sonarqube/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir sonarqube-out \
platformio run --disable-auto-clean
# platformio ci -v --build-dir="./bin" --keep-build-dir --project-conf=platformio.ini ./src/
- name: Package firmware
run: |
cp .pio/build/esp32dev/firmware.bin 0x10000.bin
cp .pio/build/esp32dev/firmware.bin flash.bin
wget --no-verbose -O COPYRIGHT-ESP.html https://docs.espressif.com/projects/esp-idf/en/latest/esp32/COPYRIGHT.html
zip --junk-paths obs-flash-${{ env.OBS_FLASH_VERSION }}.zip \
flash.bin \
COPYRIGHT-ESP.html \
LICENSE
- name: Analyze with SonarCloud
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Hack - point sonarqube to the real sources not the copy of it
# See also https://community.sonarsource.com/t/scanning-platformio-c-embeded-projects/35141/2
# sed -i 's|OpenBikeSensorFlash/bin|OpenBikeSensorFlash|g' \
# sonarqube-out/build-wrapper-dump.json
# looks like pio copys our source from the main folder to a src folder
# sed -i 's|"src/|"main/|g' \
# sonarqube-out/build-wrapper-dump.json
# sed -i 's|\.pio/|bin/.pio/|g' \
# sonarqube-out/build-wrapper-dump.json
# replace gcc with our script that reports the fake arch "le32-unknown-nacl"
sed -i "s|/github/home/.platformio/packages/toolchain-xtensa32/bin/xtensa-esp32-elf-g..|`pwd`/.github/fake-cc|g" \
sonarqube-out/build-wrapper-dump.json
./sonarqube/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin/sonar-scanner \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=openbikesensor \
-Dsonar.projectKey=openbikesensor_OpenBikeSensorFlash \
-Dsonar.coverage.exclusions=**/* \
-Dsonar.sources=src \
-Dsonar.sourceEncoding=UTF-8 \
-Dsonar.cfamily.cache.enabled=false \
-Dsonar.cfamily.threads=1 \
-Dsonar.cfamily.build-wrapper-output=sonarqube-out \
-Dsonar.projectVersion=${{ env.OBS_MAJOR_VERSION }} || echo Result: $?
- name: Upload Build Asset
uses: actions/upload-artifact@v3
with:
name: obs-flash-${{ env.OBS_FLASH_VERSION }}
path: |
flash.bin
sonarqube-out/build-wrapper-dump.json
COPYRIGHT-ESP.html
LICENSE
if-no-files-found: error
- name: Generate changelog
id: changelog
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }}
uses: metcalfc/changelog-generator@v4.1.0
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Create Release
id: create_release
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }}
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.OBS_FLASH_VERSION }}
release_name: ${{ env.OBS_FLASH_VERSION }}
body: |
![GitHub downloads](https://img.shields.io/github/downloads-pre/openbikesensor/OpenBikeSensorFlash/${{ env.OBS_FLASH_VERSION }}/total) ![GitHub commits since release](https://img.shields.io/github/commits-since/openbikesensor/OpenBikeSensorFlash/${{ github.sha }}?label=commits%20since%20${{ env.OBS_FLASH_VERSION }})
Version ${{ env.OBS_FLASH_VERSION }} based on ${{ github.ref }} ${{ github.sha }}
${{ steps.changelog.outputs.changelog }}
## :tada: Major features and improvements
## :rocket: New features and improvements
## :bug: Bug Fixes
## :ghost: Maintenance
## :package: Dependency updates
## :construction_worker: Changes for developers / internal
draft: true
prerelease: true
- name: Upload Release Asset
id: upload-release-asset
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./obs-flash-${{ env.OBS_FLASH_VERSION }}.zip
asset_name: obs-flash-${{ env.OBS_FLASH_VERSION }}.zip
asset_content_type: application/zip
- name: Upload Release Asset flash bin
id: upload-release-asset-flash-bin
if: ${{ env.OBS_PREPARE_RELEASE == 'true' }}
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: flash.bin
asset_name: flash.bin
asset_content_type: application/x-esp32