diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index b73e9d5..f9ce930 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -11,7 +11,7 @@ jobs: container: image: ghcr.io/metabolicatlas/memote-docker:0.13 volumes: - - /Users/petre/standard-gem-validation/crap:/project:rw + - ${{ github.workspace }}:/project:rw options: --user root --workdir /project outputs: matrix: ${{ steps.set-matrix.outputs.matrix }} @@ -29,14 +29,14 @@ jobs: git config --global --add safe.directory /__w/standard-GEM-validation/standard-GEM-validation python -c 'import runner; runner.matrix()' - # - name: Commit index of standard-GEMs - # uses: stefanzweifel/git-auto-commit-action@v5 - # with: - # commit_user_name: validation-bot - # commit_message: update index of standard-GEMs - # file_pattern: index.json - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Commit index of standard-GEMs + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_user_name: validation-bot + commit_message: update index of standard-GEMs + file_pattern: index.json + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Define job matrix from index id: set-matrix @@ -48,7 +48,7 @@ jobs: container: image: ghcr.io/metabolicatlas/memote-docker:0.13 volumes: - - /Users/petre/standard-gem-validation/crap:/project:rw + - ${{ github.workspace }}:/project:rw options: --user root --workdir /project continue-on-error: true env: @@ -70,14 +70,14 @@ jobs: git config --global --add safe.directory /__w/standard-GEM-validation/standard-GEM-validation python -c 'import runner; runner.validate("${{ matrix.gem }}")' - # - name: Update branch - # run: git pull --ff + - name: Update branch + run: git pull --ff - # - name: Auto-commit results - # uses: stefanzweifel/git-auto-commit-action@v5 - # with: - # commit_user_name: validation-bot - # commit_message: update validation results for ${{ matrix.gem }} - # file_pattern: results/*.json - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Auto-commit results + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_user_name: validation-bot + commit_message: update validation results for ${{ matrix.gem }} + file_pattern: results/*.json + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/runner.py b/runner.py index 849acc0..ca06e79 100644 --- a/runner.py +++ b/runner.py @@ -10,7 +10,6 @@ MODEL_FILENAME = 'model' MODEL_FORMATS = ['.yml', '.xml', '.mat', '.json'] RELEASES = 5 -TEST_RESULTS = {} header_auth = {'Authorization': 'token %s' % API_TOKEN} # additional_branch_tags = [] @@ -56,7 +55,7 @@ def releases(nameWithOwner): release_tags = list(map(lambda x: x['node']['tagName'], json_data)) if not release_tags: return [] - return release_tags + additional_branch_tags + return additional_branch_tags + release_tags def matrix(): m = json.dumps(list(gem_repositories())) @@ -80,10 +79,11 @@ def validate(nameWithOwner): for model_release in releases(nameWithOwner): release_data = {} standard_gem_releases = releases('MetabolicAtlas/standard-GEM') - last_standard = standard_gem_releases[len(standard_gem_releases)-3:-2] + last_standard = standard_gem_releases[len(standard_gem_releases)-1:] for standard_version in last_standard: print("{}: {} | standard-GEM version: {}".format(nameWithOwner, model_release, standard_version)) gem_is_standard = gem_follows_standard(nameWithOwner, model_release, standard_version) + test_results = {} if gem_is_standard: for model_format in MODEL_FORMATS: my_model = model + model_format @@ -91,13 +91,13 @@ def validate(nameWithOwner): if response.ok: with open(my_model, 'w') as file: file.write(response.text) - resultJSONString(tests.yaml.validate, model) - resultJSONString(tests.cobra.loadYaml, model) - resultJSONString(tests.cobra.loadSbml, model) - resultJSONString(tests.cobra.loadMatlab, model) - resultJSONString(tests.cobra.loadJson, model) - resultJSONString(tests.cobra.validateSbml, model) - resultJSONString(tests.memote.scoreAnnotationAndConsistency, model) + test_results.update(resultJSONString(tests.cobra.loadYaml, model)) + test_results.update(resultJSONString(tests.cobra.loadSbml, model)) + test_results.update(resultJSONString(tests.cobra.loadMatlab, model)) + test_results.update(resultJSONString(tests.cobra.loadJson, model)) + test_results.update(resultJSONString(tests.cobra.validateSbml, model)) + test_results.update(resultJSONString(tests.yaml.validate, model)) + test_results.update(resultJSONString(tests.memote.scoreAnnotationAndConsistency, model)) else: print('is not following standard') release_data = { 'standard-GEM' : [ { standard_version : gem_is_standard }, { 'test_results' : test_results} ] } @@ -106,5 +106,5 @@ def validate(nameWithOwner): output.write(json.dumps(data, indent=2, sort_keys=True)) def resultJSONString(testToRun, model): - testModule, moduleVersion, status, errors = testToRun(model) - TEST_RESULTS.update({testModule: { moduleVersion : status, 'errors': errors[:300] } }) \ No newline at end of file + testModule, description, moduleVersion, status, errors = testToRun(model) + return {testModule: { 'description': description, 'version': moduleVersion, 'status': status, 'errors': errors[:300] } } \ No newline at end of file diff --git a/tests/cobra.py b/tests/cobra.py index 97b43f2..3a23b42 100644 --- a/tests/cobra.py +++ b/tests/cobra.py @@ -1,73 +1,83 @@ import cobra import json +from pathlib import Path def loadYaml(model_name): - print('load yaml') - is_valid = False + description = 'Check if the model in YAML can be loaded with cobrapy.' + print(description) + status = False errors = '' try: cobra.io.load_yaml_model(model_name + '.yml') - is_valid = True + status = True except FileNotFoundError: errors = "File missing" except Exception as e: errors = json.dumps(str(e)) print(e) - return 'cobrapy-load-yaml', cobra.__version__, is_valid, errors + return 'cobrapy-load-yaml', description, cobra.__version__, status, errors def loadSbml(model_name): - print('load sbml') - is_valid = False + description = 'Check if the model in SBML format can be loaded with cobrapy.' + print(description) + status = False errors = '' try: cobra.io.read_sbml_model(model_name + '.xml') - is_valid = True + status = True except FileNotFoundError: errors = "File missing" except Exception as e: errors = json.dumps(str(e)) print(e) - return 'cobrapy-load-sbml', cobra.__version__, is_valid, errors + return 'cobrapy-load-sbml', description, cobra.__version__, status, errors def loadMatlab(model_name): - print('load matlab') - is_valid = False + description = 'Check if the model in Matlab format can be loaded with cobrapy.' + print(description) + status = False errors = '' try: - cobra.io.load_matlab_model(model_name + '.mat') - is_valid = True + data_dir = Path(".") / ".." + data_dir = data_dir.resolve() + model_path = data_dir / "{}.mat".format(model_name) + cobra.io.load_matlab_model(str(model_path.resolve())) + status = True except FileNotFoundError: errors = "File missing" except Exception as e: errors = json.dumps(str(e)) print(e) - return 'cobrapy-load-matlab', cobra.__version__, is_valid, errors + return 'cobrapy-load-matlab', description, cobra.__version__, status, errors def loadJson(model_name): - print('load json') - is_valid = False + description = 'Check if the model in JSON format can be loaded with cobrapy.' + print(description) + status = False errors = '' try: cobra.io.load_json_model(model_name + '.json') - is_valid = True + status = True except FileNotFoundError: errors = "File missing" except Exception as e: errors = json.dumps(str(e)) print(e) - return 'cobrapy-load-json', cobra.__version__, is_valid, errors + return 'cobrapy-load-json', description, cobra.__version__, status, errors def validateSbml(model_name): - print('validate sbml with cobrapy') - is_valid = False + description = 'Check with cobrapy if the model in SBML format is valid.' + print(description) + status = False + errors = '' try: _, result = cobra.io.sbml.validate_sbml_model(model_name + '.xml') - if result == {}: - is_valid = True + if result['SBML_FATAL'] == [] and result['SBML_ERROR'] == [] and result['SBML_SCHEMA_ERROR'] == [] and result['COBRA_FATAL'] == [] and result['COBRA_ERROR'] == []: + status = True else: raise Exception(result) except Exception as e: errors = json.dumps(str(e)) print(e) - return 'cobrapy-validate-sbml', cobra.__version__, is_valid, errors \ No newline at end of file + return 'cobrapy-validate-sbml', description, cobra.__version__, status, errors \ No newline at end of file diff --git a/tests/memote.py b/tests/memote.py index 8b034d6..e3004c3 100644 --- a/tests/memote.py +++ b/tests/memote.py @@ -3,7 +3,8 @@ import memote def scoreAnnotationAndConsistency(model_name): - print('memote scoring') + description = 'Check the score of the model in SBML format with Memote.' + print(description) memote_score = False errors = '' try: @@ -16,4 +17,4 @@ def scoreAnnotationAndConsistency(model_name): except Exception as e: errors = json.dumps(str(e)) print(e) - return 'memote-score', memote.__version__, memote_score, errors \ No newline at end of file + return 'memote-score', description, memote.__version__, memote_score, errors \ No newline at end of file diff --git a/tests/yaml.py b/tests/yaml.py index c1890fd..d1ed721 100644 --- a/tests/yaml.py +++ b/tests/yaml.py @@ -3,7 +3,8 @@ import json def validate(model_name): - print('validate YAML with yamllint') + description = 'Check if the model in YAML format is formatted correctly.' + print(description) is_valid = False errors = '' try: