name: NukiHub on: push: branches: ["*"] tags: ["*"] pull_request: branches: ["*"] tags: ["*"] workflow_dispatch: permissions: contents: write jobs: build: name: Build ${{ matrix.board }} (${{ matrix.build }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: board: [esp32dev, esp32-s3, esp32-c3, esp32solo1] build: [release, debug] env: BOARD: ${{ matrix.board }} VARIANT: ${{ matrix.name || matrix.board }} BUILD: ${{ matrix.build }} steps: - name: Fix variant name run: | # remove dash character export VARIANT=${VARIANT//-/} if [ "$VARIANT" = "esp32dev" ]; then VARIANT="esp32" fi echo "VARIANT=${VARIANT}" | tee -a ${GITHUB_ENV} - uses: actions/checkout@v4 with: submodules: recursive - uses: actions/cache@v4 with: path: | ~/.cache/pip ~/.platformio/.cache key: ${{ runner.os }}-pio - uses: actions/setup-python@v5 with: python-version: '3.9' - name: Install PlatformIO Core run: pip install --upgrade platformio - name: Install ESPTool run: pip install --upgrade esptool - name: Add version info env: Version: ${{ github.run_id }}.${{ github.run_number }}.${{ github.run_attempt }} run: | sed -i "s/unknownbuildnr/$Version (${BUILD})/g" src/Config.h - name: Build ${{ matrix.build }} PlatformIO Project ${{ matrix.board }} run: | if [ "$BUILD" = "debug" ]; then BOARD="${BOARD}_dbg" fi echo "::group::Building with PlatformIO" pio run --environment ${BOARD} echo "::endgroup::" mkdir -p ${BUILD}/${VARIANT} cp -v .pio/build/${BOARD}/firmware.bin ${BUILD}/${VARIANT}/nuki_hub_${VARIANT}.bin cp -v .pio/build/${BOARD}/partitions.bin ${BUILD}/${VARIANT}/nuki_hub.partitions.bin cp -v .pio/build/${BOARD}/bootloader.bin ${BUILD}/${VARIANT}/bootloader.bin if [ "$BUILD" = "debug" ]; then cp -v .pio/build/${BOARD}/firmware.elf ${BUILD}/${VARIANT}/nuki_hub_${VARIANT}.elf fi cp -v bin/boot_app0.bin ${BUILD}/${VARIANT}/boot_app0.bin cp -v how-to-flash.txt ${BUILD}/${VARIANT}/how-to-flash.txt - name: Pack webflash image if: ${{ matrix.build == 'release' && matrix.board != 'esp32solo1' }} env: POSITION_BOOTLOADER: "0x0" POSITION_PARTITIONS: "0x8000" POSITION_BOOT_APP: "0xe000" POSITION_APP: "0x10000" CHIP: ${{ env.VARIANT }} FILES: ${{ format('{0}/{1}', env.BUILD, env.VARIANT) }} run: | if [ "$BOARD" = "esp32dev" ]; then POSITION_BOOTLOADER="0x1000" fi esptool.py \ --chip ${CHIP} \ merge_bin -o ${FILES}/webflash_nuki_hub_${VARIANT}.bin \ --flash_mode dio \ --flash_freq keep \ --flash_size keep \ ${POSITION_BOOT_APP} bin/boot_app0.bin \ ${POSITION_BOOTLOADER} ${FILES}/bootloader.bin \ ${POSITION_APP} ${FILES}/nuki_hub_${VARIANT}.bin \ ${POSITION_PARTITIONS} ${FILES}/nuki_hub.partitions.bin - name: Add flash script env: DOC: how-to-flash.txt FILES: ${{ format('{0}/{1}', env.BUILD, env.VARIANT) }} run: | BOARD=`echo $BOARD | tr '[:lower:]' '[:upper:]'` # fix for docs if [ "$BOARD" = "ESP32SOLO1" ]; then BOARD="ESP32Solo1" elif [ "$BOARD" = "ESP32DEV" ]; then BOARD="ESP32" fi # look for documentation on flash and copy the command command=`sed -n '/^Howto flash (esptool)$/,$p' ${DOC} | sed -n '/^## '"${BOARD}"'$/,\${ n; n; p; }' | head -n1` if [ -z "$command" ]; then echo "::error::Command not found in document ${DOC} for board ${BOARD}" exit 1 fi echo -n "Command: " echo "$command" | tee ${FILES}/flash.sh chmod a+x ${FILES}/flash.sh - name: Upload Artifact ${{ matrix.board }}-${{ matrix.build }} uses: actions/upload-artifact@v4 with: name: ${{ format('{0}-{1}-assets', env.VARIANT, matrix.build) }} path: ${{ matrix.build }}/${{ env.VARIANT }} release: name: Release new version needs: build runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags') steps: - name: Get the version id: get_version run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT - name: Git Checkout uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: Download release assets uses: actions/download-artifact@v4 with: path: release pattern: '*-release-assets' - name: Download debug assets uses: actions/download-artifact@v4 with: path: debug pattern: '*-debug-assets' - name: Build zip archives id: zip env: VERSION: ${{ steps.get_version.outputs.VERSION }} run: | NUKI="NukiHub-${VERSION}" ARTIFACTS="" for FOLDER in release/*; do MODEL=`echo "${FOLDER}" | cut -d '/' -f2 | cut -d '-' -f1 | tr '[:lower:]' '[:upper:]'` ZIPFILE="${NUKI}-${MODEL}.zip" echo "${FOLDER} -- ${ZIPFILE}" cd $FOLDER zip -9r ../../${ZIPFILE} * -x "webflash_nuki_hub_*.bin" ARTIFACTS="${ARTIFACTS}${ZIPFILE}," cd ../.. done for FOLDER in debug/*; do MODEL=`echo "${FOLDER}" | cut -d '/' -f2 | cut -d '-' -f1 | tr '[:lower:]' '[:upper:]'` ZIPFILE="${NUKI}-${MODEL}-DEBUG.zip" echo "${FOLDER} -- ${ZIPFILE}" cd $FOLDER zip -9r ../../${ZIPFILE} * ARTIFACTS="${ARTIFACTS}${ZIPFILE}," cd ../.. done # remove last character ARTIFACTS="${ARTIFACTS%?}" echo "artifacts=${ARTIFACTS}" | tee -a ${GITHUB_OUTPUT} - name: Create Release id: create_release uses: ncipollo/release-action@v1 with: prerelease: false allowUpdates: true updateOnlyUnreleased: true draft: true name: "Nuki Hub ${{ steps.get_version.outputs.VERSION }}" artifacts: ${{ steps.zip.outputs.artifacts }} artifactContentType: application/zip - name: Copy binaries to ota and webflash run: | cp -vf release/*/nuki_hub_*.bin ota/ cp -vf release/*/webflash_nuki_hub_*.bin webflash/ rm -rf release rm -rf debug rm -rf NukiHub-*.zip - name: Commit binaries to master uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: "Update binaries for version ${{ steps.get_version.outputs.VERSION }}" file_pattern: 'ota/*.bin webflash/*.bin' branch: master