2 Commits
Author SHA1 Message Date
Matt SpencerandCopilot bf031b55b7 ci: publish a release for every commit to main
release / release (push) Successful in 3m2s
Add a Gitea Actions workflow that builds the firmware and publishes a
release whenever main changes.

The version is MAJOR.MINOR from the version in Cargo.toml plus the number of
commits on main as the patch number, so it only ever goes up and can be worked
out again from any commit. The workflow stamps it into Cargo.toml for the
build, which puts it in the app descriptor, and the firmware now logs it at
boot. The release is tagged v plus the version.

Each release carries a full image (bootloader, partition table and
application, stopping short of the storage partition so flashing it keeps the
Zigbee network), the application image alone, the unstripped build for
backtraces, and checksums.

The submodule is declared with an SSH address, so the workflow rewrites it to
HTTPS for the runner, which has no key. The README documents the scheme.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-29 01:04:33 +00:00
Matt SpencerandCopilot c92adaed01 docs: license the project under the MIT License
Add the LICENSE file, declare the license in Cargo.toml, and say so in the
README. The Zigbee stack in vendor/zigbee-rs is a separate project and keeps
its own licenses (MIT or Apache-2.0).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-29 00:38:36 +00:00
5 changed files with 182 additions and 0 deletions

No files matched your search

