build.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: Stage build artifacts
  106. env:
  107. ARTIFACT_VERSION: ${{ steps.build_version.outputs.artifact_version }}
  108. run: |
  109. set -eu
  110. shopt -s nullglob
  111. mkdir -p build/artifacts
  112. for f in build/openpuck/*.{uf2,bin,hex,elf,map,zip}; do
  113. [ -f "$f" ] || continue
  114. base="$(basename "$f")"
  115. stem="${base%.*}"
  116. ext="${f##*.}"
  117. cp "$f" "build/artifacts/${stem}-${ARTIFACT_VERSION}.${ext}"
  118. done
  119. for f in build/reversepuck/*.{uf2,bin,hex,elf,map,zip}; do
  120. [ -f "$f" ] || continue
  121. base="$(basename "$f")"
  122. stem="${base%.*}"
  123. ext="${f##*.}"
  124. cp "$f" "build/artifacts/${stem}-${ARTIFACT_VERSION}.${ext}"
  125. done
  126. ls -la build/artifacts
  127. - name: Upload build artifacts
  128. uses: actions/upload-artifact@v4
  129. with:
  130. name: openpuck-firmware
  131. retention-days: 7
  132. path: |
  133. build/artifacts/*