build.yml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. name: Build
  2. on:
  3. push:
  4. branches:
  5. - main
  6. tags:
  7. - '[0-9]*.[0-9]*.[0-9]*'
  8. # PRs get the same gate -- without this the checks only ran after merge.
  9. pull_request:
  10. pull_request_review:
  11. types:
  12. - submitted
  13. jobs:
  14. compile:
  15. if: github.event_name != 'pull_request_review' || github.event.review.state == 'approved'
  16. runs-on: ubuntu-latest
  17. steps:
  18. - name: Check out repository
  19. uses: actions/checkout@v4
  20. with:
  21. fetch-depth: 0
  22. ref: ${{ github.event.pull_request.head.sha || github.sha }}
  23. - name: Set up Arduino CLI
  24. uses: arduino/setup-arduino-cli@v2
  25. - name: Set up Python
  26. uses: actions/setup-python@v5
  27. with:
  28. python-version: '3.x'
  29. - name: Install adafruit-nrfutil
  30. # The Adafruit nRF52 build recipe shells out to adafruit-nrfutil to
  31. # package the DFU .zip; it is not bundled with the core on the runner.
  32. run: pip install adafruit-nrfutil
  33. - name: Install Adafruit nRF52 core
  34. run: |
  35. arduino-cli config init --overwrite
  36. arduino-cli config set board_manager.additional_urls https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
  37. arduino-cli core update-index
  38. arduino-cli core install adafruit:nrf52
  39. - name: Resolve build version
  40. id: build_version
  41. run: |
  42. set -eu
  43. SEMVER_RE='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$'
  44. BASE_VERSION="$(
  45. git tag --list \
  46. | grep -E "$SEMVER_RE" \
  47. | sort -V \
  48. | tail -n1 || true
  49. )"
  50. if [ -z "$BASE_VERSION" ]; then
  51. BASE_VERSION="0.9.1"
  52. fi
  53. if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "pull_request_review" ]; then
  54. PR_NUMBER="${{ github.event.pull_request.number }}"
  55. SHORT_SHA="$(git rev-parse --short=8 "${GITHUB_SHA}")"
  56. VERSION="${BASE_VERSION}-pr${PR_NUMBER}+${SHORT_SHA}"
  57. else
  58. VERSION="${BASE_VERSION}"
  59. fi
  60. echo "version=$VERSION" >> "$GITHUB_OUTPUT"
  61. - name: Generate version header
  62. env:
  63. OPK_BUILD_VERSION: ${{ steps.build_version.outputs.version }}
  64. run: ./gen_version.sh
  65. - name: Compile OpenPuck
  66. run: |
  67. mkdir -p build/openpuck build/cache/openpuck
  68. arduino-cli compile \
  69. -b adafruit:nrf52:feather52840 \
  70. --clean \
  71. --build-path build/cache/openpuck \
  72. --output-dir build/openpuck \
  73. --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" \
  74. OpenPuck
  75. - name: Generate UF2 (OpenPuck)
  76. # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in
  77. # platform.txt, so arduino-cli only emits .hex/.zip. Convert the .hex to
  78. # a drag-and-drop .uf2 ourselves.
  79. run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
  80. - name: Compile ReversePuckFirmware
  81. run: |
  82. mkdir -p build/reversepuck build/cache/reversepuck
  83. arduino-cli compile \
  84. -b adafruit:nrf52:feather52840 \
  85. --clean \
  86. --build-path build/cache/reversepuck \
  87. --output-dir build/reversepuck \
  88. --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb}" \
  89. ReversePuckFirmware
  90. - name: Generate UF2 (ReversePuckFirmware)
  91. run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2
  92. - name: List build outputs
  93. run: |
  94. find build/openpuck build/reversepuck -maxdepth 1 -type f -print | sort
  95. - name: Upload build artifacts
  96. uses: actions/upload-artifact@v4
  97. with:
  98. name: openpuck-firmware
  99. retention-days: 7
  100. path: |
  101. build/openpuck/*.uf2
  102. build/openpuck/*.bin
  103. build/openpuck/*.hex
  104. build/openpuck/*.elf
  105. build/openpuck/*.map
  106. build/openpuck/*.zip
  107. build/reversepuck/*.uf2
  108. build/reversepuck/*.bin
  109. build/reversepuck/*.hex
  110. build/reversepuck/*.elf
  111. build/reversepuck/*.map
  112. build/reversepuck/*.zip