+128
View File
@@ -0,0 +1,128 @@
name: release
# Every commit to main builds the firmware and publishes a release.
#
# The version is MAJOR.MINOR from the version in Cargo.toml, with the number
# of commits on main as the patch number, so it only ever goes up and can be
# worked out again from any commit: Cargo.toml saying 0.1.0 gives 0.1.57 for
# the 57th commit. Change MAJOR or MINOR in Cargo.toml to start a new series.
on:
push:
branches:
- main
jobs:
release:
# Must match a label of the Gitea runner.
runs-on: ubuntu-latest
env:
ESPFLASH_VERSION: v4.6.0
steps:
- name: Check out the repository
uses: actions/checkout@v4
with:
# the commit count and the previous release tag need the history
fetch-depth: 0
- name: Fetch the Zigbee stack
run: |
# the submodule is declared with an SSH address; a runner has no key
git config --global url."https://github.com/".insteadOf "git@github.com:"
git submodule update --init
- name: Work out the version
id: version
run: |
base=$(sed -n 's/^version = "\([0-9]*\.[0-9]*\)\..*"/\1/p' Cargo.toml | head -n 1)
count=$(git rev-list --count HEAD)
version="$base.$count"
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "Releasing $version"
# the firmware reads its version from the package, so this is what
# ends up in the app descriptor and the boot log
sed -i '0,/^version = ".*"/s//version = "'"$version"'"/' Cargo.toml
- name: Install Rust
run: |
if ! command -v rustup > /dev/null; then
curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain none
fi
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
export PATH="$HOME/.cargo/bin:$PATH"
# installs the toolchain, components and target that
# rust-toolchain.toml asks for
rustup toolchain install || true
cargo --version
- name: Install espflash
run: |
curl -fsSL -o espflash.zip \
"https://github.com/esp-rs/espflash/releases/download/${ESPFLASH_VERSION}/espflash-x86_64-unknown-linux-musl.zip"
python3 -m zipfile -e espflash.zip "$HOME/espflash-bin"
chmod +x "$HOME/espflash-bin/espflash"
echo "$HOME/espflash-bin" >> "$GITHUB_PATH"
- name: Build the firmware
run: cargo build --release
- name: Package the images
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
elf=target/riscv32imac-unknown-none-elf/release/smart-light
mkdir dist
# the application on its own: what goes into a firmware slot
espflash save-image --chip esp32c6 --flash-size 4mb "$elf" "dist/smart-light-$VERSION.bin"
# bootloader, partition table and application, to be written at
# address 0. Without padding it stops short of the storage
# partition, so flashing it keeps the light's Zigbee network.
espflash save-image --chip esp32c6 --flash-size 4mb --merge --skip-padding \
--partition-table partitions.csv "$elf" "dist/smart-light-$VERSION-full.bin"
# for decoding backtraces
gzip -9 -c "$elf" > "dist/smart-light-$VERSION.elf.gz"
(cd dist && sha256sum * > SHA256SUMS)
ls -l dist
- name: Publish the release
env:
VERSION: ${{ steps.version.outputs.version }}
# the job's own token if it may create releases, otherwise a token
# kept in the RELEASE_TOKEN secret
TOKEN: ${{ secrets.RELEASE_TOKEN || secrets.GITHUB_TOKEN }}
API: ${{ github.server_url }}/api/v1
REPO: ${{ github.repository }}
run: |
previous=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null || true)
notes=$(git log --no-merges --pretty='- %s (%h)' -n 50 ${previous:+"$previous..HEAD"})
payload=$(python3 -c '
import json, sys
version, sha, notes = sys.argv[1:4]
body = "Built from " + sha[:7] + ".\n\n" + notes
print(json.dumps({
"tag_name": "v" + version,
"target_commitish": sha,
"name": "smart-light " + version,
"body": body,
"draft": False,
"prerelease": False,
}))' "$VERSION" "$GITHUB_SHA" "$notes")
response=$(curl -fsS -X POST \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d "$payload" "$API/repos/$REPO/releases")
id=$(printf '%s' "$response" | python3 -c 'import json, sys; print(json.load(sys.stdin)["id"])')
for file in dist/*; do
curl -fsS -X POST \
-H "Authorization: token $TOKEN" \
-F "attachment=@$file" \
"$API/repos/$REPO/releases/$id/assets?name=$(basename "$file")" > /dev/null
echo "uploaded $(basename "$file")"
done
+1
View File
@@ -2,6 +2,7 @@
name = "smart-light"
version = "0.1.0"
edition = "2024"
license = "MIT"
[features]
default = ["esp32c6", "zigbee"]
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Matt Spencer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+31
View File
@@ -119,3 +119,34 @@ sets its speed and intensity. Home Assistant needs a quirk to talk to it:
3. Restart Home Assistant. The light then has an Effect select and Effect speed
and Effect intensity sliders.
## Releases
Every commit to `main` builds the firmware on the Gitea runner and publishes a
release (`.gitea/workflows/release.yml`).
The version is the `MAJOR.MINOR` of the version in `Cargo.toml` followed by the
number of commits on `main`, so with `0.1.0` in `Cargo.toml` the 57th commit
becomes `0.1.57`. It only goes up, and can be worked out again from any commit.
To start a new series, change the major or minor number in `Cargo.toml`. The
build writes the version into the firmware, which logs it at boot, and the
release is tagged `v` plus the version.
Each release has:
- `smart-light-<version>-full.bin`: bootloader, partition table and
application. Write it at address 0 with
`espflash write-bin 0x0 smart-light-<version>-full.bin`. It stops short of
the `storage` partition, so the light keeps its Zigbee network.
- `smart-light-<version>.bin`: the application alone, for a firmware slot.
- `smart-light-<version>.elf.gz`: the unstripped build, for decoding backtraces.
- `SHA256SUMS`.
The workflow's `runs-on` must match a label of your Gitea runner. If the job's
own token is not allowed to create releases, add a token with write access to
the repository as a secret named `RELEASE_TOKEN`.
## License
Released under the [MIT License](LICENSE). The Zigbee stack in
`vendor/zigbee-rs` is a separate project with its own licenses.
+1
View File
@@ -41,6 +41,7 @@ const BRIGHTNESS_STEP: i16 = 8;
#[esp_rtos::main]
async fn main(spawner: embassy_executor::Spawner) -> ! {
esp_println::logger::init_logger_from_env();
log::info!("smart-light {}", env!("CARGO_PKG_VERSION"));
let peripherals = esp_hal::init(esp_hal::Config::default());
let timg0 = TimerGroup::new(peripherals.TIMG0);