build.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. make build BUILD_PATH=build/cache/openpuck OUTPUT_DIR=build/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. make reversepuck BUILD_PATH=build/cache/reversepuck OUTPUT_DIR=build/reversepuck
  88. - name: Generate UF2 (ReversePuckFirmware)
  89. run: ./gen_uf2.sh build/reversepuck/ReversePuckFirmware.ino.hex build/reversepuck/ReversePuckFirmware.ino.uf2
  90. - name: List build outputs
  91. run: |
  92. find build/openpuck build/reversepuck -maxdepth 1 -type f -print | sort
  93. - name: Upload OpenPuck UF2 artifact
  94. uses: actions/upload-artifact@v4
  95. with:
  96. name: OpenPuck-${{ steps.build_version.outputs.artifact_version }}-standard.uf2
  97. retention-days: 7
  98. if-no-files-found: error
  99. path: build/openpuck/OpenPuck.ino.uf2
  100. - name: Upload OpenPuck HEX artifact
  101. uses: actions/upload-artifact@v4
  102. with:
  103. name: OpenPuck-${{ steps.build_version.outputs.artifact_version }}-standard.hex
  104. retention-days: 7
  105. if-no-files-found: error
  106. path: build/openpuck/OpenPuck.ino.hex
  107. - name: Upload ReversePuckFirmware UF2 artifact
  108. uses: actions/upload-artifact@v4
  109. with:
  110. name: ReversePuckFirmware-${{ steps.build_version.outputs.artifact_version }}.uf2
  111. retention-days: 7
  112. if-no-files-found: error
  113. path: build/reversepuck/ReversePuckFirmware.ino.uf2
  114. - name: Upload ReversePuckFirmware HEX artifact
  115. uses: actions/upload-artifact@v4
  116. with:
  117. name: ReversePuckFirmware-${{ steps.build_version.outputs.artifact_version }}.hex
  118. retention-days: 7
  119. if-no-files-found: error
  120. path: build/reversepuck/ReversePuckFirmware.ino.hex