Skip to content

Commit

Permalink
feat: auto-set version number from git tag (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Dec 15, 2023
1 parent 5cfdf6b commit 88eaf31
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
21 changes: 21 additions & 0 deletions .github/detect-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# detect the version number from the git tag

echo "Detecting version number..."
version=0.0.0

pushd $(dirname $0)/..

git_tag=$(git describe --tags --abbrev=0)
if [ -n "$git_tag" ]; then
version=$(echo $git_tag | sed 's;^v;;')
echo "VERSION = $version"
else
echo """WARNING: not a git repository
setting VERSION to $version
edit $(pwd)/.version to set the correct version""" >&2
fi

echo $version > .version

popd
9 changes: 8 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with: # settings needed for version number detection
clean: false
fetch-tags: true
fetch-depth: 0
- name: setup meson
run: python -m pip install meson ninja
- name: summarize dependencies
Expand All @@ -100,7 +104,10 @@ jobs:
run: ls *.tar.gz | xargs -I{} tar xzvf {}
- run: tree
- name: configure
run: ./configure.py --hipo hipo --fmt fmt --examples --no-documentation
run: |
./configure.py --hipo hipo --fmt fmt --examples --no-documentation
echo '### Iguana Version' >> $GITHUB_STEP_SUMMARY
cat .version >> $GITHUB_STEP_SUMMARY
- name: build
run: ./install-iguana.sh
- name: dump build log
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# build artifacts
*.ini
.version
install-iguana.sh
/build*/
/iguana
Expand Down
12 changes: 8 additions & 4 deletions configure.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

from configparser import ConfigParser
import argparse, os, sys, textwrap
import argparse, os, sys, textwrap, subprocess

# constants
SYSTEM_ASSUMPTION = 'assume system installation'
Expand Down Expand Up @@ -30,8 +30,13 @@ class Formatter(argparse.ArgumentDefaultsHelpFormatter, argparse.RawDescriptionH
parser_build.add_argument( '--ini', default='build-iguana.ini', type=str, help='name of the output config INI file')
args = parser.parse_args()

# get prefix absolute path
prefix = os.path.realpath(args.prefix)
# get prefix and source absolute paths
prefix = os.path.realpath(args.prefix)
sourceDir = os.path.dirname(os.path.realpath(__file__))

# detect the version number
subprocess.run('.github/detect-version.sh', cwd=sourceDir)
print(SEPARATOR)

# set dependency paths
cmake_prefix_path = []
Expand Down Expand Up @@ -76,7 +81,6 @@ def meson_string_array(arr):
print(SEPARATOR)

# generate the installation script
sourceDir = os.path.dirname(os.path.realpath(__file__))
installScript = 'install-iguana.sh'
with open(installScript, 'w') as fp:
fp.write(textwrap.dedent(f'''\
Expand Down
7 changes: 5 additions & 2 deletions doc/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ Inspect both of them, and if they look correct, proceed with building and instal

Instead of `configure.py`, use `meson` directly for more control:

1. Follow the [note on dependency resolution](dependency_resolution.md)
2. Build with `meson`, for example
1. The version number is dynamically determined from the most recent `git` tag; either:
- run `.github/detect-version.sh`
- put the version number in `.version` in the top-level directory of the repository
2. Follow the [note on dependency resolution](dependency_resolution.md)
3. Build with `meson`, for example
```bash
meson setup --prefix=$(pwd)/iguana build-iguana /path/to/iguana/repository
meson install -C build-iguana
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'iguana',
'cpp',
version: '0.1.0',
version: files(meson.project_source_root() / '.version'),
license: 'LGPLv3',
default_options: [ 'cpp_std=c++17' ],
meson_version: '>=1.1',
Expand Down

0 comments on commit 88eaf31

Please sign in to comment.