Skip to content

Commit

Permalink
Revise .github/scripts/check-release.sh
Browse files Browse the repository at this point in the history
- Introduce `read_version` helper function. Simplify the implementation.
- Use named variables in `check_tag`. Report file name correctly.
  • Loading branch information
vvv committed May 31, 2023
1 parent b2dee07 commit d8d2cd0
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions .github/scripts/check-release.sh
@@ -1,24 +1,31 @@
#!/bin/bash
#!/usr/bin/env bash
set -eu -o pipefail

# 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
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
}

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
file_tag="$(cat Cargo.toml | read_version)"
check_tag $current_tag $file_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

0 comments on commit d8d2cd0

Please sign in to comment.