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>
129 lines
5.0 KiB
YAML
129 lines
5.0 KiB
YAML
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
|