Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: Package bids-examples and bids-error-examples into Python distributions on schema-* tags #1252

Merged
merged 81 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2ac1b0d
Test draft
TheChymera Aug 19, 2022
b3a3fb0
triggering on tag
TheChymera Aug 19, 2022
7244ecf
debug
TheChymera Aug 19, 2022
1f5c52f
debug
TheChymera Aug 19, 2022
599b2ac
debug
TheChymera Aug 19, 2022
2e62662
debug
TheChymera Aug 19, 2022
208a143
debug
TheChymera Aug 19, 2022
688bfe0
debug
TheChymera Aug 19, 2022
4f7a0a1
debug
TheChymera Aug 19, 2022
4e3ab04
debug
TheChymera Aug 19, 2022
3e592eb
debug
TheChymera Aug 19, 2022
7b17e52
debug
TheChymera Aug 19, 2022
36b5c39
debug
TheChymera Aug 19, 2022
4fa3d51
debug
TheChymera Aug 19, 2022
17e5071
debug
TheChymera Aug 19, 2022
41d58ed
debug
TheChymera Aug 19, 2022
409d2b8
debug
TheChymera Aug 19, 2022
ebe109a
debug
TheChymera Aug 19, 2022
8dd2b04
debug
TheChymera Aug 19, 2022
265ce16
debug
TheChymera Aug 19, 2022
429c82a
debug
TheChymera Aug 19, 2022
dd30771
debug
TheChymera Aug 19, 2022
07bb861
debug
TheChymera Aug 19, 2022
da5712e
debug
TheChymera Aug 19, 2022
74cedb6
debug
TheChymera Aug 19, 2022
1401b0f
debug
TheChymera Aug 19, 2022
3162add
debug
TheChymera Aug 19, 2022
88f4d8a
debug
TheChymera Aug 19, 2022
4dc1416
debug
TheChymera Aug 19, 2022
bcd2a8e
debug
TheChymera Aug 19, 2022
3e05385
debug
TheChymera Aug 19, 2022
682110e
debug
TheChymera Aug 19, 2022
06c18dd
debug
TheChymera Aug 19, 2022
c03e047
debug
TheChymera Aug 19, 2022
5073423
debug
TheChymera Aug 19, 2022
bd2ae75
debug
TheChymera Aug 19, 2022
0d281f2
debug
TheChymera Aug 19, 2022
31db5e2
debug
TheChymera Aug 19, 2022
581d0f7
Test upload to test.pypi before doing the real thing
TheChymera Aug 19, 2022
2575641
debug
TheChymera Aug 19, 2022
f81010e
debug
TheChymera Aug 19, 2022
3646a1c
utility script for testing tag hooks
TheChymera Aug 19, 2022
be9e638
Generating testdata inside repo as opposed to in separate archive
TheChymera Aug 19, 2022
9d4a749
overwrite version file
TheChymera Aug 19, 2022
fca0ce8
Preserve version
TheChymera Aug 19, 2022
c4e0035
Fixing broken version file
TheChymera Aug 19, 2022
d21b157
Including testdata if present
TheChymera Aug 19, 2022
11d55b3
debug
TheChymera Aug 19, 2022
bca2a68
Including testdata in sdist if existent
TheChymera Aug 19, 2022
89f2b0b
debug
TheChymera Aug 19, 2022
554a311
debug
TheChymera Aug 24, 2022
cb60df7
debug
TheChymera Aug 24, 2022
d7ea69f
debug
TheChymera Aug 24, 2022
6cf62dd
debug
TheChymera Aug 24, 2022
ff957d2
debug
TheChymera Aug 24, 2022
19736c4
debug
TheChymera Aug 24, 2022
7c6525a
debug
TheChymera Aug 24, 2022
b0df765
debug
TheChymera Aug 24, 2022
ab57c67
debug
TheChymera Aug 24, 2022
8a99bad
Added documentation
TheChymera Aug 24, 2022
bc14b91
debug
TheChymera Aug 24, 2022
3a85de1
debug
TheChymera Aug 24, 2022
9e9c788
debug
TheChymera Aug 24, 2022
f69c859
debug
TheChymera Aug 24, 2022
1522b5a
debug
TheChymera Aug 24, 2022
447b69d
debug
TheChymera Aug 24, 2022
3d1f1b2
debug
TheChymera Aug 24, 2022
9bf983d
black fixes
TheChymera Aug 24, 2022
61febef
debug
TheChymera Aug 24, 2022
9b17668
black and isort fixes
TheChymera Aug 24, 2022
17a7d1d
debug
TheChymera Aug 24, 2022
69af7a5
debug
TheChymera Aug 24, 2022
bf15f9d
debug
TheChymera Aug 24, 2022
9c7a877
Reverted schema version and removed debugging print call.
TheChymera Aug 24, 2022
084ade7
RF: Use importlib-resources, reduce path depth
effigies Aug 25, 2022
1993e89
CI: Add separate build and publish steps
effigies Aug 25, 2022
593f047
CI: Set global default shell
effigies Aug 25, 2022
4ad77da
STY: Prettier CI file
effigies Aug 25, 2022
b9e526f
MNT: Update test_tag
effigies Aug 25, 2022
c763bb0
Merge pull request #5 from effigies/autodata2
TheChymera Aug 25, 2022
2e55307
Update .github/workflows/schemacode_ci.yml
effigies Aug 25, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 106 additions & 52 deletions .github/workflows/schemacode_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,81 @@ on:
push:
branches:
- "master"
paths:
- "tools/schemacode/**"
- "src/schema/**"
tags:
- "schema-*"
pull_request:
branches:
- "*"
paths:
- "tools/schemacode/**"
- "src/schema/**"

