Skip to content

Commit bbe138d

Browse files
authored
Merge pull request #23 from bofh69/copilot/update-version-numbers
Automate version updates and include Arduino firmware in releases
2 parents 4d7b890 + 91606da commit bbe138d

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed

.github/workflows/publish.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
runs-on: ubuntu-latest
2121
permissions:
2222
contents: read
23+
outputs:
24+
version: ${{ steps.extract_version.outputs.version }}
2325

2426
steps:
2527
- uses: actions/checkout@v4
@@ -29,6 +31,54 @@ jobs:
2931
with:
3032
python-version: '3.11'
3133

34+
- name: Update version from tag
35+
id: extract_version
36+
if: github.event_name == 'release'
37+
env:
38+
VERSION_TAG: ${{ github.ref_name }}
39+
run: |
40+
# Extract version from tag (remove 'v' prefix if present)
41+
VERSION="${VERSION_TAG#v}"
42+
43+
# Validate version is not empty and contains only valid characters
44+
if [[ -z "$VERSION" ]]; then
45+
echo "Error: Failed to extract version from tag"
46+
exit 1
47+
fi
48+
49+
# Validate semver format: X.Y.Z or X.Y.Z-prerelease
50+
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+([.-][a-zA-Z0-9]+)*)?$ ]]; then
51+
echo "Error: Invalid version format: $VERSION"
52+
echo "Version must match semver format (e.g., 1.2.3 or 1.2.3-alpha.1)"
53+
exit 1
54+
fi
55+
56+
echo "Updating version to: $VERSION"
57+
echo "version=$VERSION" >> $GITHUB_OUTPUT
58+
59+
# Check that required files exist
60+
if [[ ! -f pyproject.toml ]]; then
61+
echo "Error: pyproject.toml not found"
62+
exit 1
63+
fi
64+
65+
if [[ ! -f src/pn5180_tagomatic/__init__.py ]]; then
66+
echo "Error: src/pn5180_tagomatic/__init__.py not found"
67+
exit 1
68+
fi
69+
70+
# Update pyproject.toml
71+
sed -i "s/^version = .*/version = \"$VERSION\"/" pyproject.toml
72+
73+
# Update __init__.py
74+
sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" src/pn5180_tagomatic/__init__.py
75+
76+
# Verify changes
77+
echo "pyproject.toml version:"
78+
grep "^version = " pyproject.toml
79+
echo "__init__.py version:"
80+
grep "^__version__ = " src/pn5180_tagomatic/__init__.py
81+
3282
- name: Install build dependencies
3383
run: |
3484
python -m pip install --upgrade pip
@@ -89,3 +139,72 @@ jobs:
89139
uses: pypa/gh-action-pypi-publish@release/v1
90140
with:
91141
repository-url: https://test.pypi.org/legacy/
142+
143+
build-arduino:
144+
name: Build Arduino Firmware
145+
if: github.event_name == 'release'
146+
needs: [build]
147+
runs-on: ubuntu-latest
148+
permissions:
149+
contents: write
150+
151+
steps:
152+
- uses: actions/checkout@v4
153+
154+
- name: Set up Arduino CLI
155+
uses: arduino/setup-arduino-cli@v1
156+
157+
- name: Install platform
158+
run: |
159+
arduino-cli config init
160+
arduino-cli core update-index
161+
arduino-cli core install arduino:mbed_rp2040
162+
163+
- name: Install libraries
164+
run: |
165+
arduino-cli lib install simpleRPC
166+
arduino-cli lib install FastLED
167+
168+
- name: Compile sketch for Raspberry Pi Pico
169+
run: |
170+
arduino-cli compile -e --fqbn arduino:mbed_rp2040:pico sketch/pn5180_reader
171+
172+
- name: Find and rename UF2 file
173+
id: find_uf2
174+
env:
175+
VERSION: ${{ needs.build.outputs.version }}
176+
run: |
177+
# Find all uf2 files
178+
mapfile -t UF2_FILES < <(find sketch/pn5180_reader/build -name "*.uf2")
179+
180+
if [[ ${#UF2_FILES[@]} -eq 0 ]]; then
181+
echo "Error: No UF2 files found"
182+
exit 1
183+
fi
184+
185+
if [[ ${#UF2_FILES[@]} -gt 1 ]]; then
186+
echo "Warning: Multiple UF2 files found:"
187+
printf '%s\n' "${UF2_FILES[@]}"
188+
echo "Using the first one: ${UF2_FILES[0]}"
189+
fi
190+
191+
UF2_FILE="${UF2_FILES[0]}"
192+
193+
# Create a descriptive filename using version from build job
194+
NEW_NAME="pn5180_reader-${VERSION}-raspberry-pi-pico.uf2"
195+
196+
# Copy to a known location with the new name
197+
mkdir -p release
198+
cp "$UF2_FILE" "release/$NEW_NAME"
199+
200+
echo "uf2_file=release/$NEW_NAME" >> $GITHUB_OUTPUT
201+
echo "uf2_name=$NEW_NAME" >> $GITHUB_OUTPUT
202+
203+
echo "Created release file:"
204+
ls -lh "release/$NEW_NAME"
205+
206+
- name: Upload UF2 to Release
207+
uses: softprops/action-gh-release@v1
208+
with:
209+
files: ${{ steps.find_uf2.outputs.uf2_file }}
210+
fail_on_unmatched_files: true

0 commit comments

Comments
 (0)