forked from EnviroDIY/ModularSensors
-
Notifications
You must be signed in to change notification settings - Fork 1
240 lines (203 loc) · 9.35 KB
/
build_examples.yaml
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
231
232
233
234
235
236
237
238
239
240
name: Build Examples
# Triggers the workflow on push or pull request events
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
generate_matrix:
name: Generate build matrices
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
outputs:
arduino_job_matrix: ${{ steps.py_matrix.outputs.arduino_job_matrix }}
pio_job_matrix: ${{ steps.py_matrix.outputs.pio_job_matrix }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip'
- name: Install python dependencies, including PlatformIO
run: pip install -r continuous_integration/requirements.txt
- name: Generate Matrices
id: py_matrix
run: |
python continuous_integration/generate_job_matrix.py
- name: Store generated examples
uses: actions/upload-artifact@v3
with:
name: generated_examples
path: |
continuous_integration_artifacts/
print_job_matrix:
name: print_job_matrix
runs-on: ubuntu-latest
needs: generate_matrix
steps:
- name: Check the generated matrix output
run: |
echo "Arduino job matrix:"
echo "${{ needs.generate_matrix.outputs.arduino_job_matrix }}"
echo
echo "PlatformIO job matrix"
echo "${{ needs.generate_matrix.outputs.pio_job_matrix }}"
determine_library_source:
name: determine_library_source
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
outputs:
library_install_zip: ${{ steps.store_vars.outputs.library_install_zip }}
library_install_git: ${{ steps.store_vars.outputs.library_install_git }}
steps:
- uses: actions/checkout@v3
- name: Set environment variables for pushes to any branch in EnviroDIY/ModularSensors
if: github.event_name == 'push'
run: |
echo "Push to commit ${GITHUB_SHA}"
echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.zip" >> $GITHUB_ENV
echo "LIBRARY_INSTALL_GIT=https://github.com/${GITHUB_REPOSITORY}.git#${GITHUB_SHA}" >> $GITHUB_ENV
- name: Set environment variable for PR's from any branch in EnviroDIY/ModularSensors
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.name == github.repository
run: |
echo "Pull Request from the ${GITHUB_HEAD_REF} branch"
echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_HEAD_REF}.zip" >> $GITHUB_ENV
echo "LIBRARY_INSTALL_GIT=https://github.com/${GITHUB_REPOSITORY}.git#${GITHUB_HEAD_REF}" >> $GITHUB_ENV
- name: Set environment variable for PR's from any branch in EnviroDIY/ModularSensors
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.name != github.repository
run: |
echo "Pull Request from the fork ${{ github.event.pull_request.head.repo.full_name }} at ${{ github.event.pull_request.head.ref }}"
echo "LIBRARY_INSTALL_ZIP=https://github.com/${{ github.event.pull_request.head.repo.full_name }}/archive/${{ github.event.pull_request.head.ref }}.zip" >> $GITHUB_ENV
echo "LIBRARY_INSTALL_GIT=https://github.com${{ github.event.pull_request.head.repo.full_name }}.git#${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
- name: store enviroment variables as output
id: store_vars
run: |
echo "library_install_zip=${{ env.LIBRARY_INSTALL_ZIP }}" >> $GITHUB_OUTPUT
echo "library_install_git=${{ env.LIBRARY_INSTALL_GIT }}" >> $GITHUB_OUTPUT
print_library_source:
name: print_library_source
runs-on: ubuntu-latest
needs: determine_library_source
steps:
- name: Check the library installation source
run: |
echo "Link to zip for Arduino CLI testing install:"
echo "${{ needs.determine_library_source.outputs.library_install_zip }}"
echo
echo "Git reference for PlatformIO testing install"
echo "${{ needs.determine_library_source.outputs.library_install_git }}"
build_ex_arduino:
name: ${{ matrix.job_info.job_name }}
runs-on: ubuntu-latest
needs: [generate_matrix, determine_library_source]
env:
LIBRARY_INSTALL_ZIP: ${{ needs.determine_library_source.outputs.library_install_zip }}
strategy:
matrix:
job_info: ${{ fromJSON(needs.generate_matrix.outputs.arduino_job_matrix) }}
steps:
- uses: actions/checkout@v3
- name: Unused Step
run: echo "This is needed to make the step number match with the PlatformIO jobs. =)"
# We use the `arduino/setup-arduino-cli` action to install and
# configure the Arduino CLI on the system.
- name: Setup Arduino CLI
uses: arduino/setup-arduino-cli@v1.1.1
- name: Restore Arduino platforms and libraries
uses: actions/cache@v3
id: cache_libraries
with:
path: |
home/arduino
# if nothing in the dependencies.json file has changed, then it will
# be a "cache hit" and we can restore libraries from cache and not
# download them. If it has changed we have to re-download.
key: ${{ hashFiles('./continuous_integration/dependencies.json','continuous_integration/install-deps-arduino-cli.sh') }}
# Install cores and library dependencies for the Arduino CLI, iff no cache
- name: Install the Arduino libraries
if: steps.cache_libraries.outputs.cache-hit != 'true'
run: |
chmod +x continuous_integration/install-deps-arduino-cli.sh
sh continuous_integration/install-deps-arduino-cli.sh
# Install ModularSensors for the Arduino CLI
- name: Install the testing version of Modular Sensors for the Arduino CLI
run: |
chmod +x continuous_integration/install-test-version-arduino-cli.sh
sh continuous_integration/install-test-version-arduino-cli.sh
- name: Download the prepared examples
uses: actions/download-artifact@v3
with:
name: generated_examples
path: |
continuous_integration_artifacts/
- name: Include problem matcher
uses: ammaraskar/gcc-problem-matcher@master
# Run the script to compile the examples
- name: Compile
env:
ACTION_RUN_ID: ${{ github.run_id }}
run: |
chmod +x ${{ matrix.job_info.script }}
bash ${{ matrix.job_info.script }}
# NOTE: Don't uninstall for PlatformIO because the library manager will clean up the
# dependencies leaving nothing for the cache
# pio pkg uninstall --library -g EnviroDIY_ModularSensors
- name: Uninstall testing version of Modular Sensors before caching
run: |
arduino-cli --config-file continuous_integration/arduino_cli.yaml lib uninstall ModularSensors
build_pio:
name: ${{ matrix.job_info.job_name }}
runs-on: ubuntu-latest
needs: [generate_matrix, determine_library_source]
env:
LIBRARY_INSTALL_GIT: ${{ needs.determine_library_source.outputs.library_install_zip }}
strategy:
matrix:
job_info: ${{ fromJSON(needs.generate_matrix.outputs.pio_job_matrix) }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
cache: 'pip'
- name: Install python dependencies, including PlatformIO
run: pip install -r continuous_integration/requirements.txt
- name: Restore PlatformIO and Arduino platforms and libraries
uses: actions/cache@v3
id: cache_libraries
with:
path: |
~/.platformio
# if nothing in the dependencies.json file has changed, then it will
# be a "cache hit" and we can restore libraries from cache and not
# download them. If it has changed we have to re-download.
key: ${{ hashFiles('./continuous_integration/dependencies.json','continuous_integration/install-deps-platformio.sh') }}
# Install the dependencies for PlatformIO
- name: Install the PlatformIO dependencies at global level
if: steps.cache_libraries.outputs.cache-hit != 'true'
run: |
chmod +x continuous_integration/install-deps-platformio.sh
sh continuous_integration/install-deps-platformio.sh
cp -a /home/runner/.platformio/lib/. $GITHUB_WORKSPACE/lib/
# Install ModularSensors at the Global level for PlatformIO
# Force install to get the right version
- name: Install the testing version of Modular Sensors for PlatformIO
run: |
pio pkg install -g --library ${{ env.LIBRARY_INSTALL_GIT }}
- name: Download the prepared examples
uses: actions/download-artifact@v3
with:
name: generated_examples
path: |
continuous_integration_artifacts/
- name: Include problem matcher
uses: ammaraskar/gcc-problem-matcher@master
# Run the script to compile the examples
- name: Compile
env:
ACTION_RUN_ID: ${{ github.run_id }}
run: |
chmod +x ${{ matrix.job_info.script }}
bash ${{ matrix.job_info.script }}