diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..1d7226e499 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +name: Release + +on: + push: + branches: + - main + - test + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Install dependencies and set path + run: | + sudo apt-get update + sudo apt-get install -y ninja-build libcunit1-dev python3-pip + # Install meson as root so we can install to the system below. + sudo pip install meson + - name: Build tarball and changelogs + run: | + git rm -rf c/tests/meson-subproject + git config --global user.email "CI@CI.com" + git config --global user.name "Mr Robot" + git add -A + git commit -m "dummy commit to make meson not add in the symlinked directory" + meson c build-gcc + meson dist -C build-gcc + python docs/convert_changelog.py c/CHANGELOG.rst > C-CHANGELOG.txt + python docs/convert_changelog.py python/CHANGELOG.rst > PYTHON-CHANGELOG.txt + - name: Get the version + id: get_version + run: + echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3) + - name: C Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') && contains(github.event.ref, 'C_') + with: + name: C API ${{ steps.get_version.outputs.VERSION }} + body_path: C-CHANGELOG.txt + draft: True + fail_on_unmatched_files: True + files: build-gcc/meson-dist/* + - name: Python Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') && !contains(github.event.ref, 'C_') + with: + name: Python ${{ steps.get_version.outputs.VERSION }} + body_path: PYTHON-CHANGELOG.txt + draft: True + fail_on_unmatched_files: True \ No newline at end of file diff --git a/c/VERSION b/c/VERSION new file mode 100644 index 0000000000..f2766ee363 --- /dev/null +++ b/c/VERSION @@ -0,0 +1 @@ +0.99.15 \ No newline at end of file diff --git a/c/meson.build b/c/meson.build index f6ce389203..cea298b567 100644 --- a/c/meson.build +++ b/c/meson.build @@ -1,4 +1,7 @@ -project('tskit', ['c', 'cpp'], default_options: ['c_std=c99', 'cpp_std=c++11']) +project('tskit', ['c', 'cpp'], + version: files('VERSION'), + default_options: ['c_std=c99', 'cpp_std=c++11'] +) kastore_proj = subproject('kastore') kastore_dep = kastore_proj.get_variable('kastore_dep') @@ -43,7 +46,10 @@ if not meson.is_subproject() test_core = executable('test_core', sources: ['tests/test_core.c'], - link_with: [tskit_lib, test_lib], c_args: extra_c_args, dependencies: kastore_dep) + link_with: [tskit_lib, test_lib], + c_args: extra_c_args+['-DMESON_PROJECT_VERSION="@0@"'.format(meson.project_version())], + dependencies: kastore_dep, + ) test('core', test_core) test_tables = executable('test_tables', diff --git a/c/tests/test_core.c b/c/tests/test_core.c index 431e876f93..97f1d4c210 100644 --- a/c/tests/test_core.c +++ b/c/tests/test_core.c @@ -526,6 +526,17 @@ test_avl_random(void) validate_avl(sizeof(keys) / sizeof(*keys), keys); } +static void +test_meson_version(void) +{ + char version[100]; + + sprintf( + version, "%d.%d.%d", TSK_VERSION_MAJOR, TSK_VERSION_MINOR, TSK_VERSION_PATCH); + /* the MESON_PROJECT_VERSION define is passed in by meson when compiling */ + CU_ASSERT_STRING_EQUAL(version, MESON_PROJECT_VERSION); +} + int main(int argc, char **argv) { @@ -543,6 +554,7 @@ main(int argc, char **argv) { "test_avl_sequential", test_avl_sequential }, { "test_avl_interleaved", test_avl_interleaved }, { "test_avl_random", test_avl_random }, + { "test_meson_version", test_meson_version }, { NULL, NULL }, }; diff --git a/docs/convert_changelog.py b/docs/convert_changelog.py index 80c1f17538..984d0eaa23 100644 --- a/docs/convert_changelog.py +++ b/docs/convert_changelog.py @@ -1,5 +1,5 @@ import re -from pathlib import Path +import sys SUBS = [ (r":user:`([A-Za-z0-9-]*)`", r"[@\1](https://github.com/\1)"), @@ -7,11 +7,6 @@ (r":issue:`([0-9]*)`", r"[#\1](https://github.com/tskit-dev/tskit/issues/\1)"), ] -FILES = [ - Path(__file__).parent.parent / "c" / "CHANGELOG.rst", - Path(__file__).parent.parent / "python" / "CHANGELOG.rst", -] - def process_log(log): delimiters_seen = 0 @@ -27,9 +22,5 @@ def process_log(log): yield line -for file in FILES: - with open(file) as f: - print("-------------") - print(file) - print("-------------") - print("".join(process_log(f.readlines()))) +with open(sys.argv[1]) as f: + print("".join(process_log(f.readlines()))) diff --git a/docs/development.md b/docs/development.md index 7339b4dc17..c1830fd835 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1098,8 +1098,9 @@ git tag -a C_MAJOR.MINOR.PATCH -m "C API version C_MAJOR.MINOR.PATCH" git push upstream --tags ``` -Then prepare a release for the tag on GitHub, copying across the changelog. -Running `python docs/convert_changelog.py` will format the changelog for GitHub. +After a couple of minutes a github action will make a draft release with the changelog +at the [releases page](https://github.com/tskit-dev/tskit/releases). Check it looks +right and publish the release (Click on the little pencil). After release, start a section in the changelog for new developments and close the GitHub issue milestone of the release. @@ -1123,9 +1124,9 @@ git push upstream --tags This will trigger a build of the distribution artifacts for Python on [Github Actions](https://github.com/tskit-dev/tskit/actions). and deploy them to the [test PyPI](https://test.pypi.org/project/tskit/). Check -the release looks good there, then create a release on Github based on the tag you -pushed. Copy the changelog into the release. Running `python docs/convert_changelog.py` -will format the changelog for GitHub. Publishing this release will cause the github +the release looks good there, then publish the draft release on the +[releases page](https://github.com/tskit-dev/tskit/releases) (Click on the little pencil). +Publishing this release will cause the github action to deploy to the [production PyPI](https://pypi.org/project/tskit/). After release, start a section in the changelog for new developments and close the GitHub issue milestone of the release. diff --git a/python/tests/test_lowlevel.py b/python/tests/test_lowlevel.py index b3c4ba048e..59d38898af 100644 --- a/python/tests/test_lowlevel.py +++ b/python/tests/test_lowlevel.py @@ -3507,6 +3507,11 @@ def test_tskit_version(self): version = _tskit.get_tskit_version() assert version == (0, 99, 15) + def test_tskit_version_file(self): + maj, min_, patch = _tskit.get_tskit_version() + with open(f"{tskit.__path__[0]}/../../c/VERSION") as f: + assert f.read() == f"{maj}.{min_}.{patch}" + def test_uninitialised(): # These methods work from an instance that has a NULL ref so don't check