Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error messages in
check-release.sh
- `check_tag`: Report file name correctly. Use named variables. - Introduce `read_version` helper function. Simplify the implementation. - Show meaningful error message if `GITHUB_REF` is not set or its format is incorrect.
- Loading branch information
Showing
1 changed file
with
33 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# check_tag $current_tag $file_tag $file_name | ||
function check_tag { | ||
if [[ "$1" != "$2" ]]; then | ||
echo "Error: the current tag does not match the version in Cargo.toml: found $2 - expected $1" | ||
ret=1 | ||
fi | ||
#!/usr/bin/env bash | ||
set -eu -o pipefail | ||
|
||
check_tag() { | ||
local expected=$1 | ||
local actual=$2 | ||
local filename=$3 | ||
|
||
if [[ $actual != $expected ]]; then | ||
echo >&2 "Error: the current tag does not match the version in $filename: found $actual, expected $expected" | ||
return 1 | ||
fi | ||
} | ||
|
||
read_version() { | ||
grep '^version = ' | cut -d \" -f 2 | ||
} | ||
|
||
if [[ -z "${GITHUB_REF:-}" ]]; then | ||
echo >&2 "Error: GITHUB_REF is not set" | ||
exit 1 | ||
fi | ||
|
||
if [[ ! "$GITHUB_REF" =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+(-[a-z0-9]+)?$ ]]; then | ||
echo >&2 "Error: GITHUB_REF is not a valid tag: $GITHUB_REF" | ||
exit 1 | ||
fi | ||
|
||
current_tag=${GITHUB_REF#refs/tags/v} | ||
ret=0 | ||
current_tag=${GITHUB_REF#'refs/tags/v'} | ||
|
||
file_tag="$(grep '^version = ' Cargo.toml | cut -d '=' -f 2 | tr -d '"' | tr -d ' ')" | ||
check_tag $current_tag $file_tag | ||
toml_tag="$(cat Cargo.toml | read_version)" | ||
check_tag "$current_tag" "$toml_tag" Cargo.toml || ret=1 | ||
|
||
lock_file='Cargo.lock' | ||
lock_tag=$(grep -A 1 'name = "meilisearch-auth"' $lock_file | grep version | cut -d '=' -f 2 | tr -d '"' | tr -d ' ') | ||
check_tag $current_tag $lock_tag $lock_file | ||
lock_tag=$(grep -A 1 '^name = "meilisearch-auth"' Cargo.lock | read_version) | ||
check_tag "$current_tag" "$lock_tag" Cargo.lock || ret=1 | ||
|
||
if [[ "$ret" -eq 0 ]] ; then | ||
echo 'OK' | ||
if (( ret == 0 )); then | ||
echo 'OK' | ||
fi | ||
exit $ret |