build.yml 4.6 KB

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