mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Version checker (#3102)
* Updates for docker version check script: - Do not run on a push to stable - Check existing versions via GitHub API - Add stable docker image tag also * Fix regex pattern * Check for null regex result * Push to stable on tagged release
This commit is contained in:
parent
8a2cfa04d1
commit
ccefefdc7f
18
.github/workflows/docker.yaml
vendored
18
.github/workflows/docker.yaml
vendored
@ -2,7 +2,6 @@
|
|||||||
# This workflow runs under any of the following conditions:
|
# This workflow runs under any of the following conditions:
|
||||||
#
|
#
|
||||||
# - Push to the master branch
|
# - Push to the master branch
|
||||||
# - Push to the stable branch
|
|
||||||
# - Publish release
|
# - Publish release
|
||||||
#
|
#
|
||||||
# The following actions are performed:
|
# The following actions are performed:
|
||||||
@ -21,7 +20,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- 'master'
|
- 'master'
|
||||||
- 'stable'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
@ -29,12 +27,15 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repo
|
- name: Check out repo
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Version Check
|
- name: Version Check
|
||||||
run: |
|
run: |
|
||||||
python3 ci/check_version_number.py
|
python3 ci/version_check.py
|
||||||
echo "git_commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
echo "git_commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||||
echo "git_commit_date=$(git show -s --format=%ci)" >> $GITHUB_ENV
|
echo "git_commit_date=$(git show -s --format=%ci)" >> $GITHUB_ENV
|
||||||
- name: Run Unit Tests
|
- name: Run Unit Tests
|
||||||
@ -65,5 +66,12 @@ jobs:
|
|||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
target: production
|
target: production
|
||||||
tags: inventree/inventree:${{ env.docker_tag }}
|
tags: ${{ env.docker_tags }}
|
||||||
build-args: commit_hash=${{ env.git_commit_hash }},commit_date=${{ env.git_commit_date }},commit_tag=${{ env.docker_tag }}
|
build-args: commit_hash="${{ env.git_commit_hash }}", commit_date="${{ env.git_commit_date }}"
|
||||||
|
- name: Push to Stable Branch
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
if: env.stable_release == 'true'
|
||||||
|
with:
|
||||||
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
branch: stable
|
||||||
|
force: true
|
||||||
|
3
.github/workflows/qc_checks.yaml
vendored
3
.github/workflows/qc_checks.yaml
vendored
@ -91,9 +91,6 @@ jobs:
|
|||||||
cache: 'pip'
|
cache: 'pip'
|
||||||
- name: Run pre-commit Checks
|
- name: Run pre-commit Checks
|
||||||
uses: pre-commit/action@v2.0.3
|
uses: pre-commit/action@v2.0.3
|
||||||
- name: Check version number
|
|
||||||
run: |
|
|
||||||
python3 ci/check_version_number.py
|
|
||||||
|
|
||||||
python:
|
python:
|
||||||
name: Tests - inventree-python
|
name: Tests - inventree-python
|
||||||
|
@ -4,20 +4,79 @@ Ensure that the release tag matches the InvenTree version number:
|
|||||||
master / main branch:
|
master / main branch:
|
||||||
- version number must end with 'dev'
|
- version number must end with 'dev'
|
||||||
|
|
||||||
stable branch:
|
|
||||||
- version number must *not* end with 'dev'
|
|
||||||
- version number cannot already exist as a release tag
|
|
||||||
|
|
||||||
tagged branch:
|
tagged branch:
|
||||||
- version number must match tag being built
|
- version number must match tag being built
|
||||||
- version number cannot already exist as a release tag
|
- version number cannot already exist as a release tag
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def get_existing_release_tags():
|
||||||
|
"""Request information on existing releases via the GitHub API"""
|
||||||
|
|
||||||
|
response = requests.get('https://api.github.com/repos/inventree/inventree/releases')
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise ValueError(f'Unexpected status code from GitHub API: {response.status_code}')
|
||||||
|
|
||||||
|
data = json.loads(response.text)
|
||||||
|
|
||||||
|
# Return a list of all tags
|
||||||
|
tags = []
|
||||||
|
|
||||||
|
for release in data:
|
||||||
|
tag = release['tag_name'].strip()
|
||||||
|
match = re.match(r"^.*(\d+)\.(\d+)\.(\d+).*$", tag)
|
||||||
|
|
||||||
|
if len(match.groups()) != 3:
|
||||||
|
print(f"Version '{tag}' did not match expected pattern")
|
||||||
|
continue
|
||||||
|
|
||||||
|
tags.append([int(x) for x in match.groups()])
|
||||||
|
|
||||||
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
def check_version_number(version_string):
|
||||||
|
"""Check the provided version number.
|
||||||
|
|
||||||
|
Returns True if the provided version is the 'newest' InvenTree release
|
||||||
|
"""
|
||||||
|
|
||||||
|
print(f"Checking version '{version_string}'")
|
||||||
|
|
||||||
|
# Check that the version string matches the required format
|
||||||
|
match = re.match(r"^(\d+)\.(\d+)\.(\d+)(?: dev)?$", version_string)
|
||||||
|
|
||||||
|
if not match or len(match.groups()) != 3:
|
||||||
|
raise ValueError(f"Version string '{version_string}' did not match required pattern")
|
||||||
|
|
||||||
|
version_tuple = [int(x) for x in match.groups()]
|
||||||
|
|
||||||
|
# Look through the existing releases
|
||||||
|
existing = get_existing_release_tags()
|
||||||
|
|
||||||
|
# Assume that this is the highest release, unless told otherwise
|
||||||
|
highest_release = True
|
||||||
|
|
||||||
|
for release in existing:
|
||||||
|
if release == version_tuple:
|
||||||
|
raise ValueError(f"Duplicate release '{version_string}' exists!")
|
||||||
|
|
||||||
|
if release > version_tuple:
|
||||||
|
highest_release = False
|
||||||
|
print(f"Found newer release: {str(release)}")
|
||||||
|
|
||||||
|
return highest_release
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
here = os.path.abspath(os.path.dirname(__file__))
|
here = os.path.abspath(os.path.dirname(__file__))
|
||||||
@ -49,24 +108,12 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
print(f"InvenTree Version: '{version}'")
|
print(f"InvenTree Version: '{version}'")
|
||||||
|
|
||||||
|
highest_release = check_version_number(version)
|
||||||
|
|
||||||
# Determine which docker tag we are going to use
|
# Determine which docker tag we are going to use
|
||||||
docker_tag = None
|
docker_tags = None
|
||||||
|
|
||||||
if GITHUB_REF_TYPE == 'branch' and ('stable' in GITHUB_REF or 'stable' in GITHUB_BASE_REF):
|
if GITHUB_REF_TYPE == 'tag':
|
||||||
print("Checking requirements for 'stable' release branch:")
|
|
||||||
|
|
||||||
pattern = r"^\d+(\.\d+)+$"
|
|
||||||
result = re.match(pattern, version)
|
|
||||||
|
|
||||||
if result is None:
|
|
||||||
print(f"Version number '{version}' does not match required pattern for stable branch")
|
|
||||||
sys.exit(1)
|
|
||||||
else:
|
|
||||||
print(f"Version number '{version}' matches stable branch")
|
|
||||||
|
|
||||||
docker_tag = 'stable'
|
|
||||||
|
|
||||||
elif GITHUB_REF_TYPE == 'tag':
|
|
||||||
# GITHUB_REF should be of th eform /refs/heads/<tag>
|
# GITHUB_REF should be of th eform /refs/heads/<tag>
|
||||||
version_tag = GITHUB_REF.split('/')[-1]
|
version_tag = GITHUB_REF.split('/')[-1]
|
||||||
print(f"Checking requirements for tagged release - '{version_tag}':")
|
print(f"Checking requirements for tagged release - '{version_tag}':")
|
||||||
@ -77,7 +124,10 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
# TODO: Check if there is already a release with this tag!
|
# TODO: Check if there is already a release with this tag!
|
||||||
|
|
||||||
docker_tag = version_tag
|
if highest_release:
|
||||||
|
docker_tags = [version_tag, 'stable']
|
||||||
|
else:
|
||||||
|
docker_tags = [version_tag]
|
||||||
|
|
||||||
elif GITHUB_REF_TYPE == 'branch':
|
elif GITHUB_REF_TYPE == 'branch':
|
||||||
# Otherwise we know we are targetting the 'master' branch
|
# Otherwise we know we are targetting the 'master' branch
|
||||||
@ -92,7 +142,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
print(f"Version number '{version}' matches development branch")
|
print(f"Version number '{version}' matches development branch")
|
||||||
|
|
||||||
docker_tag = 'latest'
|
docker_tags = ['latest']
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Unsupported branch / version combination:")
|
print("Unsupported branch / version combination:")
|
||||||
@ -102,13 +152,20 @@ if __name__ == '__main__':
|
|||||||
print("GITHUB_REF:", GITHUB_REF)
|
print("GITHUB_REF:", GITHUB_REF)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if docker_tag is None:
|
if docker_tags is None:
|
||||||
print("Docker tag could not be determined")
|
print("Docker tag could not be determined")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(f"Version check passed for '{version}'!")
|
print(f"Version check passed for '{version}'!")
|
||||||
print(f"Docker tag: '{docker_tag}'")
|
print(f"Docker tags: '{docker_tags}'")
|
||||||
|
|
||||||
# Ref: https://getridbug.com/python/how-to-set-environment-variables-in-github-actions-using-python/
|
# Ref: https://getridbug.com/python/how-to-set-environment-variables-in-github-actions-using-python/
|
||||||
with open(os.getenv('GITHUB_ENV'), 'a') as env_file:
|
with open(os.getenv('GITHUB_ENV'), 'a') as env_file:
|
||||||
env_file.write(f"docker_tag={docker_tag}\n")
|
|
||||||
|
# Construct tag string
|
||||||
|
tags = ",".join([f"inventree/inventree:{tag}" for tag in docker_tags])
|
||||||
|
|
||||||
|
env_file.write(f"docker_tags={tags}\n")
|
||||||
|
|
||||||
|
if GITHUB_REF_TYPE == 'tag' and highest_release:
|
||||||
|
env_file.write("stable_release=true\n")
|
Loading…
Reference in New Issue
Block a user