| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- name: Build
- on:
- push:
- branches:
- - main
- tags:
- - '[0-9]*.[0-9]*.[0-9]*'
- # Build every PR head commit and publish UF2 artifacts for reviewers.
- pull_request:
- concurrency:
- group: build-${{ github.event.pull_request.number || github.ref }}
- cancel-in-progress: true
- permissions:
- contents: read
- jobs:
- compile:
- runs-on: ubuntu-latest
- steps:
- - name: Check out repository
- uses: actions/checkout@v4
- with:
- fetch-depth: 0
- ref: ${{ github.event.pull_request.head.sha || github.sha }}
- - name: Set up Arduino CLI
- uses: arduino/setup-arduino-cli@v2
- - name: Set up Python
- uses: actions/setup-python@v5
- with:
- python-version: '3.x'
- - name: Install adafruit-nrfutil
- # The Adafruit nRF52 build recipe shells out to adafruit-nrfutil to
- # package the DFU .zip; it is not bundled with the core on the runner.
- run: pip install adafruit-nrfutil
- - name: Install Adafruit nRF52 core
- run: |
- arduino-cli config init --overwrite
- arduino-cli config set board_manager.additional_urls https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
- arduino-cli core update-index
- arduino-cli core install adafruit:nrf52
- - name: Resolve build version
- id: build_version
- env:
- PR_NUMBER: ${{ github.event.pull_request.number || '' }}
- HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
- run: |
- set -eu
- SEMVER_RE='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
- BASE_VERSION="$(
- git tag --list \
- | grep -E "$SEMVER_RE" \
- | sort -V \
- | tail -n1 || true
- )"
- if [ -z "$BASE_VERSION" ]; then
- BASE_VERSION="0.9.1"
- fi
- SHORT_SHA="$(git rev-parse --short=8 "${HEAD_SHA}")"
- PR_NUMBER_SAFE="${PR_NUMBER:-0}"
- if [ "${{ github.event_name }}" = "pull_request" ]; then
- VERSION="${BASE_VERSION}-pr${PR_NUMBER_SAFE}+${SHORT_SHA}"
- ARTIFACT_VERSION="${BASE_VERSION}-pr${PR_NUMBER_SAFE}-${SHORT_SHA}"
- else
- VERSION="${BASE_VERSION}"
- ARTIFACT_VERSION="${BASE_VERSION}-${SHORT_SHA}"
- fi
- echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
- echo "pr_number=$PR_NUMBER_SAFE" >> "$GITHUB_OUTPUT"
- echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
- echo "artifact_version=$ARTIFACT_VERSION" >> "$GITHUB_OUTPUT"
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- - name: Generate version header
- env:
- OPK_BUILD_VERSION: ${{ steps.build_version.outputs.version }}
- run: ./gen_version.sh
- - name: Compile OpenPuck
- run: |
- mkdir -p build/openpuck build/cache/openpuck
- arduino-cli compile \
- -b adafruit:nrf52:feather52840 \
- --clean \
- --build-path build/cache/openpuck \
- --output-dir build/openpuck \
- --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DCFG_TUD_TASK_QUEUE_SZ=64 -DCFG_TUD_VENDOR_TX_BUFSIZE=256" \
- OpenPuck
- - name: Generate UF2 (OpenPuck)
- # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in
- # platform.txt, so arduino-cli only emits .hex/.zip. Convert the .hex to
- # a drag-and-drop .uf2 ourselves.
- run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
- - name: Compile ReversePuckFirmware
- run: |
- mkdir -p build/reversepuck build/cache/reversepuck
- arduino-cli compile \
- -b adafruit:nrf52:feather52840 \
- --clean \
- --build-path build/cache/reversepuck \
- --output-dir build/reversepuck \
- --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb}" \
- ReversePuckFirmware
- - name: Generate UF2 (ReversePuckFirmware)
- run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2
- - name: List build outputs
- run: |
- find build/openpuck build/reversepuck -maxdepth 1 -type f -print | sort
- - name: Stage build artifacts
- env:
- ARTIFACT_VERSION: ${{ steps.build_version.outputs.artifact_version }}
- run: |
- set -eu
- mkdir -p build/artifacts
- for f in build/openpuck/*.{uf2,bin,hex,elf,map,zip}; do
- [ -f "$f" ] || continue
- ext="${f##*.}"
- cp "$f" "build/artifacts/OpenPuck-${ARTIFACT_VERSION}.${ext}"
- done
- for f in build/reversepuck/*.{uf2,bin,hex,elf,map,zip}; do
- [ -f "$f" ] || continue
- ext="${f##*.}"
- cp "$f" "build/artifacts/ReversePuckFirmware-${ARTIFACT_VERSION}.${ext}"
- done
- ls -la build/artifacts
- - name: Upload build artifacts
- uses: actions/upload-artifact@v4
- with:
- name: openpuck-firmware
- retention-days: 7
- path: |
- build/artifacts/*
|