add scripts/get_module_version.sh

This script consumes a Prometheus version (or version tag) and prints
the appropriate module version.

Signed-off-by: Jan Fajerski <jfajersk@redhat.com>
This commit is contained in:
Jan Fajerski 2024-08-14 14:36:49 +02:00
parent 76999c1dcb
commit 0f79e5e289
3 changed files with 26 additions and 2 deletions

View file

@ -253,7 +253,7 @@ jobs:
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v2.'))
||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v3.'))
run: ./scripts/ui_release.sh --check-package "$(echo ${{ github.ref_name }}|sed s/v2/v0/)"
run: ./scripts/ui_release.sh --check-package "$(./scripts/get_module_version.sh ${{ github.ref_name }})"
- name: build
run: make assets
- name: Copy files before publishing libs

View file

@ -187,7 +187,7 @@ the Prometheus server, we use major version zero releases for the libraries.
Tag the new library release via the following commands:
```bash
tag="v$(sed s/2/0/ < VERSION)"
tag="v$(./scripts/get_module_version.sh)"
git tag -s "${tag}" -m "${tag}"
git push origin "${tag}"
```

24
scripts/get_module_version.sh Executable file
View file

@ -0,0 +1,24 @@
#!/usr/bin/env bash
# if no version string is passed as an argument, read VERSION file
if [ $# -eq 0 ]; then
VERSION="$(< VERSION)"
else
VERSION=$1
fi
# Remove leading 'v' if present
VERSION="${VERSION#v}"
# Extract MAJOR, MINOR, and REST
MAJOR="${VERSION%%.*}"
MINOR="${VERSION#*.}"; MINOR="${MINOR%%.*}"
REST="${VERSION#*.*.}"
# Format and output based on MAJOR version
if [[ "$MAJOR" == "2" ]]; then
echo "0.$MINOR.$REST"
elif [[ "$MAJOR" == "3" ]]; then
printf "0.3%02d.$REST\n" "$MINOR"
fi