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
This commit is contained in:
Kevin Song 2023-10-01 01:59:34 -05:00 committed by GitHub
parent 8168c21293
commit 001253cebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 7 deletions

View File

@ -176,6 +176,7 @@ jobs:
env: env:
KEYCHAIN_FILENAME: app-signing.keychain-db KEYCHAIN_FILENAME: app-signing.keychain-db
KEYCHAIN_ENTRY: AC_PASSWORD KEYCHAIN_ENTRY: AC_PASSWORD
STARSHIP_VERSION: ${{ needs.release_please.outputs.tag_name }}
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4 uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4

View File

@ -87,4 +87,4 @@ trap - INT
# Build the component package # Build the component package
version="$(starship_version "$starship_program_file")" 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

View File

@ -11,12 +11,20 @@ starship_version() {
if [ "$1" = "${1#/}" ]; then if [ "$1" = "${1#/}" ]; then
starship_program_file="./$starship_program_file" starship_program_file="./$starship_program_file"
fi 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 else
# try to get this information from Cargo.toml pushd "$(git rev-parse --show-toplevel)" &> /dev/null || true
pushd "$(git rev-parse --show-toplevel)" || true grep '^version = \"\(.*\)\"' Cargo.toml | head -n 1 | cut -f 2 -d '"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+'
grep '^version = \"\(.*\)\"' Cargo.toml | cut -f 2 -d '"' popd &> /dev/null || true
popd
fi fi
} }