Skip to content

Commit

Permalink
Add version helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
folmos-at-orange committed Oct 26, 2023
1 parent b58e1fc commit 26b99f6
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/update-kni-tutorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/
Expand Down
50 changes: 50 additions & 0 deletions scripts/khiops-package-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#! /usr/bin/env bash
# Creates a "package-version" of Khiops
# - if the commit is tagged:
# - if the tag matches the Khiops version in the sources:
# - package-version = version
# - otherwise:
# - warn
# - package-version = version-SNAPSHOT-$TAG
# - otherwise:
# - package-version = version-SNAPSHOT-$SHORT_COMMIT_HASH

# 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-SNAPSHOT-$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-SNAPSHOT-$short_hash"
echo "::warning: Creating snapshot package $khiops_package_version" 1>&2
fi
echo "$khiops_package_version"
}

main "$@"
17 changes: 17 additions & 0 deletions scripts/khiops-version
Original file line number Diff line number Diff line change
@@ -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/'

0 comments on commit 26b99f6

Please sign in to comment.