diff --git a/.github/actions/build-version/action.yml b/.github/actions/build-version/action.yml new file mode 100644 index 00000000..821e5b4e --- /dev/null +++ b/.github/actions/build-version/action.yml @@ -0,0 +1,21 @@ +name: Build version +description: >- + Works out the build version and stamps it into pubspec.yaml, exporting + WIMSY_VERSION, WIMSY_VERSION_CORE, WIMSY_BUILD_NUMBER and WIMSY_MSIX_VERSION + to later steps in the job. Maps GitHub's tag ref and run number onto the + provider-neutral tool/fetch_release_history.sh and tool/build_version.sh. + The repository must already be checked out. +runs: + using: composite + steps: + - name: Fetch release history + shell: bash + run: bash tool/fetch_release_history.sh + - name: Set build version + shell: bash + # Passed via env, not interpolated into the script, so a tag name + # cannot inject shell. + env: + RELEASE_TAG: ${{ startsWith(github.ref, 'refs/tags/v') && github.ref_name || '' }} + BUILD_NUMBER: ${{ github.run_number }} + run: bash tool/build_version.sh --tag "$RELEASE_TAG" --build-number "$BUILD_NUMBER" --write-pubspec | tee -a "$GITHUB_ENV" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b8f6d36a..bb845776 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,22 +14,7 @@ jobs: channel: stable cache: true - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Install xmpp_stone dependencies @@ -43,6 +28,20 @@ jobs: - name: Test run: flutter test + test-ci-scripts: + # The version scripts run on all three runner types, so test them on all + # three, in parallel with the builds rather than in front of them. + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v7 + - name: Test CI scripts + shell: bash + run: bash tool/test_build_version.sh + dependency-vulnerability-scan: needs: analyze runs-on: ubuntu-latest @@ -230,22 +229,7 @@ jobs: with: targets: x86_64-unknown-linux-gnu - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Show compiler versions @@ -263,7 +247,8 @@ jobs: tar -C build/linux/x64/release -czf wimsy-linux.tar.gz bundle - name: Package Linux (.deb) run: | - VERSION=$(grep '^version:' pubspec.yaml | awk '{print $2}') + # Display version without the +build suffix now in pubspec.yaml. + VERSION="$WIMSY_VERSION" PKG_DIR="wimsy_${VERSION}_amd64" mkdir -p "$PKG_DIR/DEBIAN" \ "$PKG_DIR/usr/lib/wimsy" \ @@ -334,22 +319,7 @@ jobs: with: targets: x86_64-pc-windows-msvc - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Build Windows @@ -384,41 +354,18 @@ jobs: with: targets: x86_64-apple-darwin,aarch64-apple-darwin - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Build macOS - run: flutter build macos --release + # Numeric-only build name: Flutter mangles the -pre- display + # version on Apple platforms. The build number comes from pubspec.yaml. + run: flutter build macos --release --build-name "$WIMSY_VERSION_CORE" - name: Package macOS run: tool/package_macos_dmg.sh build/macos/Build/Products/Release/wimsy.app wimsy-macos.dmg - name: Verify macOS package shell: bash - run: | - set -euo pipefail - # Only tag builds have a version Flutter passes through unchanged: - # pre-release versions like 0.0.6-pre- are mangled into - # CFBundleShortVersionString (non-digits stripped), so skip the - # version check for those. - expected_version="" - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - expected_version="${GITHUB_REF#refs/tags/v}" - fi - tool/verify_macos_dmg.sh wimsy-macos.dmg "$expected_version" + run: tool/verify_macos_dmg.sh wimsy-macos.dmg "$WIMSY_VERSION_CORE" "$WIMSY_BUILD_NUMBER" - name: Upload macOS artifact uses: actions/upload-artifact@v6 with: @@ -439,26 +386,12 @@ jobs: with: targets: aarch64-apple-ios,aarch64-apple-ios-sim,x86_64-apple-ios - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Build iOS - run: flutter build ios --no-codesign + # Numeric-only build name; see build-macos. + run: flutter build ios --no-codesign --build-name "$WIMSY_VERSION_CORE" - name: Upload iOS artifact uses: actions/upload-artifact@v6 with: @@ -481,22 +414,7 @@ jobs: - name: Install cargo-ndk run: cargo install cargo-ndk --locked - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Build Android (release) @@ -667,22 +585,7 @@ jobs: channel: stable cache: true - name: Set Build Version - shell: bash - run: | - set -euo pipefail - git fetch --tags --force - base_tag="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" - base_version="${base_tag#v}" - if [[ -z "$base_version" ]]; then - base_version="0.0.0" - fi - if [[ "${GITHUB_REF:-}" == refs/tags/v* ]]; then - version="${GITHUB_REF#refs/tags/v}" - else - version="${base_version}-pre-$(git rev-parse --short HEAD)" - fi - sed -i -E "s/^version: .*/version: ${version}/" pubspec.yaml - echo "Build version set to ${version}" + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Test WebTransport in Chrome @@ -715,6 +618,8 @@ jobs: with: channel: stable cache: true + - name: Set Build Version + uses: ./.github/actions/build-version - name: Install dependencies run: flutter pub get - name: Build Web (GitHub Pages) @@ -728,7 +633,7 @@ jobs: uses: actions/deploy-pages@v4 publish-release: - needs: [build-linux, build-windows, build-macos, build-android, build-web, sbom] + needs: [build-linux, build-windows, build-macos, build-android, build-web, sbom, test-ci-scripts] if: startsWith(github.ref, 'refs/tags/v') runs-on: ubuntu-latest permissions: diff --git a/tool/build_version.sh b/tool/build_version.sh new file mode 100755 index 00000000..6cfd404d --- /dev/null +++ b/tool/build_version.sh @@ -0,0 +1,225 @@ +#!/usr/bin/env bash +# Works out the build version from git and prints it, optionally also +# stamping it into pubspec.yaml. +# +# Usage: tool/build_version.sh [--tag TAG] [--build-number N] +# [--write-pubspec] [--pubspec PATH] +# --tag TAG build a release from tag TAG (vX.Y.Z or X.Y.Z, with an +# optional -pre-release part such as -rc1). Empty or +# omitted means a pre-release build. +# --build-number N positive integer build number (default 1). +# --write-pubspec also rewrite the version and msix_version lines of +# the pubspec (see below). Without it, nothing is +# modified. +# --pubspec PATH pubspec to rewrite (default pubspec.yaml). +# +# Run from inside the git checkout. Nothing here is specific to a CI +# provider: CI maps its own tag and run number onto --tag and +# --build-number, and reads the printed values. Release tags are found in +# HEAD's history, so in a shallow or tagless clone run +# tool/fetch_release_history.sh first; a pre-release or -rc build fails +# rather than guessing if HEAD's history is cut off before any final +# release. +# +# Tags must be v followed by a semver 2.0.0 version (X.Y.Z without leading +# zeros, optional -pre-release and +build parts). Use dotted pre-release +# numbers (v1.0.0-rc.10, not -rc10) so that rc10 sorts after rc9. +# +# Versions: +# release build: display version from the tag (build metadata in the +# tag, e.g. v1.2.3+foo, is rejected) +# pre-release build: display version -pre-, where +# is the nearest release tag to HEAD, unless the +# highest final release in HEAD's history is at least +# as high (an older release merged back in, or an rc +# whose final release exists), in which case it is that +# final release. 0.0.0 if there are no tags. Build +# metadata on the base tag is dropped. +# +# Output (stdout, one KEY=VALUE per line; diagnostics go to stderr): +# WIMSY_VERSION display version, e.g. 0.0.6 or 0.0.6-pre-d217e1d +# WIMSY_VERSION_CORE numeric X.Y.Z only, e.g. 0.0.6. Pass this as +# --build-name on iOS/macOS: Flutter otherwise strips +# non-digits from the display version and produces +# nonsense such as 0.0.62171. Apple platforms only accept +# numeric versions, so a pre-release (or an -rc tag) has +# the same short version as its release there; the build +# number tells them apart. +# WIMSY_BUILD_NUMBER the build number. A CI run counter is shared by all +# branches, so it orders builds by when they ran, not by +# what they contain, and restarts if the counter does. +# WIMSY_MSIX_VERSION MSIX versions are four numbers with no pre-release +# part, so only final releases get their own X.Y.Z.0. +# Pre-release and -rc tag builds get +# ., +# which sorts after that release, before the next, and +# in build order in between. The build number must then +# fit the 16-bit field (at most 65535), or this fails. +# +# --write-pubspec sets: +# version: + +# msix_version: +# so every tool that reads the pubspec (flutter build, msix:create, +# package_info_plus and hence Sentry) picks the version up without extra +# flags. Restore it afterwards with `git checkout pubspec.yaml`. +set -euo pipefail + +# shellcheck source=tool/release_tags.sh +source "$(dirname "${BASH_SOURCE[0]}")/release_tags.sh" + +usage() { + sed -n '5,14p' "$0" | sed 's/^# \{0,1\}//' >&2 + exit 2 +} + +tag="" +build_number="1" +write_pubspec=false +pubspec="pubspec.yaml" +while (($# > 0)); do + case "$1" in + --tag) tag="${2-}"; shift 2 || usage ;; + --build-number) build_number="${2-}"; shift 2 || usage ;; + --write-pubspec) write_pubspec=true; shift ;; + --pubspec) pubspec="${2-}"; shift 2 || usage ;; + *) echo "error: unknown argument '$1'" >&2; usage ;; + esac +done + +if [[ ! "$build_number" =~ ^[1-9][0-9]*$ ]]; then + echo "error: build number must be a positive integer, got '$build_number'" >&2 + exit 1 +fi + +# version_of TAG: TAG's version without the leading v and any +build +# metadata (which carries no meaning for ordering). +version_of() { + local v="${1#v}" + echo "${v%%+*}" +} + +# core_le A B: true if the X.Y.Z core of version A is <= that of B. +core_le() { + local -a a b + local i + IFS=. read -r -a a <<<"${1%%[-+]*}" + IFS=. read -r -a b <<<"${2%%[-+]*}" + for i in 0 1 2; do + if ((a[i] < b[i])); then return 0; fi + if ((a[i] > b[i])); then return 1; fi + done + return 0 +} + +# nearest_tag: the release tag (final or pre-release) nearest to HEAD, or +# nothing. describe's glob is only a first filter; the tag must also be a +# valid release tag. +nearest_tag() { + local t + t="$(git describe --tags --abbrev=0 --match 'v[0-9]*' 2>/dev/null || true)" + if [[ -n "$t" ]] && is_release_tag "$t"; then echo "$t"; fi +} + +# last_final_tag: the highest final release tag in HEAD's history, or +# nothing. +last_final_tag() { + local t core x y z + git tag --merged HEAD --list 'v[0-9]*' | while read -r t; do + if is_final_tag "$t"; then + core="$(version_of "$t")" + IFS=. read -r x y z <<<"$core" + echo "$x $y $z $t" + fi + done | sort -k1,1n -k2,2n -k3,3n | tail -n 1 | cut -d' ' -f4 +} + +# require_history FINAL_TAG: fail unless a final release was found or HEAD's +# history is complete, so a missing tag means "none" rather than "not +# fetched". +require_history() { + if [[ -z "$1" ]] && head_is_shallow; then + echo "error: HEAD's history is shallow and contains no final release tag; run tool/fetch_release_history.sh first" >&2 + exit 1 + fi +} + +# msix_prerelease FINAL_TAG: .. +msix_prerelease() { + if ((build_number > 65535)); then + echo "error: build number $build_number exceeds the MSIX field limit of 65535" >&2 + exit 1 + fi + echo "$(version_of "${1:-v0.0.0}").${build_number}" +} + +if [[ -n "$tag" ]]; then + [[ "$tag" == v* ]] || tag="v$tag" + if ! is_release_tag "$tag"; then + echo "error: tag '$tag' is not v followed by a semver version (X.Y.Z, no leading zeros, optional -pre-release)" >&2 + exit 1 + fi + if [[ "$tag" == *+* ]]; then + echo "error: tag '$tag' must not contain +build metadata; the build number is appended automatically" >&2 + exit 1 + fi + version="${tag#v}" + if is_final_tag "$tag"; then + msix_version="${version}.0" + else + # An -rc tag: numbered like a pre-release on MSIX, so that its final + # release is an upgrade from it. + final_tag="$(last_final_tag)" + require_history "$final_tag" + msix_version="$(msix_prerelease "$final_tag")" + fi +else + final_tag="$(last_final_tag)" + require_history "$final_tag" + base_tag="$(nearest_tag)" + base_version="$(version_of "${base_tag:-v0.0.0}")" + if [[ -n "$final_tag" ]] && core_le "$base_version" "$(version_of "$final_tag")"; then + base_version="$(version_of "$final_tag")" + fi + version="${base_version}-pre-$(git rev-parse --short HEAD)" + msix_version="$(msix_prerelease "$final_tag")" +fi +core="${version%%-*}" + +if [[ "$write_pubspec" == "true" ]]; then + if [[ ! -f "$pubspec" ]]; then + echo "error: $pubspec not found" >&2 + exit 1 + fi + # awk (rather than sed -i) behaves the same on Linux, macOS (BSD) and + # Windows (Git Bash), with one exception: Git for Windows' awk drops the CR + # of a CRLF line as it reads it, so it cannot tell a CRLF file (as Windows + # checkouts usually are) from an LF one. So the line ending is detected from + # the raw bytes with od, and awk strips any CR it does see and writes every + # line with that ending. msix_version keeps its indentation. Each line must + # be found exactly once, or the pubspec is left untouched. + # Escape sequences, which awk -v expands (a literal newline in a -v value + # is an error in some awks). + eol='\n' + if od -An -c "$pubspec" | grep -q '\\r'; then eol='\r\n'; fi + tmp="$(mktemp)" + trap 'rm -f "$tmp"' EXIT + awk -v version="${version}+${build_number}" -v msix="$msix_version" -v eol="$eol" ' + BEGIN { ORS = eol } + { sub(/\r$/, "") } + /^version:/ { print "version: " version; v++; next } + /^[ \t]+msix_version:/ { match($0, /^[ \t]+/) + print substr($0, 1, RLENGTH) "msix_version: " msix + m++; next } + { print } + END { if (v != 1 || m != 1) { print "matched version:" v+0 " msix_version:" m+0 > "/dev/stderr"; exit 1 } } + ' "$pubspec" >"$tmp" || { + echo "error: expected exactly one top-level 'version:' and one indented 'msix_version:' line in $pubspec" >&2 + exit 1 + } + cat "$tmp" >"$pubspec" +fi + +echo "WIMSY_VERSION=${version}" +echo "WIMSY_VERSION_CORE=${core}" +echo "WIMSY_BUILD_NUMBER=${build_number}" +echo "WIMSY_MSIX_VERSION=${msix_version}" diff --git a/tool/fetch_release_history.sh b/tool/fetch_release_history.sh new file mode 100755 index 00000000..0ee77b7b --- /dev/null +++ b/tool/fetch_release_history.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# Fetches what tool/build_version.sh needs from git: the release tags in +# HEAD's history, and, in a shallow clone, only as much history as it takes +# to reach the last final release. +# +# Usage: tool/fetch_release_history.sh [REMOTE] +# REMOTE defaults to origin. +# +# CI systems typically check out a shallow (often depth-1) clone without tags, +# so the last release cannot be found from HEAD. Fetching full history works +# but grows with the repository; this instead: +# 1. lists the remote's v* tags and the commits they point to +# (git ls-remote: no history is downloaded); +# 2. if HEAD's history is cut off, fetches more of it in steps of +# WIMSY_HISTORY_STEP commits (default 20) until it contains the commit of +# a final release tag (vX.Y.Z, no -pre-release part), or HEAD's whole +# history is present and no final release is in it; +# 3. fetches every release tag (final or pre-release) whose commit is in +# HEAD's history, so tags are present even in a full clone made without +# them. +# +# HEAD is fetched by commit id, so a detached HEAD (e.g. a pull request +# merge commit) works too. No tag is fetched unless its commit is already in +# HEAD's history, so tags elsewhere add no shallow boundaries of their own. +set -euo pipefail + +# shellcheck source=tool/release_tags.sh +source "$(dirname "${BASH_SOURCE[0]}")/release_tags.sh" + +remote="${1:-origin}" +step="${WIMSY_HISTORY_STEP:-20}" + +if [[ ! "$step" =~ ^[1-9][0-9]*$ ]]; then + echo "error: WIMSY_HISTORY_STEP must be a positive integer, got '$step'" >&2 + exit 1 +fi + +# " " for every release tag on the remote. Annotated tags are +# listed twice by ls-remote, the second time peeled (name^{}) to the commit +# they point at; the peeled id is the one that appears in history. +tag_commits="$(git ls-remote --tags "$remote" 'refs/tags/v*' | awk ' + { ref = $2; sub(/^refs\/tags\//, "", ref) + if (ref ~ /\^\{\}$/) { sub(/\^\{\}$/, "", ref); peeled[ref] = $1 } + else { plain[ref] = $1 } } + END { for (r in plain) print (r in peeled ? peeled[r] : plain[r]), r }' | + while read -r commit tag; do + if is_release_tag "$tag"; then echo "$commit $tag"; fi + done)" +final_commits="$(while read -r commit tag; do + if [[ -n "$tag" ]] && is_final_tag "$tag"; then echo "$commit"; fi +done <<<"$tag_commits")" + +# tags_in_history: the tags of tag_commits whose commits are in HEAD's +# history as fetched so far, one per line (one pass over history). +tags_in_history() { + awk 'NR == FNR { seen[$1]; next } ($1 in seen) { print $2 }' \ + <(git rev-list HEAD) <(printf '%s\n' "$tag_commits") +} +final_in_history() { + [[ -n "$final_commits" ]] && grep -qxF -f <(printf '%s\n' "$final_commits") <(git rev-list HEAD) +} + +# HEAD is fetched again with an absolute depth that grows by step each +# time, rather than with --deepen. GitHub will not deepen a commit that no ref +# points to any more, which is what a pull request run checks out once the +# base branch has moved on (GitHub then replaces the merge commit), but it +# does serve such a commit at a given depth. +# +# The starting depth is HEAD's commit count, which is at least the depth the +# clone was made with: asking for less than a clone already has would cut its +# history back rather than extend it. +head="$(git rev-parse HEAD)" +depth="$(git rev-list --count HEAD)" +while head_is_shallow && ! final_in_history; do + before="$(git rev-list --count HEAD)" + depth=$((depth + step)) + git fetch --quiet --depth="$depth" "$remote" "$head" + # No new commits is fine if the fetch only cleared the shallow marker on a + # root commit (git can leave one there when the depth ends exactly at the + # root); it is an error if HEAD's history is still cut off. + if [[ "$(git rev-list --count HEAD)" == "$before" ]] && head_is_shallow; then + echo "error: fetching more of HEAD's history ($head) from $remote" \ + "fetched no new commits; giving up" >&2 + exit 1 + fi +done + +# Their commits are already present, so this transfers only the tag refs +# (and annotated tag objects). +refspecs=() +while read -r tag; do + if [[ -n "$tag" ]]; then refspecs+=("+refs/tags/$tag:refs/tags/$tag"); fi +done <<<"$(tags_in_history)" +if ((${#refspecs[@]} > 0)); then + git fetch --quiet --no-tags "$remote" "${refspecs[@]}" +fi +echo "HEAD has $(git rev-list --count HEAD) commit(s) of history; fetched ${#refspecs[@]} release tag(s) in it." >&2 diff --git a/tool/release_tags.sh b/tool/release_tags.sh new file mode 100644 index 00000000..22340bc2 --- /dev/null +++ b/tool/release_tags.sh @@ -0,0 +1,35 @@ +# Definitions shared by tool/build_version.sh and +# tool/fetch_release_history.sh, so the two agree on what a release tag is +# and on when history is incomplete. Source this file; do not run it. +# shellcheck shell=bash + +# A semver 2.0.0 version (https://semver.org), as an extended regex: +# X.Y.Z without leading zeros, an optional -pre-release and an optional +# +build part, each made of dot-separated [0-9A-Za-z-] identifiers (numeric +# pre-release identifiers without leading zeros). +semver_num='(0|[1-9][0-9]*)' +semver_pre_id="($semver_num|[0-9]*[A-Za-z-][0-9A-Za-z-]*)" +semver_build_id='[0-9A-Za-z-]+' +SEMVER_ERE="^$semver_num\\.$semver_num\\.$semver_num(-$semver_pre_id(\\.$semver_pre_id)*)?(\\+$semver_build_id(\\.$semver_build_id)*)?\$" +unset semver_num semver_pre_id semver_build_id + +# is_release_tag TAG: TAG is v followed by a semver version. +is_release_tag() { + [[ "$1" == v* && "${1#v}" =~ $SEMVER_ERE ]] +} + +# is_final_tag TAG: TAG is a release tag without a -pre-release part (build +# metadata, which may itself contain hyphens, is allowed). +is_final_tag() { + is_release_tag "$1" && [[ "${1%%+*}" != *-* ]] +} + +# head_is_shallow: true while HEAD's history is cut off, i.e. some commit in +# it is a shallow boundary. Whether the repository as a whole is shallow is +# not the question: another ref's shallow tip (e.g. the branch originally +# cloned) keeps that true even once HEAD's history is complete. +head_is_shallow() { + local shallow_file + shallow_file="$(git rev-parse --git-path shallow)" + [[ -s "$shallow_file" ]] && grep -qxF -f "$shallow_file" <(git rev-list HEAD) +} diff --git a/tool/test_build_version.sh b/tool/test_build_version.sh new file mode 100755 index 00000000..79ba0e91 --- /dev/null +++ b/tool/test_build_version.sh @@ -0,0 +1,377 @@ +#!/usr/bin/env bash +# Tests for tool/build_version.sh and tool/fetch_release_history.sh. Runs +# against throwaway git repositories, so it needs no network access and never +# touches the real checkout. +# +# Usage: bash tool/test_build_version.sh +set -euo pipefail +# Byte-wise string comparison and sorting, whatever the developer's locale. +export LC_ALL=C + +tool_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +build_version="$tool_dir/build_version.sh" +fetch_history="$tool_dir/fetch_release_history.sh" +work="$(mktemp -d)" +trap 'rm -rf "$work"' EXIT + +failures=0 +check() { # check DESCRIPTION EXPECTED ACTUAL + if [[ "$2" == "$3" ]]; then + echo "ok: $1" + else + echo "FAIL: $1"$'\n'" expected: $2"$'\n'" actual: $3" >&2 + failures=$((failures + 1)) + fi +} + +fixture_pubspec='name: wimsy +version: 0.0.2 + +dependencies: + flutter: + sdk: flutter + +msix_config: + display_name: Wimsy + msix_version: 0.0.2.0 + sign_msix: false' + +# new_repo DIR: a git repo with the fixture pubspec and one commit. +new_repo() { + mkdir -p "$1" + git -C "$1" init -q + git -C "$1" config user.email test@example.invalid + git -C "$1" config user.name test + git -C "$1" config commit.gpgsign false + git -C "$1" config tag.gpgsign false + printf '%s\n' "$fixture_pubspec" >"$1/pubspec.yaml" + git -C "$1" add pubspec.yaml + git -C "$1" commit -q -m initial +} +commit() { git -C "$1" commit -q --allow-empty -m "$2"; } +sha() { git -C "$1" rev-parse --short HEAD; } +line() { grep "^ *$2:" "$1/pubspec.yaml" | sed -E 's/^ *[a-z_]+: //'; } +# value OUTPUT KEY: the value of KEY in build_version.sh output. +value() { grep "^$2=" <<<"$1" | cut -d= -f2-; } + +# bv DIR ARGS...: run build_version.sh in DIR. +bv() { + local dir="$1" + shift + (cd "$dir" && bash "$build_version" "$@") +} + +# shallow_clone ORIGIN DEST: a depth-1, tagless clone, as CI checks out. +shallow_clone() { git clone -q --depth 1 --no-tags "$(file_url "$1")" "$2"; } +# full_clone_no_tags ORIGIN DEST: full history, but no tags. +full_clone_no_tags() { git clone -q --no-tags "$(file_url "$1")" "$2"; } +file_url() { + # Git for Windows needs a native path in the file:// URL. + if command -v cygpath >/dev/null 2>&1; then + echo "file:///$(cygpath -m "$1")" + else + echo "file://$1" + fi +} + +# --- No tags: pre-release from 0.0.0; nothing written by default --- +r="$work/notags" +new_repo "$r" +out="$(bv "$r" --build-number 7)" +check "no tags: output" "WIMSY_VERSION=0.0.0-pre-$(sha "$r") +WIMSY_VERSION_CORE=0.0.0 +WIMSY_BUILD_NUMBER=7 +WIMSY_MSIX_VERSION=0.0.0.7" "$out" +check "no tags: pubspec not written without --write-pubspec" "$fixture_pubspec" "$(cat "$r/pubspec.yaml")" +check "no tags: working tree clean" "" "$(git -C "$r" status --porcelain)" + +# --- Pre-release after tags, written to pubspec --- +r="$work/pre" +new_repo "$r" +git -C "$r" tag v0.0.5 +commit "$r" second +git -C "$r" tag v0.0.6 +commit "$r" third +out="$(bv "$r" --tag "" --build-number 12 --write-pubspec)" +check "pre-release: version" "0.0.6-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +check "pre-release: core" "0.0.6" "$(value "$out" WIMSY_VERSION_CORE)" +check "pre-release: msix" "0.0.6.12" "$(value "$out" WIMSY_MSIX_VERSION)" +check "pre-release: pubspec version" "0.0.6-pre-$(sha "$r")+12" "$(line "$r" version)" +check "pre-release: pubspec msix_version" "0.0.6.12" "$(line "$r" msix_version)" +check "pre-release: rest of pubspec untouched" \ + "$(printf '%s\n' "$fixture_pubspec" | grep -v 'version:')" \ + "$(grep -v 'version:' "$r/pubspec.yaml")" + +# --- Release builds --- +r="$work/release" +new_repo "$r" +out="$(bv "$r" --tag v0.0.7 --build-number 13 --write-pubspec)" +check "release: version" "0.0.7" "$(value "$out" WIMSY_VERSION)" +check "release: core" "0.0.7" "$(value "$out" WIMSY_VERSION_CORE)" +check "release: msix" "0.0.7.0" "$(value "$out" WIMSY_MSIX_VERSION)" +check "release: pubspec version" "0.0.7+13" "$(line "$r" version)" +check "release: tag without v" "0.0.7" "$(value "$(bv "$r" --tag 0.0.7)" WIMSY_VERSION)" +check "release: build 70000 keeps a .0 MSIX field" "0.0.8.0" \ + "$(value "$(bv "$r" --tag v0.0.8 --build-number 70000)" WIMSY_MSIX_VERSION)" +git -C "$r" tag v1.2.2 +out="$(bv "$r" --tag v1.2.3-rc1 --build-number 5)" +check "rc tag: version" "1.2.3-rc1" "$(value "$out" WIMSY_VERSION)" +check "rc tag: core" "1.2.3" "$(value "$out" WIMSY_VERSION_CORE)" +# Numbered after the last final release, so the final 1.2.3.0 upgrades it. +check "rc tag: msix based on last final release" "1.2.2.5" "$(value "$out" WIMSY_MSIX_VERSION)" +check "rc tag with build number over MSIX limit: fails" "1" \ + "$(bv "$r" --tag v1.2.3-rc1 --build-number 65536 >/dev/null 2>&1 && echo 0 || echo 1)" +check "default build number" "1" "$(value "$(bv "$r" --tag v0.0.7)" WIMSY_BUILD_NUMBER)" + +# --- Pre-release after an -rc tag: MSIX is based on the last final release --- +r="$work/afterrc" +new_repo "$r" +git -C "$r" tag v1.0.0 +commit "$r" second +git -C "$r" tag v1.1.0-rc1 +commit "$r" third +out="$(bv "$r" --build-number 40)" +check "after rc tag: version" "1.1.0-rc1-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +check "after rc tag: msix based on last final release" "1.0.0.40" "$(value "$out" WIMSY_MSIX_VERSION)" + +# --- Base is the higher of the nearest tag and the highest final release --- +# An older release merged back in after a newer one, nearer to HEAD. +# git describe walks history by commit date, so the commits get increasing +# dates for it to find the nearer, older tag. +r="$work/mergeback" +new_repo "$r" +minute=0 +dated_commit() { + minute=$((minute + 1)) + GIT_COMMITTER_DATE="2030-01-01T00:$(printf %02d "$minute"):00Z" \ + GIT_AUTHOR_DATE="2030-01-01T00:$(printf %02d "$minute"):00Z" "$@" +} +main_branch="$(git -C "$r" symbolic-ref --short HEAD)" +dated_commit commit "$r" "main" +git -C "$r" tag v2.0.0 +git -C "$r" checkout -q -b maint HEAD~1 +for i in 1 2 3; do dated_commit commit "$r" "maint $i"; done +git -C "$r" tag v1.0.1 +git -C "$r" checkout -q "$main_branch" +dated_commit git -C "$r" merge -q --no-ff -m "merge maint" maint +check "merge-back: git describe does pick the older tag" "v1.0.1" \ + "$(git -C "$r" describe --tags --abbrev=0 --match 'v[0-9]*')" +out="$(bv "$r" --build-number 6)" +check "merge-back: based on the higher release" "2.0.0-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +check "merge-back: msix agrees" "2.0.0.6" "$(value "$out" WIMSY_MSIX_VERSION)" + +# An rc superseded by its final release on the same commit. The rc tag is +# dated later, so git describe picks it over the final one. +r="$work/superseded" +new_repo "$r" +GIT_COMMITTER_DATE="2030-01-01T00:00:00Z" git -C "$r" tag -a v2.0.0 -m final +GIT_COMMITTER_DATE="2030-01-02T00:00:00Z" git -C "$r" tag -a v2.0.0-rc1 -m rc +commit "$r" second +check "superseded rc: git describe does pick the rc" "v2.0.0-rc1" \ + "$(git -C "$r" describe --tags --abbrev=0 --match 'v[0-9]*')" +check "superseded rc: based on the final release" "2.0.0-pre-$(sha "$r")" \ + "$(value "$(bv "$r" --build-number 3)" WIMSY_VERSION)" + +# An rc with no final release at all is not superseded by the implicit 0.0.0. +r="$work/onlyrc" +new_repo "$r" +git -C "$r" tag v0.0.0-rc1 +commit "$r" second +out="$(bv "$r" --build-number 2)" +check "only an rc tag: based on it" "0.0.0-rc1-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +check "only an rc tag: msix" "0.0.0.2" "$(value "$out" WIMSY_MSIX_VERSION)" + +# A v-prefixed tag that is not a release version is ignored. +r="$work/badtag" +new_repo "$r" +git -C "$r" tag v1.2 +commit "$r" second +check "non-semver tag ignored" "0.0.0-pre-$(sha "$r")" "$(value "$(bv "$r")" WIMSY_VERSION)" + +# --- Build metadata on the base tag is dropped --- +r="$work/basemeta" +new_repo "$r" +git -C "$r" tag v1.2.3+meta-x +commit "$r" second +out="$(bv "$r" --build-number 3)" +check "base tag +metadata: dropped" "1.2.3-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +check "base tag +metadata: msix" "1.2.3.3" "$(value "$out" WIMSY_MSIX_VERSION)" + +# --- pubspec formatting is preserved --- +r="$work/indent" +new_repo "$r" +sed 's/^ msix_version:/ msix_version:/' "$r/pubspec.yaml" >"$r/p" && mv "$r/p" "$r/pubspec.yaml" +bv "$r" --tag v0.0.9 --write-pubspec >/dev/null +check "4-space msix_version indent preserved" " msix_version: 0.0.9.0" "$(grep msix_version "$r/pubspec.yaml")" + +# CRLF (Windows checkouts). Checked as raw bytes: on Windows, text tools +# (awk, grep, sed, and $(...) itself) may translate CRLF as they read, which +# would hide the very thing being checked. The fixture and the expected +# result are written with bash's printf, and compared through od, which reads +# bytes as they are. +# as_crlf [VERSION_LINE MSIX_LINE]: the fixture pubspec with CRLF endings, +# optionally with its version and msix_version lines replaced. +as_crlf() { + local l + while IFS= read -r l; do + case "$l" in + "version: "*) l="${1:-$l}" ;; + " msix_version: "*) l="${2:-$l}" ;; + esac + printf '%s\r\n' "$l" + done <<<"$fixture_pubspec" +} +hex() { od -An -tx1 -v | tr -d ' \n'; } +r="$work/crlf" +new_repo "$r" +as_crlf >"$r/pubspec.yaml" +bv "$r" --tag v0.1.0 --write-pubspec >/dev/null +check "CRLF: rewritten pubspec is exactly the expected CRLF bytes" \ + "$(as_crlf "version: 0.1.0+1" " msix_version: 0.1.0.0" | hex)" \ + "$(hex <"$r/pubspec.yaml")" + +r="$work/otherpath" +new_repo "$r" +cp "$r/pubspec.yaml" "$r/other.yaml" +bv "$r" --tag v0.2.0 --write-pubspec --pubspec other.yaml >/dev/null +check "--pubspec: named file written" "0.2.0+1" "$(grep '^version:' "$r/other.yaml" | cut -d' ' -f2)" +check "--pubspec: default file untouched" "0.0.2" "$(line "$r" version)" + +# --- Shallow CI-style clones --- +# A depth-1, tagless clone of a repo with a few releases and some commits +# after the last one. +origin="$work/origin" +new_repo "$origin" +git -C "$origin" tag v0.0.4 +for i in $(seq 1 30); do commit "$origin" "pre-0.0.5 $i"; done +git -C "$origin" tag v0.0.5 +for i in $(seq 1 30); do commit "$origin" "pre-0.0.6 $i"; done +# Annotated, so ls-remote reports it with a separate peeled (^{}) line. +git -C "$origin" tag -a v0.0.6 -m "Release 0.0.6" +for i in $(seq 1 25); do commit "$origin" "after 0.0.6 $i"; done +total="$(git -C "$origin" rev-list --count HEAD)" + +r="$work/shallow-unfetched" +shallow_clone "$origin" "$r" +check "shallow: clone starts shallow" "true" "$(git -C "$r" rev-parse --is-shallow-repository)" +status=0 +err="$(bv "$r" --build-number 9 2>&1 >/dev/null)" || status=$? +check "shallow, history not fetched: fails instead of guessing 0.0.0" "1" "$status" +check "shallow, history not fetched: says what to do" "1" "$(grep -c fetch_release_history <<<"$err")" +status=0 +bv "$r" --tag v0.0.6 >/dev/null || status=$? +check "shallow, release build: needs no history" "0" "$status" + +r="$work/shallow" +shallow_clone "$origin" "$r" +(cd "$r" && WIMSY_HISTORY_STEP=10 bash "$fetch_history" 2>/dev/null) +out="$(bv "$r" --build-number 9)" +check "fetched: last tag found" "0.0.6-pre-$(sha "$r")" "$(value "$out" WIMSY_VERSION)" +fetched="$(git -C "$r" rev-list --count HEAD)" +check "fetched: only history back to the last tag (fetched $fetched of $total)" "yes" \ + "$( ((fetched <= 26 + 10 && fetched < total)) && echo yes || echo no)" +check "fetched: still shallow" "true" "$(git -C "$r" rev-parse --is-shallow-repository)" + +# A clone deeper than depth 1 (e.g. a CI checkout with a larger fetch depth). +r="$work/shallow-deeper" +git clone -q --depth 15 --no-tags "$(file_url "$origin")" "$r" +status=0 +(cd "$r" && WIMSY_HISTORY_STEP=2 bash "$fetch_history" 2>/dev/null) || status=$? +check "fetched, depth-15 clone: fetch succeeds" "0" "$status" +check "fetched, depth-15 clone: last tag found" "0.0.6-pre-$(sha "$r")" \ + "$(value "$(bv "$r" 2>/dev/null)" WIMSY_VERSION)" + +r="$work/shallow-detached" +shallow_clone "$origin" "$r" +git -C "$r" checkout -q --detach +(cd "$r" && bash "$fetch_history" 2>/dev/null) +check "fetched, detached HEAD (PR merge commit): last tag found" "0.0.6-pre-$(sha "$r")" \ + "$(value "$(bv "$r")" WIMSY_VERSION)" + +# A pull request merge commit that no ref points to any more: GitHub replaces +# it when the base branch moves, but a run created before that still checks +# it out by id. GitHub serves it by id but will not deepen it with --deepen; +# local git does deepen it, so this cannot catch that, but it does check that +# the fetch works on such a commit. +git -C "$origin" config uploadpack.allowAnySHA1InWant true +tree="$(git -C "$origin" rev-parse 'HEAD^{tree}')" +pr_commit="$(git -C "$origin" commit-tree -p HEAD -m "pull request change" "$tree")" +stale_merge="$(git -C "$origin" commit-tree -p HEAD -p "$pr_commit" -m "stale merge" "$tree")" +r="$work/shallow-stale-merge" +shallow_clone "$origin" "$r" +git -C "$r" fetch -q --depth 1 origin "$stale_merge" +git -C "$r" checkout -q --detach "$stale_merge" +status=0 +(cd "$r" && WIMSY_HISTORY_STEP=10 bash "$fetch_history" 2>/dev/null) || status=$? +check "fetched, unreferenced merge commit: fetch succeeds" "0" "$status" +check "fetched, unreferenced merge commit: last tag found" "0.0.6-pre-$(sha "$r")" \ + "$(value "$(bv "$r" 2>/dev/null)" WIMSY_VERSION)" + +notags_origin="$work/notags-origin" +new_repo "$notags_origin" +for i in $(seq 1 5); do commit "$notags_origin" "c$i"; done +r="$work/shallow-notags" +shallow_clone "$notags_origin" "$r" +status=0 +(cd "$r" && WIMSY_HISTORY_STEP=2 bash "$fetch_history" 2>/dev/null) || status=$? +check "no tags anywhere: fetch succeeds" "0" "$status" +check "no tags anywhere: fetches everything" "false" "$(git -C "$r" rev-parse --is-shallow-repository)" +check "no tags anywhere: 0.0.0 pre-release" "0.0.0-pre-$(sha "$r")" "$(value "$(bv "$r")" WIMSY_VERSION)" + +# A branch whose history holds no tag, on a remote that has tags elsewhere +# (e.g. an orphan branch). This must terminate with HEAD's full history, and +# must not fetch the unrelated tags. +origin_branch="$(git -C "$origin" symbolic-ref --short HEAD)" +git -C "$origin" checkout -q --orphan unrelated +git -C "$origin" commit -q --allow-empty -m "orphan root" +for i in $(seq 1 4); do commit "$origin" "orphan $i"; done +git -C "$origin" checkout -q "$origin_branch" +r="$work/shallow-orphan" +shallow_clone "$origin" "$r" +git -C "$r" fetch -q --depth 1 origin unrelated +git -C "$r" checkout -q FETCH_HEAD +status=0 +(cd "$r" && WIMSY_HISTORY_STEP=2 bash "$fetch_history" 2>/dev/null) || status=$? +check "unrelated tags: fetch terminates successfully" "0" "$status" +check "unrelated tags: HEAD history complete (root + 4)" "5" "$(git -C "$r" rev-list --count HEAD)" +check "unrelated tags: no tags fetched" "" "$(git -C "$r" tag)" +check "unrelated tags: 0.0.0 pre-release" "0.0.0-pre-$(sha "$r")" "$(value "$(bv "$r")" WIMSY_VERSION)" + +r="$work/full-notags" +full_clone_no_tags "$origin" "$r" +check "full clone without tags: starts with no tags" "" "$(git -C "$r" tag)" +(cd "$r" && bash "$fetch_history" 2>/dev/null) +check "full clone without tags: release tags fetched" "v0.0.4 v0.0.5 v0.0.6" "$(git -C "$r" tag | tr '\n' ' ' | sed 's/ $//')" +check "full clone without tags: version" "0.0.6-pre-$(sha "$r")" "$(value "$(bv "$r")" WIMSY_VERSION)" + +# --- Failures leave the pubspec untouched --- +expect_failure() { # expect_failure DESCRIPTION DIR ARGS... + local desc="$1" dir="$2" + shift 2 + local before status=0 + before="$(cat "$dir/pubspec.yaml")" + bv "$dir" "$@" >/dev/null 2>&1 || status=$? + check "$desc: exits non-zero" "nonzero" "$([[ $status -ne 0 ]] && echo nonzero || echo zero)" + check "$desc: pubspec unchanged" "$before" "$(cat "$dir/pubspec.yaml")" +} + +r="$work/fail" +new_repo "$r" +expect_failure "build number 0" "$r" --build-number 0 --write-pubspec +expect_failure "non-numeric build number" "$r" --build-number abc --write-pubspec +expect_failure "non-numeric tag" "$r" --tag vnext --write-pubspec +expect_failure "tag with leading zeros" "$r" --tag v1.08.3 --write-pubspec +expect_failure "tag with empty pre-release" "$r" --tag v1.2.3- --write-pubspec +expect_failure "tag with a space" "$r" --tag "v1.2.3-rc 1" --write-pubspec +expect_failure "tag with +build metadata" "$r" --tag v1.2.3+hotfix --write-pubspec +expect_failure "pre-release build number over MSIX limit" "$r" --build-number 65536 --write-pubspec +expect_failure "unknown argument" "$r" --frobnicate +expect_failure "missing option value" "$r" --tag +grep -v msix_version "$r/pubspec.yaml" >"$r/p" && mv "$r/p" "$r/pubspec.yaml" +expect_failure "missing msix_version line" "$r" --write-pubspec + +if ((failures > 0)); then + echo "$failures check(s) failed" >&2 + exit 1 +fi +echo "All checks passed" diff --git a/tool/verify_macos_dmg.sh b/tool/verify_macos_dmg.sh index 37ff2348..9fe601a1 100755 --- a/tool/verify_macos_dmg.sh +++ b/tool/verify_macos_dmg.sh @@ -1,10 +1,12 @@ #!/usr/bin/env bash # Verifies a macOS release DMG produced by tool/package_macos_dmg.sh. # -# Usage: tool/verify_macos_dmg.sh DMG_PATH [EXPECTED_VERSION] +# Usage: tool/verify_macos_dmg.sh DMG_PATH [EXPECTED_VERSION [EXPECTED_BUILD]] # DMG_PATH the DMG to check # EXPECTED_VERSION optional; if given, wimsy.app's CFBundleShortVersionString # must equal it exactly +# EXPECTED_BUILD optional; if given, wimsy.app's CFBundleVersion must equal +# it exactly # # Checks (all must pass; every failure is reported before exiting non-zero): # - the image passes hdiutil verify and mounts read-only @@ -12,7 +14,8 @@ # symlink (hidden volume metadata such as .fseventsd is ignored) # - wimsy.app passes codesign --verify --deep --strict # - the main executable is universal (x86_64 and arm64) -# - the bundle version matches EXPECTED_VERSION, when given +# - the bundle version and build number match EXPECTED_VERSION and +# EXPECTED_BUILD, when given # # These checks hold for both the current ad-hoc signed build and a future # Developer ID signed and notarized build. Checks specific to Developer ID @@ -20,8 +23,9 @@ # stapler) belong with the change that introduces that signing. set -euo pipefail -dmg_path="${1:?usage: $0 DMG_PATH [EXPECTED_VERSION]}" +dmg_path="${1:?usage: $0 DMG_PATH [EXPECTED_VERSION [EXPECTED_BUILD]]}" expected_version="${2:-}" +expected_build="${3:-}" app_name="wimsy.app" failures=0 @@ -83,15 +87,19 @@ else fail "codesign --verify --deep --strict" fi - executable="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleExecutable' "$app/Contents/Info.plist")" - archs="$(lipo -archs "$app/Contents/MacOS/$executable")" + # plist_value KEY: the Info.plist value, or empty if missing (reported as + # a failure by the checks below rather than aborting under set -e). + plist_value() { /usr/libexec/PlistBuddy -c "Print :$1" "$app/Contents/Info.plist" 2>/dev/null || true; } + + executable="$(plist_value CFBundleExecutable)" + archs="$(lipo -archs "$app/Contents/MacOS/$executable" 2>/dev/null || true)" if [[ " $archs " == *" x86_64 "* && " $archs " == *" arm64 "* ]]; then pass "universal executable ($archs)" else fail "executable is not universal: $archs" fi - version="$(/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' "$app/Contents/Info.plist")" + version="$(plist_value CFBundleShortVersionString)" if [[ -z "$expected_version" ]]; then echo "skip: version check (no expected version given; bundle has $version)" elif [[ "$version" == "$expected_version" ]]; then @@ -99,6 +107,15 @@ else else fail "bundle version $version, expected $expected_version" fi + + build="$(plist_value CFBundleVersion)" + if [[ -z "$expected_build" ]]; then + echo "skip: build number check (no expected build given; bundle has $build)" + elif [[ "$build" == "$expected_build" ]]; then + pass "bundle build number $build" + else + fail "bundle build number $build, expected $expected_build" + fi fi if ((failures > 0)); then