Skip to content

Commit

Permalink
Add app version check (#8885)
Browse files Browse the repository at this point in the history
* Add check python version

* ok

* sure

* check it out

* goog

* travis -> gh
  • Loading branch information
medariox authored Dec 16, 2020
1 parent cfb9abc commit cb540cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
27 changes: 10 additions & 17 deletions .github/check_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@

VERSION_FILE = 'medusa/common.py'
VERSION_LINE_REGEXP = re.compile(r"VERSION = '([0-9.]+)'")
TRAVIS = os.environ.get('TRAVIS', False)

if TRAVIS:
TRAVIS_PULL_REQUEST = os.environ['TRAVIS_PULL_REQUEST'] # 'false' if not a PR, otherwise - the PR number
TRAVIS_PR_TARGET_BRANCH = os.environ['TRAVIS_BRANCH']
TRAVIS_PR_SOURCE_BRANCH = os.environ['TRAVIS_PULL_REQUEST_BRANCH']
TRAVIS_BUILD_DIR = os.environ['TRAVIS_BUILD_DIR']
else:
TRAVIS_PULL_REQUEST = '1234'
TRAVIS_PR_TARGET_BRANCH = 'master'
TRAVIS_PR_SOURCE_BRANCH = 'develop' # or 'release/release-0.2.3'
TRAVIS_BUILD_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
GH_PULL_REQUEST = os.environ['GITHUB_EVENT_NAME']
GH_PR_TARGET_BRANCH = os.environ['GITHUB_BASE_REF']
GH_PR_SOURCE_BRANCH = os.environ['GITHUB_HEAD_REF']
GH_BUILD_DIR = os.environ['GITHUB_WORKSPACE']

TRAVIS_PR_TARGET_BRANCH = TRAVIS_PR_TARGET_BRANCH.lower()
TRAVIS_PR_SOURCE_BRANCH = TRAVIS_PR_SOURCE_BRANCH.lower()
GH_PR_TARGET_BRANCH = GH_PR_TARGET_BRANCH.lower()
GH_PR_SOURCE_BRANCH = GH_PR_SOURCE_BRANCH.lower()


class Version(object):
Expand Down Expand Up @@ -61,7 +54,7 @@ def __repr__(self):
def search_file_for_version():
"""Get the app version from the code."""
version_file = VERSION_FILE.split('/')
filename = os.path.abspath(os.path.join(TRAVIS_BUILD_DIR, *version_file))
filename = os.path.abspath(os.path.join(GH_BUILD_DIR, *version_file))
with io.open(filename, 'r', encoding='utf-8') as fh:
for line in fh:
match = VERSION_LINE_REGEXP.match(line)
Expand All @@ -73,9 +66,9 @@ def search_file_for_version():

# Are we merging either develop or a release branch into master in a pull request?
if all((
TRAVIS_PULL_REQUEST != 'false',
TRAVIS_PR_TARGET_BRANCH == 'master',
TRAVIS_PR_SOURCE_BRANCH == 'develop' or TRAVIS_PR_SOURCE_BRANCH.startswith('release/')
GH_PULL_REQUEST == 'pull_request',
GH_PR_TARGET_BRANCH == 'master',
GH_PR_SOURCE_BRANCH == 'develop' or GH_PR_SOURCE_BRANCH.startswith('release/')
)):
# Get lastest git tag on master branch
proc = subprocess.call(['git', 'fetch', 'origin', 'master:master'])
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/version-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Check app version

on: [pull_request]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Check version
run: python ./.github/check_version.py

0 comments on commit cb540cd

Please sign in to comment.