From d66844c1b101f1f7b1a2c9d3df00929f64db86a4 Mon Sep 17 00:00:00 2001 From: Felipe Olmos Date: Wed, 4 Oct 2023 12:19:31 +0200 Subject: [PATCH] Add version helper scripts --- .github/workflows/update-kni-tutorial.yml | 10 ++--- scripts/khiops-package-version | 50 +++++++++++++++++++++++ scripts/khiops-version | 17 ++++++++ 3 files changed, 71 insertions(+), 6 deletions(-) create mode 100755 scripts/khiops-package-version create mode 100755 scripts/khiops-version diff --git a/.github/workflows/update-kni-tutorial.yml b/.github/workflows/update-kni-tutorial.yml index 1dfb9a140..a08faaeea 100644 --- a/.github/workflows/update-kni-tutorial.yml +++ b/.github/workflows/update-kni-tutorial.yml @@ -6,16 +6,14 @@ jobs: update-repo: runs-on: ubuntu-latest permissions: - contents: write # To push a branch + contents: write # To push a branch steps: - - name: Checkout khiops sources + - name: Checkout Khiops sources uses: actions/checkout@v3 with: path: khiops - name: Put Khiops version on the environment - run: | - KHIOPS_VERSION=$(grep "KHIOPS_VERSION" khiops/src/Learning/KWUtils/KWKhiopsVersion.h | cut -d"(" -f2 | cut -d")" -f1) - echo "KHIOPS_VERSION=${KHIOPS_VERSION}" >> "$GITHUB_ENV" + run: echo "KHIOPS_VERSION=$(./khiops/scripts/khiops-version)" >> "$GITHUB_ENV" - name: Checkout KNI-tutorial uses: actions/checkout@v3 with: @@ -26,7 +24,7 @@ jobs: # README.md and *.c files are generated by cmake configure - name: Update local KNI-tutorial run: | - cmake -B khiops/build -S khiops -DMPI=OFF -DBUILD_JARS=OFF -DBUILD_LEX_YACC=OFF -DTESTING=OFF + cmake -B khiops/build -S khiops -DMPI=OFF -DBUILD_JARS=OFF -DBUILD_LEX_YACC=OFF -DTESTING=OFF cp khiops/build/tmp/kni.README.md tutorial/README.md cp khiops/build/tmp/KNIRecodeFile.c tutorial/cpp/ cp khiops/build/tmp/KNIRecodeMTFiles.c tutorial/cpp/ diff --git a/scripts/khiops-package-version b/scripts/khiops-package-version new file mode 100755 index 000000000..7caceb6c0 --- /dev/null +++ b/scripts/khiops-package-version @@ -0,0 +1,50 @@ +#! /usr/bin/env bash +# Creates a "package-version" of Khiops +# - if the commit is tagged: +# - if the matches the in the sources: +# - package-version = +# - otherwise: +# - warn +# - package-version = -preview- +# - otherwise: +# - package-version = -preview- + +# Common safeguards +set -euo pipefail + +# Save this script's directory +SCRIPT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)" + +main () { + # The ref_name it should be either a hash or a tag + declare ref_name="$1" + + # Whether ref_name is a tag (default false) + declare is_tag="${2:-false}" + + # Obtain the khiops version from the source + local script_dir + local khiops_version + khiops_version="$("$SCRIPT_DIR/khiops-version")" + + # See the header of the script for this part + local khiops_package_version + if [[ "$is_tag" == "true" ]] + then + if [[ "$ref_name" == "v${khiops_version}" ]] + then + khiops_package_version="$khiops_version" + else + khiops_package_version="$khiops_version-preview-$ref_name" + echo "::warning: Tag '$ref_name' doesn't match the Khiops source version '$khiops_version'" 1>&2 + echo "::warning: Creating snapshot package $khiops_package_version" 1>&2 + fi + else + short_hash="$(git rev-parse --short --verify "$ref_name" | cut -d' ' -f1)" + khiops_package_version="$khiops_version-preview-$short_hash" + echo "::warning: Creating snapshot package $khiops_package_version" 1>&2 + fi + echo "$khiops_package_version" +} + +main "$@" diff --git a/scripts/khiops-version b/scripts/khiops-version new file mode 100755 index 000000000..bb28bebda --- /dev/null +++ b/scripts/khiops-version @@ -0,0 +1,17 @@ +#! /usr/bin/env bash + +# Obtains the khiops version stored in the sources + +set -euo pipefail + +# Obtain the khiops repo location +SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd) +KHIOPS_REPO_DIR=$(dirname "$SCRIPT_DIR") + +# Get the version +# - Get the version definition line in the KWKhiopsVersion.h file +# - Get the third token, it should be something like str(10.1.1) +# - Extract the version +grep "KHIOPS_VERSION" "$KHIOPS_REPO_DIR"/src/Learning/KWUtils/KWKhiopsVersion.h \ + | cut -d' ' -f3 \ + | sed 's/str(\(.*\))/\1/'