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

Continuous integration for tests #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
51 changes: 51 additions & 0 deletions .github/identify_collections_to_test.py
Original file line number Diff line number Diff line change
@@ -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()
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 src/test_new_collection.py --collection "$collection"
done <<< "${{ steps.collection.outputs.collections }}"