From d8d5aba850b20c2cf26969b1aa043ea48b12a326 Mon Sep 17 00:00:00 2001 From: costero-e Date: Tue, 22 Oct 2024 11:07:00 +0200 Subject: [PATCH] adding github action for updating api version --- .github/workflows/update_api_version.yml | 27 +++++++++++++++++++ beacon/conf/api_version.py | 33 ++++++++++++++++++++++++ beacon/conf/conf.py | 1 - 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/update_api_version.yml create mode 100644 beacon/conf/api_version.py diff --git a/.github/workflows/update_api_version.yml b/.github/workflows/update_api_version.yml new file mode 100644 index 0000000..4be66d7 --- /dev/null +++ b/.github/workflows/update_api_version.yml @@ -0,0 +1,27 @@ +name: update api version + +on: + push: + branches: ['master', 'api-version'] + +jobs: + updateapiversion: + runs-on: ubuntu-latest + steps: + - name: checkout repo content + uses: actions/checkout@v3 # checkout the repository content to github runner. + - name: setup python + uses: actions/setup-python@v4 + with: + python-version: 3.8 #install the python needed + - name: Install dependencies + run: | + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: execute py script + run: | + python beacon/conf/api_version.py + git config --global user.email "you@example.com" + git config --global user.name "API version update" + git add . + git commit -m "api version automatically generated" + git push \ No newline at end of file diff --git a/beacon/conf/api_version.py b/beacon/conf/api_version.py new file mode 100644 index 0000000..61be315 --- /dev/null +++ b/beacon/conf/api_version.py @@ -0,0 +1,33 @@ +import subprocess +import yaml + + +repo_url = 'https://github.com/EGA-archive/beacon2-ri-api.git' +output_lines = subprocess.check_output( + [ + "git", + "ls-remote", + repo_url, + "rev-parse", + "--short", + "sort=committerdate", + "HEAD" + ], + encoding="utf-8", +).splitlines() + +line_ref = output_lines[0].rpartition("/")[-1] + +last_line_ref=line_ref[0:7] + +last_line_ref="v2.0-"+last_line_ref + +print(last_line_ref) + +with open("beacon/conf/api_version.yml") as api_version_file: + api_version = yaml.safe_load(api_version_file) + +api_version['api_version']=last_line_ref + +with open("beacon/conf/api_version.yml", 'w') as out: + yaml.dump(api_version, out) \ No newline at end of file diff --git a/beacon/conf/conf.py b/beacon/conf/conf.py index 40cf143..93c1e1e 100644 --- a/beacon/conf/conf.py +++ b/beacon/conf/conf.py @@ -12,7 +12,6 @@ level=logging.NOTSET log_file='beacon/logs/logs.log' -api_version='2.0.0' beacon_id = 'org.ega-archive.beacon-ri-demo' # ID of the Beacon beacon_name = 'Beacon Reference Implementation demo' # Name of the Beacon service api_version = 'v2.0.0' # Version of the Beacon implementation