|
| 1 | +name: Build Examples |
| 2 | + |
| 3 | +# Triggers the workflow on push or pull request events |
| 4 | +on: [push, pull_request] |
| 5 | + |
| 6 | +concurrency: |
| 7 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 8 | + cancel-in-progress: true |
| 9 | + |
| 10 | +jobs: |
| 11 | + generate_matrix: |
| 12 | + name: Generate build matrices |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: "!contains(github.event.head_commit.message, 'ci skip')" |
| 15 | + outputs: |
| 16 | + arduino_job_matrix: ${{ steps.py_matrix.outputs.arduino_job_matrix }} |
| 17 | + pio_job_matrix: ${{ steps.py_matrix.outputs.pio_job_matrix }} |
| 18 | + |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v3 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + with: |
| 25 | + python-version: '3.x' |
| 26 | + cache: 'pip' |
| 27 | + |
| 28 | + - name: Install python dependencies, including PlatformIO |
| 29 | + run: pip install -r continuous_integration/requirements.txt |
| 30 | + |
| 31 | + - name: Generate Matrices |
| 32 | + id: py_matrix |
| 33 | + run: | |
| 34 | + python continuous_integration/generate_job_matrix.py |
| 35 | +
|
| 36 | + - name: Store generated examples |
| 37 | + uses: actions/upload-artifact@v3 |
| 38 | + with: |
| 39 | + name: generated_examples |
| 40 | + path: | |
| 41 | + continuous_integration_artifacts/ |
| 42 | +
|
| 43 | + build_ex_arduino: |
| 44 | + name: ${{ matrix.job_info.job_name }} |
| 45 | + runs-on: ubuntu-latest |
| 46 | + needs: generate_matrix |
| 47 | + strategy: |
| 48 | + matrix: |
| 49 | + job_info: ${{ fromJSON(needs.generate_matrix.outputs.arduino_job_matrix) }} |
| 50 | + |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v3 |
| 53 | + |
| 54 | + - name: Set environment variable for library installation source |
| 55 | + run: | |
| 56 | + if [[ -z "${GITHUB_HEAD_REF}" ]]; then |
| 57 | + echo "::debug::Push to commit ${GITHUB_SHA}" |
| 58 | + echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_SHA}.zip" >> $GITHUB_ENV |
| 59 | + else |
| 60 | + echo "::debug::Pull Request from the ${GITHUB_HEAD_REF} branch" |
| 61 | + echo "LIBRARY_INSTALL_ZIP=https://github.com/${GITHUB_REPOSITORY}/archive/${GITHUB_HEAD_REF}.zip" >> $GITHUB_ENV |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Unused Step |
| 65 | + run: echo "This is needed to make the step number match with the PlatformIO jobs. =)" |
| 66 | + |
| 67 | + # We use the `arduino/setup-arduino-cli` action to install and |
| 68 | + # configure the Arduino CLI on the system. |
| 69 | + - name: Setup Arduino CLI |
| 70 | + uses: arduino/setup-arduino-cli@v1.1.1 |
| 71 | + |
| 72 | + - name: Restore Arduino platforms and libraries |
| 73 | + uses: actions/cache@v3 |
| 74 | + id: cache_libraries |
| 75 | + with: |
| 76 | + path: | |
| 77 | + home/arduino |
| 78 | + # if nothing in the dependencies.json file has changed, then it will |
| 79 | + # be a "cache hit" and we can restore libraries from cache and not |
| 80 | + # download them. If it has changed we have to re-download. |
| 81 | + key: ${{ hashFiles('./continuous_integration/dependencies.json','continuous_integration/install-deps-arduino-cli.sh') }} |
| 82 | + |
| 83 | + # Install cores and library dependencies for the Arduino CLI, iff no cache |
| 84 | + - name: Install the Arduino libraries |
| 85 | + if: steps.cache_libraries.outputs.cache-hit != 'true' |
| 86 | + run: | |
| 87 | + chmod +x continuous_integration/install-deps-arduino-cli.sh |
| 88 | + sh continuous_integration/install-deps-arduino-cli.sh |
| 89 | +
|
| 90 | + # Install ModularSensors for the Arduino CLI |
| 91 | + - name: Install the testing version of Modular Sensors for the Arduino CLI |
| 92 | + run: | |
| 93 | + chmod +x continuous_integration/install-test-version-arduino-cli.sh |
| 94 | + sh continuous_integration/install-test-version-arduino-cli.sh |
| 95 | +
|
| 96 | + - name: Download the prepared examples |
| 97 | + uses: actions/download-artifact@v3 |
| 98 | + with: |
| 99 | + name: generated_examples |
| 100 | + path: | |
| 101 | + continuous_integration_artifacts/ |
| 102 | +
|
| 103 | + - name: Include problem matcher |
| 104 | + uses: ammaraskar/gcc-problem-matcher@master |
| 105 | + |
| 106 | + # Run the script to compile the examples |
| 107 | + - name: Compile |
| 108 | + env: |
| 109 | + ACTION_RUN_ID: ${{ github.run_id }} |
| 110 | + run: | |
| 111 | + chmod +x ${{ matrix.job_info.script }} |
| 112 | + bash ${{ matrix.job_info.script }} |
| 113 | +
|
| 114 | + # NOTE: Don't uninstall for PlatformIO because the library manager will clean up the |
| 115 | + # dependencies leaving nothing for the cache |
| 116 | + # pio pkg uninstall --library -g EnviroDIY_ModularSensors |
| 117 | + - name: Uninstall testing version of Modular Sensors before caching |
| 118 | + run: | |
| 119 | + arduino-cli --config-file continuous_integration/arduino_cli.yaml lib uninstall ModularSensors |
| 120 | +
|
| 121 | + build_pio: |
| 122 | + name: ${{ matrix.job_info.job_name }} |
| 123 | + runs-on: ubuntu-latest |
| 124 | + needs: generate_matrix |
| 125 | + strategy: |
| 126 | + matrix: |
| 127 | + job_info: ${{ fromJSON(needs.generate_matrix.outputs.pio_job_matrix) }} |
| 128 | + |
| 129 | + steps: |
| 130 | + - uses: actions/checkout@v3 |
| 131 | + |
| 132 | + - name: Set environment variable for library installation source |
| 133 | + run: | |
| 134 | + if [[ -z "${GITHUB_HEAD_REF}" ]]; then |
| 135 | + echo "::debug::Push to commit ${GITHUB_SHA}" |
| 136 | + echo "LIBRARY_INSTALL_SOURCE=https://github.com/${GITHUB_REPOSITORY}.git#${GITHUB_SHA}" >> $GITHUB_ENV |
| 137 | + else |
| 138 | + echo "::debug::Pull Request from the ${GITHUB_HEAD_REF} branch" |
| 139 | + echo "LIBRARY_INSTALL_SOURCE=https://github.com/${GITHUB_REPOSITORY}.git#${GITHUB_HEAD_REF}" >> $GITHUB_ENV |
| 140 | + fi |
| 141 | +
|
| 142 | + - name: Set up Python |
| 143 | + uses: actions/setup-python@v4 |
| 144 | + with: |
| 145 | + python-version: '3.x' |
| 146 | + cache: 'pip' |
| 147 | + |
| 148 | + - name: Install python dependencies, including PlatformIO |
| 149 | + run: pip install -r continuous_integration/requirements.txt |
| 150 | + |
| 151 | + - name: Restore PlatformIO and Arduino platforms and libraries |
| 152 | + uses: actions/cache@v3 |
| 153 | + id: cache_libraries |
| 154 | + with: |
| 155 | + path: | |
| 156 | + ~/.platformio |
| 157 | + # if nothing in the dependencies.json file has changed, then it will |
| 158 | + # be a "cache hit" and we can restore libraries from cache and not |
| 159 | + # download them. If it has changed we have to re-download. |
| 160 | + key: ${{ hashFiles('./continuous_integration/dependencies.json','continuous_integration/install-deps-platformio.sh') }} |
| 161 | + |
| 162 | + # Install the dependencies for PlatformIO |
| 163 | + - name: Install the PlatformIO dependencies at global level |
| 164 | + if: steps.cache_libraries.outputs.cache-hit != 'true' |
| 165 | + run: | |
| 166 | + chmod +x continuous_integration/install-deps-platformio.sh |
| 167 | + sh continuous_integration/install-deps-platformio.sh |
| 168 | + cp -a /home/runner/.platformio/lib/. $GITHUB_WORKSPACE/lib/ |
| 169 | +
|
| 170 | + # Install ModularSensors at the Global level for PlatformIO |
| 171 | + # Force install to get the right version |
| 172 | + - name: Install the testing version of Modular Sensors for PlatformIO |
| 173 | + run: | |
| 174 | + pio pkg install -g --library ${{ env.LIBRARY_INSTALL_SOURCE }} |
| 175 | +
|
| 176 | + - name: Download the prepared examples |
| 177 | + uses: actions/download-artifact@v3 |
| 178 | + with: |
| 179 | + name: generated_examples |
| 180 | + path: | |
| 181 | + continuous_integration_artifacts/ |
| 182 | +
|
| 183 | + - name: Include problem matcher |
| 184 | + uses: ammaraskar/gcc-problem-matcher@master |
| 185 | + |
| 186 | + # Run the script to compile the examples |
| 187 | + - name: Compile |
| 188 | + env: |
| 189 | + ACTION_RUN_ID: ${{ github.run_id }} |
| 190 | + run: | |
| 191 | + chmod +x ${{ matrix.job_info.script }} |
| 192 | + bash ${{ matrix.job_info.script }} |
0 commit comments