mirror of
https://github.com/rstrouse/ESPSomfy-RTS.git
synced 2026-11-20 15:52:12 +01:00
ci: review fixes for the release job and set_version.sh
- set_version.sh: three of its four patterns only matched digits and dots, so FW_VERSION and index.js stayed at v4.0.0.beta and index.html at ?v=3.0.14d. They now match any version, and the script fails when a file doesn't end up with the new one. test/scripts/test_set_version.sh covers it and runs with the native tests. - Release job: each build's files are collected from its own folder, with 4 files each and no name in two builds, before they're signed. The version bump is made on the release's branch as it is now, not the tag, so a merge during the builds doesn't reject the push. - Scorecard reports to code scanning only: publishing from a fork isn't supported, so no badge. - New workflows renamed to .yaml like build.yaml. SECURITY.md: the routes open in Secured mode, and which jobs can write what. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5c57d1a2cd
commit
787cebdb18
9 changed files with 124 additions and 18 deletions
23
.github/set_version.sh
vendored
23
.github/set_version.sh
vendored
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
# Writes a release's version into the sources: bash .github/set_version.sh v4.0.1
|
||||
# The build jobs build with it, the release job commits it.
|
||||
# Tested by test/scripts/test_set_version.sh.
|
||||
set -euo pipefail
|
||||
|
||||
VERSION="${1#v}"
|
||||
|
|
@ -11,7 +12,21 @@ if [[ ! "$VERSION" =~ ^[0-9]+(\.[0-9A-Za-z-]+)*$ ]]; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
sed -i "s/#define FW_VERSION \"v[0-9.]*\"/#define FW_VERSION \"v${VERSION}\"/" src/ConfigSettings.h
|
||||
sed -i "s/^[0-9.].*/${VERSION}/" data-src/appversion
|
||||
sed -i "s/\?v=[0-9.]*c/?v=${VERSION}c/g" data-src/index.html
|
||||
sed -i "s/appVersion = 'v[0-9.]*'/appVersion = 'v${VERSION}'/" data-src/index.js
|
||||
# Each pattern matches whatever version is there now, suffixes included
|
||||
# (v4.0.0.beta, ?v=3.0.14d). The ?v= suffix letter busts the browser cache.
|
||||
sed -i "s/#define FW_VERSION \"v[^\"]*\"/#define FW_VERSION \"v${VERSION}\"/" src/ConfigSettings.h
|
||||
sed -i "s/^[0-9].*/${VERSION}/" data-src/appversion
|
||||
sed -i "s/[?]v=[0-9][0-9A-Za-z.-]*/?v=${VERSION}c/g" data-src/index.html
|
||||
sed -i "s/appVersion = 'v[^']*'/appVersion = 'v${VERSION}'/" data-src/index.js
|
||||
|
||||
# sed succeeds when nothing matches, so check each file got the version.
|
||||
check() {
|
||||
if ! grep -qF -- "$2" "$1"; then
|
||||
echo "$1 doesn't have $2: its version string changed shape" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
check src/ConfigSettings.h "#define FW_VERSION \"v${VERSION}\""
|
||||
check data-src/appversion "${VERSION}"
|
||||
check data-src/index.html "?v=${VERSION}c"
|
||||
check data-src/index.js "appVersion = 'v${VERSION}'"
|
||||
|
|
|
|||
35
.github/workflows/build.yaml
vendored
35
.github/workflows/build.yaml
vendored
|
|
@ -38,6 +38,9 @@ jobs:
|
|||
- name: Run native unit tests
|
||||
run: pio test -e coverage
|
||||
|
||||
- name: Test the release scripts
|
||||
run: bash test/scripts/test_set_version.sh
|
||||
|
||||
# gcovr.cfg picks the files; the table goes to the run's summary page.
|
||||
- name: Coverage report
|
||||
run: |
|
||||
|
|
@ -66,7 +69,7 @@ jobs:
|
|||
uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0
|
||||
with:
|
||||
node-version: "22"
|
||||
# No cache: a release build must not pick up what a PR left in one.
|
||||
# Never cache: this workflow also builds releases.
|
||||
package-manager-cache: false
|
||||
|
||||
# The protocol 2 client (data-src/js) against the recorded fixtures.
|
||||
|
|
@ -337,8 +340,28 @@ jobs:
|
|||
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
|
||||
with:
|
||||
pattern: release-*
|
||||
path: dist
|
||||
merge-multiple: true
|
||||
path: artifacts
|
||||
|
||||
# One folder per build. Each must hold its 4 files, and no build may
|
||||
# replace another's file, so nothing unexpected gets signed.
|
||||
- name: Collect release files
|
||||
run: |
|
||||
mkdir dist
|
||||
for d in artifacts/release-*/; do
|
||||
count=$(find "$d" -type f | wc -l)
|
||||
if [ "$count" -ne 4 ]; then
|
||||
echo "::error::$d has $count files, not 4"
|
||||
exit 1
|
||||
fi
|
||||
for f in "$d"*; do
|
||||
name=$(basename "$f")
|
||||
if [ -e "dist/$name" ]; then
|
||||
echo "::error::$name comes from two builds"
|
||||
exit 1
|
||||
fi
|
||||
cp "$f" dist/
|
||||
done
|
||||
done
|
||||
|
||||
- name: Checksums
|
||||
working-directory: dist
|
||||
|
|
@ -361,9 +384,12 @@ jobs:
|
|||
TAG: ${{ github.event.release.tag_name }}
|
||||
run: gh release upload "$TAG" dist/* --clobber --repo "$GITHUB_REPOSITORY"
|
||||
|
||||
# The release's branch as it is now, not the tag: main may have moved
|
||||
# on while the boards built.
|
||||
- name: Check out code
|
||||
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
||||
with:
|
||||
ref: ${{ github.event.release.target_commitish }}
|
||||
persist-credentials: true # pushes the version bump
|
||||
|
||||
- name: Commit version update
|
||||
|
|
@ -374,6 +400,5 @@ jobs:
|
|||
bash .github/set_version.sh "$TAG"
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git add src/ConfigSettings.h data-src/appversion data-src/index.html data-src/index.js
|
||||
git commit -m "chore: bump version to $TAG"
|
||||
git commit -am "chore: bump version to $TAG"
|
||||
git push origin "HEAD:$TARGET"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ name: Scorecard
|
|||
|
||||
# OpenSSF Scorecard: rates the repo's supply chain practices (pinned
|
||||
# dependencies, token permissions, branch protection, code review, ...).
|
||||
# Results go to Security > Code scanning and to the README badge.
|
||||
# Results go to Security > Code scanning. They aren't published to
|
||||
# scorecard.dev (no badge): scorecard-action doesn't support publishing
|
||||
# from a fork.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
|
|
@ -18,7 +20,6 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
security-events: write # the results to code scanning
|
||||
id-token: write # publishing the results for the badge
|
||||
|
||||
steps:
|
||||
- name: Check out code
|
||||
|
|
@ -31,7 +32,7 @@ jobs:
|
|||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
publish_results: true
|
||||
publish_results: false
|
||||
|
||||
- name: Upload to code scanning
|
||||
uses: github/codeql-action/upload-sarif@9b3254085494b55a0f7c4c2b3d2d52cc712ce370 # v4.39.1
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
- Add or update tests for the code you change, even if nobody asked.
|
||||
- to test run `pio test -e native`
|
||||
- the web UI's protocol 2 client (`data-src/js/`): `node --test "test/js/*.test.js"`. The minify step joins those files into `index.js`, so each one ends with a `module.exports` footer for Node and adds nothing global but its classes.
|
||||
- the release scripts in `.github/` (`set_version.sh`): `bash test/scripts/test_set_version.sh`, which CI runs with the native tests.
|
||||
- coverage of the native tests: `pio test -e coverage`, then `gcovr` (`pip install gcovr`), which reads `gcovr.cfg` and writes `coverage/coverage_details.html`. Files the native env doesn't build aren't in it. CI publishes the coverage of `main` to the repo's GitHub Pages.
|
||||
- coverage of the web UI tests: add `--experimental-test-coverage --test-coverage-include="data-src/js/**"` to the `node --test` command.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
[](https://github.com/cjkas/ESPSomfy-RTS/actions/workflows/build.yaml) [](https://github.com/cjkas/ESPSomfy-RTS/actions/workflows/codeql.yml) [](https://scorecard.dev/viewer/?uri=github.com/cjkas/ESPSomfy-RTS)
|
||||
[](https://github.com/cjkas/ESPSomfy-RTS/actions/workflows/build.yaml) [](https://github.com/cjkas/ESPSomfy-RTS/actions/workflows/codeql.yaml)
|
||||
|
||||
## This is a fork which was created because the original repo seems to be bandoned and I was annoyed by constant restarts of my ESPSomfy. I've fixed some of the major issues caused by watchdog restarts. There are also compiled binaries in my fork if someone is experiencing same issues
|
||||
|
||||
|
|
|
|||
10
SECURITY.md
10
SECURITY.md
|
|
@ -10,7 +10,7 @@ The Home Assistant integration has [its own repo](https://github.com/cjkas/ESPSo
|
|||
|
||||
## What the device protects against
|
||||
|
||||
The device is meant for a local network. In the Secured mode every route and the socket need a login. The threat model, what is in scope and what isn't, is in [docs/SECURITY_PLAN.md](docs/SECURITY_PLAN.md) and [ADR 0006](docs/adr/0006-two-security-modes-eleven-http-routes.md). Don't expose the device to the internet.
|
||||
The device is meant for a local network. In the Secured mode the socket and every HTTP route need a login, except the few the login page itself needs (the web UI's files, `/loginContext`, `/login`, `/upnp.xml`). The threat model, what is in scope and what isn't, is in [docs/SECURITY_PLAN.md](docs/SECURITY_PLAN.md) and [ADR 0006](docs/adr/0006-two-security-modes-eleven-http-routes.md). Don't expose the device to the internet.
|
||||
|
||||
## Checking a download
|
||||
|
||||
|
|
@ -26,10 +26,10 @@ Or compare the checksums with the release's `SHA256SUMS` file:
|
|||
sha256sum --check --ignore-missing SHA256SUMS
|
||||
```
|
||||
|
||||
Releases before 4.0.2 have neither.
|
||||
Releases up to 4.0.1 have neither.
|
||||
|
||||
## How the build is kept clean
|
||||
|
||||
- Every action in the workflows is pinned to a commit, and libraries to exact versions. Dependabot proposes action updates after a week's cooldown.
|
||||
- The workflows can only read the repo by default. Only the release job can write, and it runs no build tools.
|
||||
- [CodeQL](.github/workflows/codeql.yml) scans the C++, the web UI, the Python scripts and the workflows on every PR. [zizmor](.github/workflows/zizmor.yml) lints the workflows, and [OpenSSF Scorecard](.github/workflows/scorecard.yml) rates the repo's practices. Findings are on the repo's Security tab.
|
||||
- Every action in the workflows is pinned to a commit, the firmware's libraries and the build's Python tools to exact versions. Dependabot proposes action updates after a week's cooldown.
|
||||
- The workflows can only read the repo's contents. Only the release job can change them (the release's files, the version bump), and it runs no build tools. The scanning jobs can also report to the Security tab, and the coverage job publishes to GitHub Pages.
|
||||
- [CodeQL](.github/workflows/codeql.yaml) scans the C++, the web UI, the Python scripts and the workflows on every PR. [zizmor](.github/workflows/zizmor.yaml) lints the workflows, and [OpenSSF Scorecard](.github/workflows/scorecard.yaml) rates the repo's practices. Findings are on the repo's Security tab.
|
||||
|
|
|
|||
64
test/scripts/test_set_version.sh
Normal file
64
test/scripts/test_set_version.sh
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/env bash
|
||||
# Tests .github/set_version.sh on copies of the real files:
|
||||
# bash test/scripts/test_set_version.sh
|
||||
set -uo pipefail
|
||||
|
||||
REPO="$(cd "$(dirname "$0")/../.." && pwd)"
|
||||
FILES=(src/ConfigSettings.h data-src/appversion data-src/index.html data-src/index.js)
|
||||
failures=0
|
||||
|
||||
fail() { echo "FAIL: $1"; failures=$((failures + 1)); }
|
||||
|
||||
# A fresh copy of the four files in a temp dir, which becomes the cwd.
|
||||
fresh() {
|
||||
WORK="$(mktemp -d)"
|
||||
for f in "${FILES[@]}"; do
|
||||
mkdir -p "$WORK/$(dirname "$f")"
|
||||
cp "$REPO/$f" "$WORK/$f"
|
||||
done
|
||||
cd "$WORK"
|
||||
}
|
||||
|
||||
run() { bash "$REPO/.github/set_version.sh" "$1" >/dev/null 2>&1; }
|
||||
|
||||
has() { grep -qF -- "$2" "$1" || fail "$3: $1 lacks $2"; }
|
||||
|
||||
# Every version string in the sources today gets the new version.
|
||||
for tag in v4.0.2 v4.1.0.beta v5.0.0-rc1; do
|
||||
fresh
|
||||
v="${tag#v}"
|
||||
run "$tag" || fail "$tag: exited non-zero"
|
||||
has src/ConfigSettings.h "#define FW_VERSION \"v$v\"" "$tag"
|
||||
[[ "$(cat data-src/appversion)" == "$v" ]] || fail "$tag: appversion is $(cat data-src/appversion)"
|
||||
has data-src/index.html "?v=${v}c" "$tag"
|
||||
has data-src/index.js "appVersion = 'v$v'" "$tag"
|
||||
# No old version left behind in index.html's links.
|
||||
if grep -o '?v=[^"'"'"']*' data-src/index.html | grep -vqxF "?v=${v}c"; then
|
||||
fail "$tag: index.html keeps an old ?v="
|
||||
fi
|
||||
done
|
||||
|
||||
# Running it twice with the same tag still passes its own check.
|
||||
fresh
|
||||
run v4.0.2 && run v4.0.2 || fail "a second run with the same tag failed"
|
||||
|
||||
# Tags that aren't versions are rejected and nothing is written.
|
||||
for tag in "v1/2" "v4.0;rm" "v4.0&" "" "vx.y" "v4..0"; do
|
||||
fresh
|
||||
if run "$tag"; then fail "accepted '$tag'"; fi
|
||||
for f in "${FILES[@]}"; do
|
||||
cmp -s "$REPO/$f" "$f" || fail "'$tag' changed $f"
|
||||
done
|
||||
done
|
||||
|
||||
# A file whose version string changed shape fails loudly instead of
|
||||
# silently keeping the old version.
|
||||
fresh
|
||||
sed -i 's/#define FW_VERSION/#define FIRMWARE_VERSION/' src/ConfigSettings.h
|
||||
if run v4.0.2; then fail "passed with no FW_VERSION line"; fi
|
||||
|
||||
if ((failures)); then
|
||||
echo "$failures failure(s)"
|
||||
exit 1
|
||||
fi
|
||||
echo "set_version.sh: all passed"
|
||||
Loading…
Add table
Add a link
Reference in a new issue