#!/usr/bin/env bash # # One monotonic versionCode rule, shared by CI and manual builds # (fdroid-repo-ci#6). Two implementations of "the next version code" is the # whole failure mode this avoids, so both paths call this one script rather # than each computing their own. # # next-version-code.sh \ # # # is the COMMITTER date (not author date -- a rebase # leaves author date unchanged, which would defeat the backwards clamp) of # the commit being built, as Unix seconds: `git log -1 --format=%ct`. This # script takes it as an argument rather than reading git itself, on purpose # -- the caller already knows its own commit, and it keeps the underlying # Python pure and testable without a git checkout. # # Prints the integer to stdout and nothing else: # # versionCode=$(bash next-version-code.sh "$INDEX_URL" "$APPLICATION_ID" \ # "$(git log -1 --format=%ct)") # # The index source may be an http(s) URL -- what both CI and a manual build # use in practice, and needs no credentials, since this repo and the F-Droid # repo it reads are both public (weblib-viewer#16: buildable when CI is # down) -- or a local file path, which is mainly what the offline test suite # uses but is equally valid for a build that already has the index checked # out. # # Fails loudly (non-zero exit, message on stderr, nothing on stdout) if the # index cannot be fetched or parsed -- see next_version_code.py for why that # is never allowed to fall back to a guess. An index with no entry at all for # this application id is NOT an error: that is a normal first-ever publish # for a channel, and yields the bare (clamped) candidate. A commit dated # implausibly far in the future is also NOT a hard failure -- it is clamped # to roughly now and a warning is printed on stderr; see next_version_code.py # for why rejecting it outright would be worse. # # The rule itself, and why each part of it is shaped this way, lives in # next_version_code.py's own docstring -- read that, not this file, for the # reasoning. This script only resolves the pinned interpreter and forwards # arguments; everything that can be unit-tested without nix lives in the # stdlib-only Python module next to it. # # Pins python3 (stdlib json/urllib/datetime/argparse does the rest -- no # other package) via with-nixpkgs.sh/nixpkgs-pin, next to this script. set -euo pipefail here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) if [ "$#" -ne 3 ]; then cat >&2 <<'USAGE' usage: next-version-code.sh USAGE exit 2 fi exec bash "$here/with-nixpkgs.sh" python3 python3 "$here/next_version_code.py" "$@"