Skip to content

Commit

Permalink
Merge pull request #85 from Jsoconno/api-retrieval-of-version
Browse files Browse the repository at this point in the history
Api retrieval of version
  • Loading branch information
jsoconno authored Jan 25, 2021
2 parents 324236b + d7818b8 commit 65f3c8c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
pip install setuptools wheel twine
- name: Build and publish
env:
Expand Down
25 changes: 25 additions & 0 deletions scripts/get_latest_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import os
import json
import requests
import re

def get_release_data(user, repo, field=None, regex_pattern=None, group_number=0):
"""
Extract data from the latest release.
"""
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/releases/latest")
release_data_dict = json.loads(response.text)

if field:
field_value = release_data_dict[field]
if regex_pattern is None:
output = field_value
else:
output = re.search(regex_pattern, field_value).group(group_number)
else:
output = release_data_dict

return output

version = get_release_data(user="jsoconno", repo="architectures", field="tag_name", regex_pattern="[0-9]*\.[0-9]*\.[0-9]*")
print(version)
11 changes: 11 additions & 0 deletions scripts/get_latest_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
get_latest_release() {
curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"v([^"]+)".*/\1/' # Pluck JSON value
}

# Usage
# get_latest_release "jsoconno/architectures"

# Example output:
# v0.31.4
25 changes: 24 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import setuptools
import json
import requests
import re

def get_release_data(user, repo, field=None, regex_pattern=None, group_number=0):
"""
Extract data from the latest release.
"""
response = requests.get(f"https://api.github.com/repos/{user}/{repo}/releases/latest")
release_data_dict = json.loads(response.text)

if field:
field_value = release_data_dict[field]
if regex_pattern is None:
output = field_value
else:
output = re.search(regex_pattern, field_value).group(group_number)
else:
output = release_data_dict

return output

version = get_release_data(user="jsoconno", repo="architectures", field="tag_name", regex_pattern="[0-9]*\.[0-9]*\.[0-9]*")

with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()

setuptools.setup(
name="architectures",
version="0.1.3",
version=version,
author="Justin O'Connor",
author_email="[email protected]",
description="Tools for creating architecture as code using Python.",
Expand Down

0 comments on commit 65f3c8c

Please sign in to comment.