build.yml 5.5 KB

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