Demo data branch backport (#12521)

* Auto-detect demo dataset branch in CI

* Fix github actions

* Fix typo
This commit is contained in:
Oliver
2026-07-31 15:57:53 +10:00
committed by GitHub
parent 74ee9c5029
commit 70dee5c145
3 changed files with 32 additions and 25 deletions
+2 -6
View File
@@ -32,10 +32,6 @@ env:
INVENTREE_BACKUP_DIR: /home/runner/work/InvenTree/test_inventree_backup
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:
contents: read
@@ -139,7 +135,7 @@ jobs:
pip-dependency: psycopg2
- name: Set up test data
run: |
invoke dev.setup-test -iv --branch "$DEMO_DATASET_BRANCH"
invoke dev.setup-test -iv
invoke int.rebuild-thumbnails
- name: Install dependencies
run: invoke int.frontend-compile --extract
@@ -221,7 +217,7 @@ jobs:
pip-dependency: psycopg2
- name: Set up test data
run: |
invoke dev.setup-test -iv --branch "$DEMO_DATASET_BRANCH"
invoke dev.setup-test -iv
invoke int.rebuild-thumbnails
- name: Install dependencies
run: invoke int.frontend-compile --extract
+2 -6
View File
@@ -40,10 +40,6 @@ env:
INVENTREE_DB_HOST: "127.0.0.1"
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:
paths-filter:
@@ -91,10 +87,10 @@ jobs:
pip-dependency: psycopg
update: true
static: false
- name: Setup Postgres Database
- name: Setup Test Data
run: |
invoke migrate
invoke dev.setup-test -i --branch "$DEMO_DATASET_BRANCH"
invoke dev.setup-test -i
- name: Create Plugin Data
run: |
pip install -U inventree-dummy-app-plugin==0.1.0
+28 -13
View File
@@ -1837,12 +1837,33 @@ def test(
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(
help={
'dev': 'Set up development environment at the end',
'validate_files': 'Validate media files are correctly copied',
'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',
}
)
@@ -1854,7 +1875,7 @@ def setup_test(
use_ssh=False,
verbose=False,
path='inventree-demo-dataset',
branch='main',
branch: Optional[str] = None,
):
"""Setup a testing environment."""
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
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
# repository uses "main" as its trunk branch - map this automatically
# so CI can pass through the detected target branch unmodified.
if not branch or branch == 'master':
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
info(f"Cloning demo dataset (branch '{branch}') ...")
run(c, f'git clone {URL} {template_dir} -b {branch} -v --depth=1')