From 22f64ffd9f91273582be76aa65b10070c7700483 Mon Sep 17 00:00:00 2001 From: Dario Date: Wed, 16 Dec 2020 18:16:57 +0100 Subject: [PATCH] Add app version check (#8885) * Add check python version * ok * sure * check it out * goog * travis -> gh --- .github/check_version.py | 27 ++++++++++----------------- .github/workflows/version-check.yml | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/version-check.yml diff --git a/.github/check_version.py b/.github/check_version.py index b9e9b2825a..c2990213d0 100644 --- a/.github/check_version.py +++ b/.github/check_version.py @@ -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): @@ -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) @@ -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']) diff --git a/.github/workflows/version-check.yml b/.github/workflows/version-check.yml new file mode 100644 index 0000000000..9d5b481fd5 --- /dev/null +++ b/.github/workflows/version-check.yml @@ -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