Skip to content

Commit 41e4dea

Browse files
Allow to specify the TinyPilot version identifier (#1871)
Follow-up of tiny-pilot/tinypilot-pro#1474, specifically tiny-pilot/tinypilot-pro#1474 (comment). This PR modifies the interface of the `build-debian-pkg` dev script so that it takes on multiple (optional) named flags, instead of just one (optional) position argument: - The `--build-targets` flag replaces the previous positional input argument. - The newly added `--tinypilot-version` now allows to set the version of the Debian package. - That way we are independent from the ambiguous behaviour of the `git describe --tags` command. We can still use it as implicit default, though. In Pro, we can then explicitly pass in the version identifier from the CircleCI build context – without, however, by directly making the `build-debian-pkg` script depend on the CircleCI context, e.g. by referencing the `CIRCLE_TAG` environment variable inside of `build-debian-pkg`. When inspecting [the parameters of the actual build](https://github.com/tiny-pilot/tinypilot/blob/b6f3eb00bd31751dc139c1d6439de11a6fc179f6/dev-scripts/build-debian-pkg#L47), the changes appear to work fine: - [`--platform linux/arm/v7 --build-arg TINYPILOT_VERSION=1.9.5-11+7fae51d`](https://app.circleci.com/pipelines/github/tiny-pilot/tinypilot/4721/workflows/5030b62c-eed8-4536-bf57-772374560679/jobs/35226?invite=true#step-103-182_107) (this PR) - [`--platform linux/arm/v7 --build-arg TINYPILOT_VERSION=1.9.5-8+b6f3eb0`](https://app.circleci.com/pipelines/github/tiny-pilot/tinypilot/4718/workflows/b01d881c-1620-4737-93c1-716d9dba93aa/jobs/35190?invite=true#step-103-390_107) (latest master) <a data-ca-tag href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1871"><img src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review on CodeApprove" /></a> --------- Co-authored-by: Jan Heuermann <jan@jotaen.net>
1 parent b6f3eb0 commit 41e4dea

4 files changed

Lines changed: 51 additions & 20 deletions

File tree

.circleci/config.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ jobs:
181181
docker_layer_caching: true
182182
- run:
183183
name: Build Debian package
184-
command: ./dev-scripts/build-debian-pkg linux/arm/v7
184+
command: |
185+
./dev-scripts/build-debian-pkg \
186+
--build-targets linux/arm/v7
185187
- run:
186188
name: Print Debian package contents
187189
command: dpkg --contents debian-pkg/releases/tinypilot*.deb

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ Once your dev system is configured for multi-architecture Docker builds, you can
285285
TARGET_PLATFORM='linux/arm/v7'
286286

287287
(rm debian-pkg/releases/tinypilot*.deb || true) && \
288-
./dev-scripts/build-debian-pkg "${TARGET_PLATFORM}" && \
288+
./dev-scripts/build-debian-pkg --build-targets "${TARGET_PLATFORM}" && \
289289
mv debian-pkg/releases/tinypilot*.deb bundler/bundle && \
290290
./bundler/create-bundle
291291
```

dev-scripts/build-debian-pkg

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,68 @@
11
#!/bin/bash
22
#
3-
# Build TinyPilot Debian packages.
4-
#
5-
# Usage:
6-
# build-debian-pkg [target architectures]
7-
#
8-
# target architecture: A comma-separated list of architectures that Docker
9-
# accepts for its --platform argument. If omitted, defaults to
10-
# "linux/arm/v7,linux/amd64". The only supported targets are linux/arm/v7 and
11-
# linux/amd64.
12-
#
13-
# Examples
14-
# build-debian-pkg "linux/arm/v7"
15-
# build-debian-pkg "linux/arm/v7,linux/amd64"
3+
# Build a TinyPilot Debian package.
164

175
# Exit build script on first failure.
186
set -e
197

20-
# Echo commands before executing them, by default to stderr.
21-
set -x
22-
238
# Exit on unset variable.
249
set -u
2510

26-
BUILD_TARGETS="${1:-linux/arm/v7,linux/amd64}"
11+
print_help() {
12+
cat <<EOF
13+
Usage: ${0##*/} [--help] [--build-targets BUILD_TARGETS] [--tinypilot-version TINYPILOT_VERSION]
14+
Build a TinyPilot Debian package.
15+
--help Optional. Display this help and exit.
16+
--build-targets BUILD_TARGETS Optional. A comma-separated list of architectures
17+
that Docker accepts for its --platform argument.
18+
If omitted, defaults to "linux/arm/v7,linux/amd64".
19+
The only supported targets are "linux/arm/v7" and
20+
"linux/amd64".
21+
--tinypilot-version TINYPILOT_VERSION Optional. The version identifier that shall be
22+
assigned. If omitted, determines the version string
23+
automatically, in the "x.y.z-i+hhhhhhh" format that
24+
we use for nightly builds.
25+
EOF
26+
}
2727

2828
print_tinypilot_version() {
2929
# Format build hash suffix according to SemVer (`-ghhhhhhh` -> `+hhhhhhh`).
3030
git describe --tags --long |
3131
sed --expression 's/\(-g\([0-9a-f]\{7\}\)\)$/+\2/g'
3232
}
3333

34+
# Parse command-line arguments.
35+
BUILD_TARGETS='linux/arm/v7,linux/amd64'
3436
TINYPILOT_VERSION="$(print_tinypilot_version)"
37+
while (( "$#" > 0 )); do
38+
case "$1" in
39+
--help)
40+
print_help
41+
exit
42+
;;
43+
--build-targets)
44+
BUILD_TARGETS="$2"
45+
shift # For flag name.
46+
shift # For flag value.
47+
;;
48+
--tinypilot-version)
49+
TINYPILOT_VERSION="$2"
50+
shift # For flag name.
51+
shift # For flag value.
52+
;;
53+
*)
54+
>&2 echo "Unknown argument: $1"
55+
>&2 echo "Use the '--help' flag for more information"
56+
exit 1
57+
;;
58+
esac
59+
done
60+
readonly BUILD_TARGETS
3561
readonly TINYPILOT_VERSION
3662

63+
# Echo commands before executing them, by default to stderr.
64+
set -x
65+
3766
PKG_VERSION="$(date '+%Y%m%d%H%M%S')"
3867
readonly PKG_VERSION
3968

dev-scripts/device/install-from-source

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
2222
readonly SCRIPT_DIR
2323
cd "${SCRIPT_DIR}/.."
2424

25-
./dev-scripts/build-debian-pkg "linux/arm/v7"
25+
./dev-scripts/build-debian-pkg --build-targets 'linux/arm/v7'
2626

2727
# Shellcheck recommends find instead of ls for non-alphanumeric filenames, but
2828
# we don't expect non-alphanumeric filenames, and the find equivalent is more

0 commit comments

Comments
 (0)