Browse Source

Add firmware build and release workflows (#75)

* Add GitHub Actions for building and releasing

* Fix build outputs: copy files from ARDUINO_BUILD_OUTPUT_DIR before cleanup

* Fix build outputs copy: search in correct Adafruit core directories

* Fix build outputs copy: handle empty build_outputs directory gracefully

* Fix build outputs copying: search .arduino15 recursively for firmware files

* Fix firmware build release workflow

* Run firmware workflows only on main

* Limit release assets to flashable files
Ulises Robles 4 tháng trước cách đây
mục cha
commit
9f01fd5e4f
4 tập tin đã thay đổi với 135 bổ sung và 2 xóa
  1. 26 1
      .github/workflows/build.yml
  2. 2 1
      .github/workflows/format.yml
  3. 105 0
      .github/workflows/release.yml
  4. 2 0
      .gitignore

+ 26 - 1
.github/workflows/build.yml

@@ -2,7 +2,8 @@ name: Build
 
 on:
   push:
-  pull_request:
+    branches:
+      - main
 
 jobs:
   compile:
@@ -32,9 +33,33 @@ jobs:
           arduino-cli core update-index
           arduino-cli core install adafruit:nrf52
 
+      - name: Generate version header
+        run: ./gen_version.sh
+
       - name: Compile OpenPuck
         run: |
+          mkdir -p build/openpuck build/cache/openpuck
           arduino-cli compile \
             -b adafruit:nrf52:feather52840 \
+            --clean \
+            --build-path build/cache/openpuck \
+            --output-dir build/openpuck \
             --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
             OpenPuck
+
+      - name: List build outputs
+        run: |
+          find build/openpuck -maxdepth 1 -type f -print | sort
+
+      - name: Upload build artifacts
+        uses: actions/upload-artifact@v4
+        with:
+          name: openpuck-firmware
+          retention-days: 7
+          path: |
+            build/openpuck/*.uf2
+            build/openpuck/*.bin
+            build/openpuck/*.hex
+            build/openpuck/*.elf
+            build/openpuck/*.map
+            build/openpuck/*.zip

+ 2 - 1
.github/workflows/format.yml

@@ -2,7 +2,8 @@ name: Format
 
 on:
   push:
-  pull_request:
+    branches:
+      - main
 
 jobs:
   clang-format:

+ 105 - 0
.github/workflows/release.yml

@@ -0,0 +1,105 @@
+name: Release
+
+on:
+  push:
+    branches:
+      - main
+
+permissions:
+  contents: write
+
+jobs:
+  build-release:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Check out repository
+        uses: actions/checkout@v4
+
+      - name: Set up Arduino CLI
+        uses: arduino/setup-arduino-cli@v2
+
+      - name: Set up Python
+        uses: actions/setup-python@v5
+        with:
+          python-version: '3.x'
+
+      - name: Install adafruit-nrfutil
+        run: pip install adafruit-nrfutil
+
+      - name: Install Adafruit nRF52 core
+        run: |
+          arduino-cli config init --overwrite
+          arduino-cli config set board_manager.additional_urls https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
+          arduino-cli core update-index
+          arduino-cli core install adafruit:nrf52
+
+      - name: Generate version header
+        run: ./gen_version.sh
+
+      - name: Compile OpenPuck
+        run: |
+          mkdir -p build/openpuck build/cache/openpuck
+          arduino-cli compile \
+            -b adafruit:nrf52:feather52840 \
+            --clean \
+            --build-path build/cache/openpuck \
+            --output-dir build/openpuck \
+            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4" \
+            OpenPuck
+
+      - name: Compile recovery build
+        run: |
+          mkdir -p build/openpuck-recovery build/cache/openpuck-recovery
+          arduino-cli compile \
+            -b adafruit:nrf52:feather52840 \
+            --clean \
+            --build-path build/cache/openpuck-recovery \
+            --output-dir build/openpuck-recovery \
+            --build-property "build.extra_flags=-DNRF52840_XXAA {build.flags.usb} -DCFG_TUD_HID=4 -DOPK_FACTORY_RESET=1" \
+            OpenPuck
+
+      - name: Collect artifacts
+        run: |
+          mkdir -p release_assets
+          REF="${GITHUB_REF_NAME}"
+          SAFE_REF="$(printf '%s' "$REF" | tr -c 'A-Za-z0-9._-' '-')"
+          SHA_SHORT="$(git rev-parse --short=8 HEAD)"
+          VERSION="${SAFE_REF}-${SHA_SHORT}"
+
+          find build/openpuck build/openpuck-recovery \
+            -maxdepth 1 -type f \
+            \( -name '*.uf2' -o -name '*.zip' \) \
+            -print | while read -r f; do
+            base="$(basename "$f")"
+            dir="$(basename "$(dirname "$f")")"
+            if [ "$dir" = "openpuck-recovery" ]; then
+              flavor="factory-reset"
+            else
+              flavor="standard"
+            fi
+            cp "$f" "release_assets/OpenPuck-${VERSION}-${flavor}-${base}"
+          done
+          test -n "$(find release_assets -maxdepth 1 -type f -print -quit)"
+          ls -la release_assets
+
+      - name: Create GitHub Release
+        uses: softprops/action-gh-release@v2
+        with:
+          tag_name: ${{ format('build-{0}', github.sha) }}
+          target_commitish: ${{ github.sha }}
+          name: ${{ format('Build {0}', github.sha) }}
+          prerelease: true
+          files: release_assets/*
+          body: |
+            OpenPuck Firmware Release
+
+            Build: ${{ github.sha }}
+            Ref: ${{ github.ref_name }}
+
+            ### Files included:
+
+            - `.zip` files for Adafruit DFU tool
+            - `.uf2` files for drag-and-drop flashing, if generated by the board core
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 2 - 0
.gitignore

@@ -3,6 +3,8 @@
 *.log
 *.json
 tmp/
+build/
+release_assets/
 # pairtui helper binary (build from scmd.c: clang -framework IOKit -framework CoreFoundation -o scmd scmd.c)
 pairtui/scmd
 __pycache__/