WrathPak
·
2025-08-16
build_uf2.yml
1name: Build and Deploy Arduino UF2 Firmware
2
3on:
4 push:
5 branches:
6 - main # Or your primary development branch
7 release:
8 types: [published] # Triggers when you publish a new release
9 workflow_dispatch: # Allows manual triggering
10
11jobs:
12 build_firmware: # This remains mostly the same
13 runs-on: ubuntu-latest
14 strategy:
15 fail-fast: false
16 matrix:
17 include:
18 # --- XIAO SAMD21 Configurations ---
19 - board_name: "XIAO_SAMD21"
20 fqbn: "Seeeduino:samd:seeed_XIAO_m0"
21 hw_define: "V1_PCB"
22 uf2_name: "xiao_basic_pcb_v1.uf2"
23 - board_name: "XIAO_SAMD21"
24 fqbn: "Seeeduino:samd:seeed_XIAO_m0"
25 hw_define: "V1_2_PCB"
26 uf2_name: "xiao_basic_pcb_v2.uf2"
27 - board_name: "XIAO_SAMD21"
28 fqbn: "Seeeduino:samd:seeed_XIAO_m0"
29 hw_define: "NO_PCB_GITHUB_SPECS"
30 uf2_name: "xiao_non_pcb.uf2"
31 - board_name: "XIAO_SAMD21"
32 fqbn: "Seeeduino:samd:seeed_XIAO_m0"
33 hw_define: "V2_ADVANCED_PCB"
34 uf2_name: "xiao_advanced_pcb.uf2"
35 # --- Adafruit QT Py SAMD21 Configurations ---
36 - board_name: "QTPY_SAMD21"
37 fqbn: "adafruit:samd:adafruit_qtpy_m0"
38 hw_define: "V1_PCB"
39 uf2_name: "qtpy_basic_pcb_v1.uf2"
40 - board_name: "QTPY_SAMD21"
41 fqbn: "adafruit:samd:adafruit_qtpy_m0"
42 hw_define: "V1_2_PCB"
43 uf2_name: "qtpy_basic_pcb_v2.uf2"
44 - board_name: "QTPY_SAMD21"
45 fqbn: "adafruit:samd:adafruit_qtpy_m0"
46 hw_define: "V2_ADVANCED_PCB"
47 uf2_name: "qtpy_advanced_pcb.uf2"
48 - board_name: "QTPY_SAMD21"
49 fqbn: "adafruit:samd:adafruit_qtpy_m0"
50 hw_define: "NO_PCB_GITHUB_SPECS"
51 uf2_name: "qtpy_non_pcb.uf2"
52 steps:
53 - name: Checkout repository
54 uses: actions/checkout@v4
55 - name: Set up Python
56 uses: actions/setup-python@v5
57 with:
58 python-version: '3.x'
59 - name: Install Arduino CLI
60 uses: arduino/setup-arduino-cli@v2
61 - name: Configure Arduino CLI and Install Cores & Libraries
62 run: |
63 arduino-cli config init
64 arduino-cli config add board_manager.additional_urls https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
65 arduino-cli core update-index
66 arduino-cli core install Seeeduino:samd
67 arduino-cli core install adafruit:samd
68 arduino-cli lib update-index
69 arduino-cli lib install MIDIUSB
70 arduino-cli lib install "Adafruit FreeTouch Library"
71 arduino-cli lib install FlashStorage_SAMD
72 arduino-cli lib install Keyboard
73 - name: Set Hardware Define in Header
74 env:
75 CONFIG_FILE: "config.h"
76 CONFIG_DEFINE: ${{ matrix.hw_define }}
77 DEFINES_LIST: "V1_PCB V1_2_PCB V2_ADVANCED_PCB NO_PCB_GITHUB_SPECS"
78 run: |
79 echo "Setting Hardware Define to: ${CONFIG_DEFINE} in ${CONFIG_FILE}"
80 if [ ! -f "$CONFIG_FILE" ]; then echo "Error: $CONFIG_FILE not found!"; exit 1; fi
81 for DEF in $DEFINES_LIST; do sed -i -E "s|^(\s*#define\s+${DEF})|//#define ${DEF}|" $CONFIG_FILE; done
82 sed -i -E "s|^(\s*//\s*#define\s+${CONFIG_DEFINE})|#define ${CONFIG_DEFINE}|" $CONFIG_FILE
83 - name: Compile Sketch
84 env: { SKETCH_DIR: "." }
85 run: arduino-cli compile --fqbn ${{ matrix.fqbn }} --output-dir build_output --export-binaries $SKETCH_DIR
86 - name: Find or Clone uf2conv.py
87 id: find_uf2conv
88 run: |
89 UF2_CONV_PATH=$(find $HOME/.arduino15/packages/ -name "uf2conv.py" | head -n 1)
90 if [ -z "$UF2_CONV_PATH" ]; then
91 echo "Cloning Microsoft UF2 repo..."
92 git clone https://github.com/microsoft/uf2.git
93 if [ -f "uf2/utils/uf2conv.py" ]; then UF2_CONV_PATH="uf2/utils/uf2conv.py"; else echo "Failed to find uf2conv.py."; exit 1; fi
94 fi
95 echo "UF2_CONV=$UF2_CONV_PATH" >> $GITHUB_ENV
96 - name: Convert to UF2
97 env: { UF2_FAMILY_ID: "0x68ED2B88", UF2_BASE_ADDR: "0x2000" }
98 run: |
99 BIN_FILE=$(find build_output -name "*.bin" | head -n 1)
100 if [ -z "$BIN_FILE" ]; then echo "Error: No .bin file found!"; exit 1; fi
101 python3 ${{ env.UF2_CONV }} -c -f ${{ env.UF2_FAMILY_ID }} -b ${{ env.UF2_BASE_ADDR }} "$BIN_FILE" -o "${{ matrix.uf2_name }}"
102 - name: Upload UF2 Artifact
103 uses: actions/upload-artifact@v4
104 with:
105 name: ${{ matrix.uf2_name }} # Upload each UF2 with its unique name
106 path: ${{ matrix.uf2_name }}
107
108 deploy: # <--- NEW JOB
109 needs: build_firmware # Runs only after all build_firmware jobs succeed
110 runs-on: ubuntu-latest
111 steps:
112 - name: Download all UF2 artifacts
113 uses: actions/download-artifact@v4 # Downloads all artifacts from this run
114 with:
115 path: all_uf2_files # Download to this directory
116
117 - name: List downloaded files
118 run: |
119 echo "Listing downloaded artifacts:"
120 ls -R all_uf2_files
121
122 - name: Checkout GitHub Pages Repo
123 uses: actions/checkout@v4
124 with:
125 repository: 'WrathPak/vail_web_updater' # <--- IMPORTANT: Change this!
126 ssh-key: ${{ secrets.GH_PAGES_DEPLOY_KEY }} # Use the secret we created
127 path: 'gh_pages_repo' # Checkout to a specific directory
128
129 - name: Copy UF2 files to Pages Repo
130 run: |
131 echo "Copying UF2 files..."
132 # Create a target directory if it doesn't exist (e.g., 'firmware')
133 mkdir -p gh_pages_repo/firmware
134 # Copy all downloaded UF2 files (they are in subdirs named after artifacts)
135 find all_uf2_files -name "*.uf2" -exec cp {} gh_pages_repo/firmware/ \;
136 echo "Files in target directory:"
137 ls gh_pages_repo/firmware/
138
139 - name: Commit and Push to Pages Repo
140 run: |
141 cd gh_pages_repo
142 git config user.name "GitHub Action"
143 git config user.email "action@github.com"
144 git add firmware/ # Add the directory (or specific files)
145 # Only commit & push if there are changes
146 if git diff --staged --quiet; then
147 echo "No changes to commit."
148 else
149 git commit -m "Update firmware UF2 files"
150 git push
151 fi