build.yml 4.4 KB

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