mirror of
https://github.com/inventree/InvenTree.git
synced 2026-08-19 19:49:48 +00:00
Demo data branch backport (#12521)
* Auto-detect demo dataset branch in CI * Fix github actions * Fix typo
This commit is contained in:
@@ -32,10 +32,6 @@ env:
|
|||||||
INVENTREE_BACKUP_DIR: /home/runner/work/InvenTree/test_inventree_backup
|
INVENTREE_BACKUP_DIR: /home/runner/work/InvenTree/test_inventree_backup
|
||||||
INVENTREE_SITE_URL: http://localhost:8000
|
INVENTREE_SITE_URL: http://localhost:8000
|
||||||
|
|
||||||
# Use the same-named branch of the demo dataset as the target branch of this build,
|
|
||||||
# so that stable branches are not broken by changes to the demo dataset on main
|
|
||||||
DEMO_DATASET_BRANCH: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
|
|
||||||
@@ -139,7 +135,7 @@ jobs:
|
|||||||
pip-dependency: psycopg2
|
pip-dependency: psycopg2
|
||||||
- name: Set up test data
|
- name: Set up test data
|
||||||
run: |
|
run: |
|
||||||
invoke dev.setup-test -iv --branch "$DEMO_DATASET_BRANCH"
|
invoke dev.setup-test -iv
|
||||||
invoke int.rebuild-thumbnails
|
invoke int.rebuild-thumbnails
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: invoke int.frontend-compile --extract
|
run: invoke int.frontend-compile --extract
|
||||||
@@ -221,7 +217,7 @@ jobs:
|
|||||||
pip-dependency: psycopg2
|
pip-dependency: psycopg2
|
||||||
- name: Set up test data
|
- name: Set up test data
|
||||||
run: |
|
run: |
|
||||||
invoke dev.setup-test -iv --branch "$DEMO_DATASET_BRANCH"
|
invoke dev.setup-test -iv
|
||||||
invoke int.rebuild-thumbnails
|
invoke int.rebuild-thumbnails
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: invoke int.frontend-compile --extract
|
run: invoke int.frontend-compile --extract
|
||||||
|
|||||||
@@ -40,10 +40,6 @@ env:
|
|||||||
INVENTREE_DB_HOST: "127.0.0.1"
|
INVENTREE_DB_HOST: "127.0.0.1"
|
||||||
INVENTREE_DB_PORT: 5432
|
INVENTREE_DB_PORT: 5432
|
||||||
|
|
||||||
# Use the same-named branch of the demo dataset as the target branch of this build,
|
|
||||||
# so that stable branches are not broken by changes to the demo dataset on main
|
|
||||||
DEMO_DATASET_BRANCH: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
paths-filter:
|
paths-filter:
|
||||||
@@ -91,10 +87,10 @@ jobs:
|
|||||||
pip-dependency: psycopg
|
pip-dependency: psycopg
|
||||||
update: true
|
update: true
|
||||||
static: false
|
static: false
|
||||||
- name: Setup Postgres Database
|
- name: Setup Test Data
|
||||||
run: |
|
run: |
|
||||||
invoke migrate
|
invoke migrate
|
||||||
invoke dev.setup-test -i --branch "$DEMO_DATASET_BRANCH"
|
invoke dev.setup-test -i
|
||||||
- name: Create Plugin Data
|
- name: Create Plugin Data
|
||||||
run: |
|
run: |
|
||||||
pip install -U inventree-dummy-app-plugin==0.1.0
|
pip install -U inventree-dummy-app-plugin==0.1.0
|
||||||
|
|||||||
@@ -1837,12 +1837,33 @@ def test(
|
|||||||
manage(c, cmd, pty=pty)
|
manage(c, cmd, pty=pty)
|
||||||
|
|
||||||
|
|
||||||
|
def _detect_ci_branch() -> Optional[str]:
|
||||||
|
"""Attempt to auto-detect the target branch when running in GitHub CI.
|
||||||
|
|
||||||
|
- For pull_request events, GITHUB_BASE_REF holds the PR's target branch (e.g. "master" or "1.4.x")
|
||||||
|
- For push events, GITHUB_REF_NAME holds the branch being pushed to
|
||||||
|
|
||||||
|
Returns None if not running in GitHub Actions, or no branch could be determined.
|
||||||
|
"""
|
||||||
|
if os.environ.get('GITHUB_ACTIONS') != 'true':
|
||||||
|
return None
|
||||||
|
|
||||||
|
base_ref = os.environ.get('GITHUB_BASE_REF')
|
||||||
|
if base_ref:
|
||||||
|
return base_ref
|
||||||
|
|
||||||
|
if os.environ.get('GITHUB_REF_TYPE') == 'branch':
|
||||||
|
return os.environ.get('GITHUB_REF_NAME')
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
@task(
|
@task(
|
||||||
help={
|
help={
|
||||||
'dev': 'Set up development environment at the end',
|
'dev': 'Set up development environment at the end',
|
||||||
'validate_files': 'Validate media files are correctly copied',
|
'validate_files': 'Validate media files are correctly copied',
|
||||||
'use_ssh': 'Use SSH protocol for cloning the demo dataset (requires SSH key)',
|
'use_ssh': 'Use SSH protocol for cloning the demo dataset (requires SSH key)',
|
||||||
'branch': 'Specify branch of demo-dataset to clone (default = main)',
|
'branch': 'Specify branch of demo-dataset to clone (default = auto-detected target branch in CI, else main)',
|
||||||
'verbose': 'Print verbose output from management commands',
|
'verbose': 'Print verbose output from management commands',
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1854,7 +1875,7 @@ def setup_test(
|
|||||||
use_ssh=False,
|
use_ssh=False,
|
||||||
verbose=False,
|
verbose=False,
|
||||||
path='inventree-demo-dataset',
|
path='inventree-demo-dataset',
|
||||||
branch='main',
|
branch: Optional[str] = None,
|
||||||
):
|
):
|
||||||
"""Setup a testing environment."""
|
"""Setup a testing environment."""
|
||||||
from src.backend.InvenTree.InvenTree.config import ( # type: ignore[import]
|
from src.backend.InvenTree.InvenTree.config import ( # type: ignore[import]
|
||||||
@@ -1876,23 +1897,17 @@ def setup_test(
|
|||||||
# Use SSH protocol for cloning the demo dataset
|
# Use SSH protocol for cloning the demo dataset
|
||||||
URL = 'git@github.com:inventree/demo-dataset.git'
|
URL = 'git@github.com:inventree/demo-dataset.git'
|
||||||
|
|
||||||
|
if not branch:
|
||||||
|
branch = _detect_ci_branch()
|
||||||
|
if branch:
|
||||||
|
info(f"Auto-detected target branch from CI: '{branch}'")
|
||||||
|
|
||||||
# InvenTree's trunk branch is named "master", but the demo-dataset
|
# InvenTree's trunk branch is named "master", but the demo-dataset
|
||||||
# repository uses "main" as its trunk branch - map this automatically
|
# repository uses "main" as its trunk branch - map this automatically
|
||||||
# so CI can pass through the detected target branch unmodified.
|
# so CI can pass through the detected target branch unmodified.
|
||||||
if not branch or branch == 'master':
|
if not branch or branch == 'master':
|
||||||
branch = 'main'
|
branch = 'main'
|
||||||
|
|
||||||
if branch != 'main':
|
|
||||||
# Stable release branches (e.g. "1.4.x") may not yet exist in the
|
|
||||||
# demo-dataset repository (e.g. it has not been backported yet).
|
|
||||||
# Fall back to "main" in that case, rather than failing the clone.
|
|
||||||
result = c.run(f'git ls-remote --heads {URL} {branch}', hide=True, warn=True)
|
|
||||||
if not result.ok or not result.stdout.strip():
|
|
||||||
warning(
|
|
||||||
f"Demo dataset has no branch named '{branch}' - falling back to 'main'"
|
|
||||||
)
|
|
||||||
branch = 'main'
|
|
||||||
|
|
||||||
# Get test data
|
# Get test data
|
||||||
info(f"Cloning demo dataset (branch '{branch}') ...")
|
info(f"Cloning demo dataset (branch '{branch}') ...")
|
||||||
run(c, f'git clone {URL} {template_dir} -b {branch} -v --depth=1')
|
run(c, f'git clone {URL} {template_dir} -b {branch} -v --depth=1')
|
||||||
|
|||||||
Reference in New Issue
Block a user