|
| 1 | +name: Build device config |
| 2 | + |
| 3 | +on: [workflow_call] |
| 4 | + |
| 5 | +jobs: |
| 6 | + metadata: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + name: Parse config metadata |
| 9 | + outputs: |
| 10 | + meta_json: ${{ steps.parse_yaml.outputs.metadata }} |
| 11 | + build_matrix: ${{ steps.parse_yaml.outputs.metadata.build }} |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Install yaml2json |
| 17 | + run: python3 -m pip install remarshal |
| 18 | + |
| 19 | + - name: Read metadata from yaml file |
| 20 | + id: parse_yaml |
| 21 | + run: | |
| 22 | + echo "metadata=$(yaml2json 'meta.yaml')" >> "$GITHUB_OUTPUT" |
| 23 | +
|
| 24 | + build: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: write |
| 28 | + needs: metadata |
| 29 | + env: |
| 30 | + HAYBOX_REPO: ${{ fromJson(needs.metadata.outputs.meta_json).repo }} |
| 31 | + HAYBOX_REVISION: ${{ fromJson(needs.metadata.outputs.meta_json).revision }} |
| 32 | + DEVICE_CONFIG_REVISION: ${{ github.ref_type == 'tag' && github.ref_name || github.sha }} |
| 33 | + PIO_ENV: ${{ matrix.env }} |
| 34 | + BIN_EXT: ${{ matrix.bin_ext }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: ${{ fromJson(needs.metadata.outputs.meta_json).build }} |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Check out specific HayBox revision |
| 42 | + run: | |
| 43 | + git clone "https://github.com/$HAYBOX_REPO" . |
| 44 | + git checkout "$HAYBOX_REVISION" |
| 45 | +
|
| 46 | + - name: Check out config repo |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + path: config/device |
| 50 | + |
| 51 | + - name: Set up Python |
| 52 | + uses: actions/setup-python@v5 |
| 53 | + with: |
| 54 | + python-version: '3.10' |
| 55 | + |
| 56 | + - name: Install PlatformIO |
| 57 | + run: | |
| 58 | + python -m pip install --upgrade pip |
| 59 | + pip install --upgrade platformio |
| 60 | +
|
| 61 | + - name: Set artifact filename environment variable |
| 62 | + run: | |
| 63 | + echo "ARTIFACT_NAME=HayBox-${HAYBOX_REVISION}-${PIO_ENV}-${DEVICE_CONFIG_REVISION}.${BIN_EXT}" >> "$GITHUB_ENV" |
| 64 | +
|
| 65 | + - name: Set artifact path environment variable |
| 66 | + run: | |
| 67 | + echo "ARTIFACT_PATH=${PIO_ENV}/${ARTIFACT_NAME}" >> "$GITHUB_ENV" |
| 68 | +
|
| 69 | + - name: Build ${{ matrix.env }} env |
| 70 | + run: | |
| 71 | + pio run -e "$PIO_ENV" |
| 72 | + mkdir -p "$PIO_ENV" |
| 73 | +
|
| 74 | + cp ".pio/build/${PIO_ENV}/firmware.${BIN_EXT}" "$ARTIFACT_PATH" |
| 75 | +
|
| 76 | + - name: Publish ${{ matrix.env }} artifacts |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: ${{ env.ARTIFACT_NAME }} |
| 80 | + path: ${{ env.ARTIFACT_PATH }} |
| 81 | + |
| 82 | + - name: Upload binaries to release |
| 83 | + uses: softprops/action-gh-release@v1 |
| 84 | + if: github.ref_type == 'tag' |
| 85 | + with: |
| 86 | + files: ${{ env.ARTIFACT_PATH }} |
0 commit comments