Skip to content

Commit

Permalink
versioning pipeline automated
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelduranfrigola committed Jun 14, 2023
1 parent bb53b53 commit 684b6f6
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 2 deletions.
21 changes: 21 additions & 0 deletions .github/scripts/static_version_writer.py
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 36 additions & 0 deletions .github/workflows/tag-to-version.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions ersilia/_static_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.1.12"
3 changes: 3 additions & 0 deletions ersilia/setup/utils/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ersilia/utils/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 684b6f6

Please sign in to comment.