From 684b6f629f31ab6bf8ee62adf8b36a3693bde417 Mon Sep 17 00:00:00 2001 From: Miquel Duran-Frigola Date: Wed, 14 Jun 2023 10:57:01 +0200 Subject: [PATCH] versioning pipeline automated --- .github/scripts/static_version_writer.py | 21 ++++++++++++++ .github/workflows/tag-to-version.yml | 36 ++++++++++++++++++++++++ ersilia/_static_version.py | 1 + ersilia/setup/utils/clone.py | 3 ++ ersilia/utils/versioning.py | 2 +- setup.py | 2 +- 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 .github/scripts/static_version_writer.py create mode 100644 .github/workflows/tag-to-version.yml create mode 100644 ersilia/_static_version.py diff --git a/.github/scripts/static_version_writer.py b/.github/scripts/static_version_writer.py new file mode 100644 index 00000000..1a7fadd4 --- /dev/null +++ b/.github/scripts/static_version_writer.py @@ -0,0 +1,21 @@ +import os +import os +from importlib.util import module_from_spec, spec_from_file_location + +ROOT = os.path.dirname(os.path.abspath(__file__)) + + +def get_version(package_path): + spec = spec_from_file_location("version", os.path.join(package_path, "_version.py")) + module = module_from_spec(spec) + spec.loader.exec_module(module) + version = module.get_version_for_setup() + return version + + +try: + version = get_version(os.path.join(ROOT, "..", "..", "ersilia")) +except: + version = get_version(os.path.join(ROOT, "ersilia")) + +print(version) diff --git a/.github/workflows/tag-to-version.yml b/.github/workflows/tag-to-version.yml new file mode 100644 index 00000000..d09252e6 --- /dev/null +++ b/.github/workflows/tag-to-version.yml @@ -0,0 +1,36 @@ +name: Tag to version + +on: + push: + tags: + - 'v*' + + workflow_dispatch: + +jobs: + version: + runs-on: ubuntu-latest + + steps: + - name: Checkout persist credentials + uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # pin@v3.5.2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + + - name: Make a change and commit + run: | + wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/static_version_writer.py + python static_version_writer.py + rm static_version_writer.py + + - name: Commit and push changes done to the README file + uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4 + with: + author_name: "ersilia-bot" + author_email: "ersilia-bot@users.noreply.github.com" + message: "update version [skip ci]" + repository: "ersilia-os/${{ github.event.repository.name }}" + github_token: ${{ secrets.GITHUB_TOKEN }} + amend: true + force: true diff --git a/ersilia/_static_version.py b/ersilia/_static_version.py new file mode 100644 index 00000000..edd90a98 --- /dev/null +++ b/ersilia/_static_version.py @@ -0,0 +1 @@ +version = "0.1.12" diff --git a/ersilia/setup/utils/clone.py b/ersilia/setup/utils/clone.py index a95c62e5..71f5f7a2 100644 --- a/ersilia/setup/utils/clone.py +++ b/ersilia/setup/utils/clone.py @@ -18,6 +18,9 @@ def clone(self, path, version): path_repo = os.path.join(path, self.cfg.HUB.PACKAGE) if self.development_path is not None: path_version = Versioner().ersilia_version_from_path(self.development_path) + if path_version is None: + shutil.copytree(self.development_path, path_repo) + return path_repo if path_version == version: shutil.copytree(self.development_path, path_repo) return path_repo diff --git a/ersilia/utils/versioning.py b/ersilia/utils/versioning.py index 314cdf85..2bb4dcc0 100644 --- a/ersilia/utils/versioning.py +++ b/ersilia/utils/versioning.py @@ -32,7 +32,7 @@ def ersilia_version_from_path(self, path): if not os.path.exists(fn): fn = os.path.join(path, static_version_file) if not os.path.exists(fn): - raise Exception + return None with open(fn, "r") as f: text = f.read() ver = text.split('"')[1] diff --git a/setup.py b/setup.py index 838e61bd..b6ddd07d 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def get_version(package_path): spec = spec_from_file_location("version", os.path.join(package_path, "_version.py")) module = module_from_spec(spec) spec.loader.exec_module(module) - version = module.get_version_for_setup() + version = module.get_version_from_static() return version