From 001253cebe8655a27fdf344fe3f36a72f12fe539 Mon Sep 17 00:00:00 2001 From: Kevin Song Date: Sun, 1 Oct 2023 01:59:34 -0500 Subject: [PATCH] ci: Fix how version is obtained for pkgbuild (#5443) * fix: Change how starship version is determined * Add STARSHIP_VERSION envar into CI for notarization * More strict! * Supress pushd/popd output * Fix shellcheck issue with quoting --- .github/workflows/release.yml | 1 + .../macos_packages/build_component_package.sh | 2 +- install/macos_packages/common.sh | 20 +++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2baabd03..20ef4ed0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -176,6 +176,7 @@ jobs: env: KEYCHAIN_FILENAME: app-signing.keychain-db KEYCHAIN_ENTRY: AC_PASSWORD + STARSHIP_VERSION: ${{ needs.release_please.outputs.tag_name }} steps: - name: Checkout repository uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 diff --git a/install/macos_packages/build_component_package.sh b/install/macos_packages/build_component_package.sh index 634f9f4d..807e5056 100644 --- a/install/macos_packages/build_component_package.sh +++ b/install/macos_packages/build_component_package.sh @@ -87,4 +87,4 @@ trap - INT # Build the component package version="$(starship_version "$starship_program_file")" -pkgbuild --identifier com.starshipprompt.starship --version "$version" --root $pkgdir starship-component.pkg +pkgbuild --identifier com.starshipprompt.starship --version "$version" --root "$pkgdir" starship-component.pkg diff --git a/install/macos_packages/common.sh b/install/macos_packages/common.sh index f69d05d0..a7efb2c3 100644 --- a/install/macos_packages/common.sh +++ b/install/macos_packages/common.sh @@ -11,12 +11,20 @@ starship_version() { if [ "$1" = "${1#/}" ]; then starship_program_file="./$starship_program_file" fi - if "$starship_program_file" -V 2>&1 >/dev/null; then - "$starship_program_file" -V | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' + + # Try to get the version from three sources in the following order: + # - the STARSHIP_VERSION envar (usually set by the CI) + # - Running the binary file + # - By cutting out the first version tag in Cargo.toml + # These get increasingly fragile as we go down the list---ideally CI should + # always run with STARSHIP_VERSION set to avoid issues in determining version. + if [ "$STARSHIP_VERSION" != "" ]; then + echo "$STARSHIP_VERSION" | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' + elif "$starship_program_file" -V >/dev/null 2>&1; then + "$starship_program_file" -V 2> /dev/null | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' else - # try to get this information from Cargo.toml - pushd "$(git rev-parse --show-toplevel)" || true - grep '^version = \"\(.*\)\"' Cargo.toml | cut -f 2 -d '"' - popd + pushd "$(git rev-parse --show-toplevel)" &> /dev/null || true + grep '^version = \"\(.*\)\"' Cargo.toml | head -n 1 | cut -f 2 -d '"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+' + popd &> /dev/null || true fi }