From 9a31696864002939198f252a74819e995e6be5e0 Mon Sep 17 00:00:00 2001 From: William Brannon Date: Sat, 6 Jan 2024 12:10:26 -0500 Subject: [PATCH 1/2] continuous integration for tests --- .github/identify_collections_to_test.py | 51 +++++++++++++++++++++++++ .github/workflows/ci.yml | 40 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/identify_collections_to_test.py create mode 100644 .github/workflows/ci.yml diff --git a/.github/identify_collections_to_test.py b/.github/identify_collections_to_test.py new file mode 100644 index 00000000..014d7e00 --- /dev/null +++ b/.github/identify_collections_to_test.py @@ -0,0 +1,51 @@ +import os +import json +import fnmatch +import subprocess + + +def get_changed_files(): + return subprocess.check_output([ + 'git', 'diff', + '--name-only', 'origin/main...' + ]).decode().splitlines() + + +def get_collections_from_file(file): + with open(file, 'rt') as f: + data = json.load(f) + + collections = [] + for k in data.keys(): + if 'Collection' in data[k].keys(): + collections += [data[k]['Collection']] + + # we're only running in response to changes in data_summaries/*.json files, + # so if there's such a file without a collection field we don't like that + # and should fail the test + assert len(collections) > 0 + + return collections + + +def main(): + changed_files = get_changed_files() + + collections_to_test = [] + for file in changed_files: + if not fnmatch.fnmatch(file, 'data_summaries/*.json'): + continue + + if not os.path.exists(file): # i.e., file was deleted + continue + + collections_to_test += get_collections_from_file(file) + + if collections_to_test: + print("::set-output name=collections::" + '\n'.join(collections_to_test)) + else: + print("::set-output name=collections::") + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..fae952ba --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI to test new collections + +on: + pull_request: + paths: + - 'data_summaries/**.json' # Trip only when data summary changed/added + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Cache Python dependencies + uses: actions/cache@v2 + id: cache + with: + path: ~/.cache/pip # This path can vary depending on your OS and Python version + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: | + pip install -U pip + pip install -r requirements.txt + + - name: Identify Collections + run: python .github/identify_collections_to_test.py + + - name: Run Tests + run: | + while IFS= read -r collection; do + python run_tests.py "$collection" + done <<< "${{ steps.collection.outputs.collections }}" From 25a5a4c9f997706386b849fdf678c70d461b08f2 Mon Sep 17 00:00:00 2001 From: William Brannon Date: Wed, 31 Jan 2024 17:39:17 -0500 Subject: [PATCH 2/2] use correct teest script name --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fae952ba..56f628d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,5 +36,5 @@ jobs: - name: Run Tests run: | while IFS= read -r collection; do - python run_tests.py "$collection" + python src/test_new_collection.py --collection "$collection" done <<< "${{ steps.collection.outputs.collections }}"