build.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. SHORT_SHA="$(git rev-parse --short=8 "${HEAD_SHA}")"
  58. PR_NUMBER_SAFE="${PR_NUMBER:-0}"
  59. if [ "${{ github.event_name }}" = "pull_request" ]; then
  60. VERSION="${BASE_VERSION}-pr${PR_NUMBER_SAFE}+${SHORT_SHA}"
  61. else
  62. VERSION="${BASE_VERSION}"
  63. fi
  64. echo "base_version=$BASE_VERSION" >> "$GITHUB_OUTPUT"
  65. echo "pr_number=$PR_NUMBER_SAFE" >> "$GITHUB_OUTPUT"
  66. echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT"
  67. echo "version=$VERSION" >> "$GITHUB_OUTPUT"
  68. - name: Generate version header
  69. env:
  70. OPK_BUILD_VERSION: ${{ steps.build_version.outputs.version }}
  71. run: ./gen_version.sh
  72. - name: Compile OpenPuck
  73. run: |
  74. mkdir -p build/openpuck build/cache/openpuck
  75. arduino-cli compile \
  76. -b adafruit:nrf52:feather52840 \
  77. --clean \
  78. --build-path build/cache/openpuck \
  79. --output-dir build/openpuck \
  80. --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" \
  81. OpenPuck
  82. - name: Generate UF2 (OpenPuck)
  83. # The Adafruit nRF52 core leaves its UF2 objcopy recipe commented out in
  84. # platform.txt, so arduino-cli only emits .hex/.zip. Convert the .hex to
  85. # a drag-and-drop .uf2 ourselves.
  86. run: ./gen_uf2.sh build/openpuck/OpenPuck.ino.hex build/openpuck/OpenPuck.ino.uf2
  87. - name: Compile ReversePuckFirmware
  88. run: |
  89. mkdir -p build/reversepuck build/cache/reversepuck
  90. arduino-cli compile \
  91. -b adafruit:nrf52:feather52840 \
  92. --clean \
  93. --build-path build/cache/reversepuck \
  94. --output-dir build/reversepuck \
  95. --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb}" \
  96. ReversePuckFirmware
  97. - name: Generate UF2 (ReversePuckFirmware)
  98. run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2
  99. - name: List build outputs
  100. run: |
  101. find build/openpuck build/reversepuck -maxdepth 1 -type f -print | sort
  102. - name: Stage build artifacts
  103. env:
  104. BASE_VERSION: ${{ steps.build_version.outputs.base_version }}
  105. PR_NUMBER: ${{ steps.build_version.outputs.pr_number }}
  106. SHORT_SHA: ${{ steps.build_version.outputs.short_sha }}
  107. run: |
  108. set -eu
  109. mkdir -p build/artifacts
  110. for f in build/openpuck/*.{uf2,bin,hex,elf,map,zip}; do
  111. [ -f "$f" ] || continue
  112. ext="${f##*.}"
  113. cp "$f" "build/artifacts/OpenPuck-${BASE_VERSION}-pr${PR_NUMBER}-${SHORT_SHA}.${ext}"
  114. done
  115. for f in build/reversepuck/*.{uf2,bin,hex,elf,map,zip}; do
  116. [ -f "$f" ] || continue
  117. ext="${f##*.}"
  118. cp "$f" "build/artifacts/ReversePuckFirmware-${BASE_VERSION}-pr${PR_NUMBER}-${SHORT_SHA}.${ext}"
  119. done
  120. ls -la build/artifacts
  121. - name: Upload build artifacts
  122. uses: actions/upload-artifact@v4
  123. with:
  124. name: openpuck-firmware
  125. retention-days: 7
  126. path: |
  127. build/artifacts/*