jobs:
defaults:
run:
shell: bash

run_tests:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: "Install build dependencies"
run: pip install --upgrade build twine
- name: "Install test dependencies on tag"
run: pip install --upgrade pytest pyyaml pandas tabulate
if: ${{ startsWith(github.ref, 'refs/tags/schema-') }}
- name: "Build archive on tag"
run: pytest tools/schemacode/bidsschematools -k make_archive
env:
BIDSSCHEMATOOLS_RELEASE: 1
if: ${{ startsWith(github.ref, 'refs/tags/schema-') }}
- name: "Build source distribution and wheel"
run: python -m build tools/schemacode
- name: "Check distribution metadata"
run: twine check tools/schemacode/dist/*
- uses: actions/upload-artifact@v3
with:
name: dist
path: tools/schemacode/dist/

test:
runs-on: ${{ matrix.os }}
needs: [build]
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.7", "3.8", "3.9", "3.10"]
name: ${{ matrix.os }} with Python ${{ matrix.python-version }}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3

- name: "Set up Python"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
python-version: ${{ matrix.python-version }}

- name: "Display Python version"
shell: bash {0}
run: python -c "import sys; print(sys.version)"

- name: "Install the schemacode package"
shell: bash {0}
- name: "Fetch packages"
uses: actions/download-artifact@v3
with:
name: dist
path: dist/

- name: "Install package"
run: |
python -m pip install --progress-bar off --upgrade pip
python -m pip install ./tools/schemacode[all]
pip install $( ls dist/*.whl )[all]

- name: "Run tests"
shell: bash {0}
run: |
python -m pytest --pyargs bidsschematools -m "not validate_schema" --cov-append --cov-report=xml --cov=bidsschematools
python -m pytest -vs --pyargs bidsschematools -m "not validate_schema" \
--cov-append --cov-report=xml --cov=bidsschematools

- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand All @@ -58,6 +87,34 @@ jobs:
path: coverage.xml
if: success()

publish:
runs-on: ${{ matrix.os }}
name: Publish Python Package
needs: [test]
strategy:
matrix:
os: ["ubuntu-latest"]
python-version: ["3.10"]
steps:
- name: "Fetch packages"
uses: actions/download-artifact@v3
with:
name: dist
path: dist/
- name: "Test PyPI upload"
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: "Upload to PyPI (on tags)"
if: ${{ startsWith(github.ref, 'refs/tags/schema-') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}

flake8-lint:
runs-on: ubuntu-latest
name: Lint schemacode
Expand All @@ -71,56 +128,53 @@ jobs:
python-version: "3.7"

- name: Install the schemacode package
shell: bash {0}
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install -e ./tools/schemacode[all]

- name: Run flake8
working-directory: ./tools/schemacode/
shell: bash {0}
run: |
flake8 .

validate_schema:
runs-on: ubuntu-latest
name: Validate schema
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set Up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.9"
- name: Set Up Python environment
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install the schemacode package
shell: bash {0}
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install -e ./tools/schemacode[all]
- name: Install the schemacode package
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install -e ./tools/schemacode[all]

- name: Run schema validation tests
run: python -m pytest --pyargs bidsschematools -m "validate_schema" --cov-append --cov-report=xml --cov=bidsschematools
- name: Run schema validation tests
run: python -m pytest --pyargs bidsschematools -m "validate_schema" --cov-append --cov-report=xml --cov=bidsschematools

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: schema_validation
path: coverage.xml
if: success()
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: schema_validation
path: coverage.xml
if: success()

upload_to_codecov:
runs-on: "ubuntu-latest"
name: Upload coverage
needs: [run_tests,validate_schema]
needs: [test, validate_schema]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v2

- name: Download artifacts
uses: actions/download-artifact@v3
- name: Download artifacts
uses: actions/download-artifact@v3

- name: Upload to CodeCov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
- name: Upload to CodeCov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
23 changes: 23 additions & 0 deletions scripts/test_tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Execute this script from anywhere in the repository to push to a new unique testing tag.
# This is a script which automates creation and pushing of unique tags for github actions.
# It is particularly useful when debugging the upload hooks for pypi.
# The workflow for that is to edit `.github/workflows/schemacode_ci.yml` and add a secondary branch name to the `on` section right after master.
# This will allow you to keep pushing to the branch as if it were master and unix-time tagged archives being uploaded to test.pypi.

EPOCH="$(date +%s)"

GIT_DIR=$( git rev-parse --git-dir )
REPO_ROOT=$( ls -d ${GIT_DIR%.git} )

VERSION_FILE="$REPO_ROOT/src/schema/SCHEMA_VERSION"

REAL_VERSION=$(cat "${VERSION_FILE}")
DUMMY_VERSION="0.0.${EPOCH}-dev"

echo "${DUMMY_VERSION}" > "${VERSION_FILE}"
git commit -a -m "Test release $DUMMY_VERSION"
git tag -a "schema-$DUMMY_VERSION" -m "Test release $DUMMY_VERSION"

echo "${REAL_VERSION}" > "${VERSION_FILE}"
31 changes: 18 additions & 13 deletions tools/schemacode/bidsschematools/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import os
import tempfile
from subprocess import run

import pytest
try:
from importlib.resources import as_file, files
except ImportError: # PY<3.9
from importlib_resources import as_file, files

from bidsschematools import schema, utils
import pytest

lgr = logging.getLogger()

Expand Down Expand Up @@ -35,22 +37,21 @@ def get_gitrepo_fixture(url, whitelist):
@pytest.fixture(scope="session")
def fixture():
archive_name = url.rsplit("/", 1)[-1]
testdata_archive = os.path.join(os.getcwd(), "testdata", archive_name)
if os.path.isdir(testdata_archive):
testdata_dir = files("bidsschematools.tests.data") / archive_name
if testdata_dir.is_dir():
lgr.info(
"Found static testdata archive under `%s`. "
"Not downloading latest data from version control.",
testdata_archive,
f"Found static testdata archive under `{testdata_dir}`. "
"Not downloading latest data from version control."
)
yield testdata_archive
with as_file(testdata_dir) as path:
yield path
else:
lgr.info(
"No static testdata available under `%s`. "
"Attempting to fetch live data from version control.",
testdata_archive,
testdata_dir,
)
with tempfile.TemporaryDirectory() as path:
assert os.path.exists(path)
lgr.debug("Cloning %r into %r", url, path)
runout = run(
[
Expand Down Expand Up @@ -79,14 +80,18 @@ def fixture():
@pytest.fixture(scope="session")
def schema_dir():
"""Path to the schema housed in the bids-specification repo."""
from bidsschematools import utils

bids_schema = utils.get_schema_path()
return bids_schema


@pytest.fixture(scope="session")
def schema_obj(schema_dir):
def schema_obj():
"""Schema object."""
return schema.load_schema(schema_dir)
from bidsschematools import schema

return schema.load_schema()


bids_examples = get_gitrepo_fixture(
Expand Down
Empty file.
25 changes: 17 additions & 8 deletions tools/schemacode/bidsschematools/tests/test_make_testdata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import tarfile
import shutil

import pytest
try:
from importlib.resources import files
except ImportError: # PY<3.9
from importlib_resources import files

from .. import __version__
import pytest


def require_env(var):
Expand All @@ -30,9 +33,15 @@ def test_make_archive(bids_examples, bids_error_examples):
* Archives will be generated under `/tmp/bidsschematools-testdata-SCHEMA_VERSION.tar.gz`
"""

archive_name = f"bidsschematools-testdata-{__version__}"
archive_path = f"/tmp/{archive_name}.tar.gz"
testdata_dir = files("bidsschematools.tests.data")
ignore_git = shutil.ignore_patterns(".git*")
shutil.copytree(bids_examples, testdata_dir / "bids-examples", ignore=ignore_git)
shutil.copytree(bids_error_examples, testdata_dir / "bids-error-examples", ignore=ignore_git)

# Keeping this for now, it would be really nice to have a separate archive someday.
# archive_name = f"bidsschematools-testdata-{__version__}"
# archive_path = f"/tmp/{archive_name}.tar.gz"

with tarfile.open(archive_path, "w:gz") as tar:
tar.add(bids_examples, arcname=f"{archive_name}/bids-examples")
tar.add(bids_error_examples, arcname=f"{archive_name}/bids-error-examples")
# with tarfile.open(archive_path, "w:gz") as tar:
# tar.add(bids_examples, arcname=f"{archive_name}/bids-examples")
# tar.add(bids_error_examples, arcname=f"{archive_name}/bids-error-examples")
2 changes: 1 addition & 1 deletion tools/schemacode/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bidsschematools =
data/schema/BIDS_VERSION
data/schema/SCHEMA_VERSION
data/schema/**/*.yaml
tests/data/*
tests/data/**/*

[options.entry_points]
console_scripts =
Expand Down