release.yml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. name: Release
  2. on:
  3. push:
  4. branches:
  5. - main
  6. permissions:
  7. contents: write
  8. jobs:
  9. build-release:
  10. runs-on: ubuntu-latest
  11. steps:
  12. - name: Check out repository
  13. uses: actions/checkout@v4
  14. - name: Set up Arduino CLI
  15. uses: arduino/setup-arduino-cli@v2
  16. - name: Set up Python
  17. uses: actions/setup-python@v5
  18. with:
  19. python-version: '3.x'
  20. - name: Install adafruit-nrfutil
  21. run: pip install adafruit-nrfutil
  22. - name: Install Adafruit nRF52 core
  23. run: |
  24. arduino-cli config init --overwrite
  25. arduino-cli config set board_manager.additional_urls https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
  26. arduino-cli core update-index
  27. arduino-cli core install adafruit:nrf52
  28. - name: Generate version header
  29. run: ./gen_version.sh
  30. - name: Compile OpenPuck
  31. run: |
  32. mkdir -p build/openpuck build/cache/openpuck
  33. arduino-cli compile \
  34. -b adafruit:nrf52:feather52840 \
  35. --clean \
  36. --build-path build/cache/openpuck \
  37. --output-dir build/openpuck \
  38. --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
  39. OpenPuck
  40. - name: Compile recovery build
  41. run: |
  42. mkdir -p build/openpuck-recovery build/cache/openpuck-recovery
  43. arduino-cli compile \
  44. -b adafruit:nrf52:feather52840 \
  45. --clean \
  46. --build-path build/cache/openpuck-recovery \
  47. --output-dir build/openpuck-recovery \
  48. --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DOPK_FACTORY_RESET=1" \
  49. OpenPuck
  50. - name: Generate UF2 images
  51. run: |
  52. UF2_FAMILY_ID=0xADA52840
  53. CORE_DIR="$(find "${HOME}/.arduino15/packages/adafruit/hardware/nrf52" \
  54. -mindepth 1 -maxdepth 1 -type d | sort -V | tail -n 1)"
  55. UF2CONV="${CORE_DIR}/tools/uf2conv/uf2conv.py"
  56. if [ ! -f "${UF2CONV}" ]; then
  57. echo "UF2 converter not found: ${UF2CONV}"
  58. exit 1
  59. fi
  60. if [ ! -f build/openpuck/OpenPuck.ino.hex ]; then
  61. echo "HEX output not found: build/openpuck/OpenPuck.ino.hex"
  62. exit 1
  63. fi
  64. if [ ! -f build/openpuck-recovery/OpenPuck.ino.hex ]; then
  65. echo "HEX output not found: build/openpuck-recovery/OpenPuck.ino.hex"
  66. exit 1
  67. fi
  68. python3 "${UF2CONV}" -f "${UF2_FAMILY_ID}" -c \
  69. -o build/openpuck/OpenPuck.ino.uf2 \
  70. build/openpuck/OpenPuck.ino.hex
  71. python3 "${UF2CONV}" -f "${UF2_FAMILY_ID}" -c \
  72. -o build/openpuck-recovery/OpenPuck.ino.uf2 \
  73. build/openpuck-recovery/OpenPuck.ino.hex
  74. - name: Collect artifacts
  75. run: |
  76. mkdir -p release_assets
  77. REF="${GITHUB_REF_NAME}"
  78. SAFE_REF="$(printf '%s' "$REF" | tr -c 'A-Za-z0-9._-' '-')"
  79. SHA_SHORT="$(git rev-parse --short=8 HEAD)"
  80. VERSION="${SAFE_REF}-${SHA_SHORT}"
  81. find build/openpuck build/openpuck-recovery \
  82. -maxdepth 1 -type f \
  83. -name '*.uf2' \
  84. -print | while read -r f; do
  85. base="$(basename "$f")"
  86. dir="$(basename "$(dirname "$f")")"
  87. if [ "$dir" = "openpuck-recovery" ]; then
  88. flavor="factory-reset"
  89. else
  90. flavor="standard"
  91. fi
  92. cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}-${base}"
  93. done
  94. test -n "$(find release_assets -maxdepth 1 -type f -print -quit)"
  95. ls -la release_assets
  96. - name: Create GitHub Release
  97. uses: softprops/action-gh-release@v2
  98. with:
  99. tag_name: ${{ format('build-{0}', github.sha) }}
  100. target_commitish: ${{ github.sha }}
  101. name: ${{ format('Build {0}', github.sha) }}
  102. prerelease: true
  103. files: release_assets/*
  104. body: |
  105. OpenPuck Firmware Release
  106. Build: ${{ github.sha }}
  107. Ref: ${{ github.ref_name }}
  108. ### Files included:
  109. - `.uf2` files for drag-and-drop flashing
  110. env:
  111. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}