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>
This commit is contained in:
1 parent
c92adaed01
commit
bf031b55b7
3 files changed
+155
No files matched your search
@@ -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
|
||||||
@@ -120,6 +120,32 @@ 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
|
3. Restart Home Assistant. The light then has an Effect select and Effect speed
|
||||||
and Effect intensity sliders.
|
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
|
## License
|
||||||
|
|
||||||
Released under the [MIT License](LICENSE). The Zigbee stack in
|
Released under the [MIT License](LICENSE). The Zigbee stack in
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const BRIGHTNESS_STEP: i16 = 8;
|
|||||||
#[esp_rtos::main]
|
#[esp_rtos::main]
|
||||||
async fn main(spawner: embassy_executor::Spawner) -> ! {
|
async fn main(spawner: embassy_executor::Spawner) -> ! {
|
||||||
esp_println::logger::init_logger_from_env();
|
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 peripherals = esp_hal::init(esp_hal::Config::default());
|
||||||
|
|
||||||
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
let timg0 = TimerGroup::new(peripherals.TIMG0);
|
||||||
|
|||||||
Reference in new issue
Block a user