Skip to content

Commit

Permalink
updated workflow files
Browse files Browse the repository at this point in the history
  • Loading branch information
ersilia-bot committed Nov 21, 2024
1 parent 5161685 commit 9bdb713
Show file tree
Hide file tree
Showing 9 changed files with 602 additions and 350 deletions.
49 changes: 49 additions & 0 deletions .github/scripts/resolve_dockerfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import sys
import os
import requests

from ersilia_pack.parsers import DockerfileInstallParser, YAMLInstallParser

REPO_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../.."))
PY_VERSION_MAP = {
'3.8': 'py38',
'3.9': 'py39',
'3.10': 'py310',
'3.11': 'py311',
'3.12': 'py312'
}
model_id = sys.argv[1]
def resolve_parser():
if os.path.exists(os.path.abspath(os.path.join(REPO_PATH, "Dockerfile"))):
return DockerfileInstallParser(file_dir=REPO_PATH)
elif os.path.exists(os.path.join(REPO_PATH, "install.yml")):
return YAMLInstallParser(file_dir=REPO_PATH)
else:
raise ValueError("No install file found")

def resolve_python_version(parser):
return parser._get_python_version()

def read_dockerfile(parser):
commands = parser._get_commands()
has_conda = parser._has_conda(commands)
if has_conda:
file_url = "https://raw.githubusercontent.com/ersilia-os/ersilia/master/dockerfiles/dockerize-ersiliapack/model/Dockerfile.conda"
else:
file_url = "https://raw.githubusercontent.com/ersilia-os/ersilia/master/dockerfiles/dockerize-ersiliapack/model/Dockerfile.pip"
response = requests.get(file_url)
return response.text

def write_version_and_model_id(file_content, python_version):
python_version = PY_VERSION_MAP[python_version]
file_content = file_content.replace("eos_identifier", model_id)
lines = file_content.split("\n")
lines[0] = lines[0].replace("VERSION", python_version)
with open(os.path.join(REPO_PATH, "../", "Dockerfile"), "w") as f:
f.write("\n".join(lines))

if __name__ == "__main__":
parser = resolve_parser()
python_version = resolve_python_version(parser)
dockerfile = read_dockerfile(parser)
write_version_and_model_id(dockerfile, python_version)
2 changes: 1 addition & 1 deletion .github/scripts/verify_model_outcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def check_non_null_outcomes_in_output_csv(csv_file_path):
header = next(csv_reader)
row = next(csv_reader)
for val in row[2:]: # Skip the first two columns (Inchikey and input)
if val not in ['', None]:
if val not in ['', None]: # Returns if even one outcome is not null
return False
return True

Expand Down
179 changes: 179 additions & 0 deletions .github/workflows/post-model-upload.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
name: Post Model Upload actions

on:
workflow_run:
workflows: ["Upload model to DockerHub"]
types:
- completed

jobs:
post-model-upload:
if: ${{ github.repository != 'ersilia-os/eos-template' }}
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Download arch.txt
uses: actions/download-artifact@v4
with:
name: arch
path: .
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Check metadata file
id: checkMetadata
continue-on-error: true
run: |
if [[ ! -f metadata.yml ]]; then
echo "metadata.yml file not found"
exit 1
fi
- name: Update Metadata YAML file with DockerHub info
id: updateMetadataYAML
if: steps.checkMetadata.outcome == 'success'
run: |
python3 -c "
import yaml
with open('metadata.yml', 'r') as f:
data = yaml.safe_load(f)
print(data)
with open('arch.txt', 'r') as f:
arch = f.read().rstrip()
arch = arch.split(',')
data['DockerHub'] = 'https://hub.docker.com/r/ersiliaos/{0}'.format(data['Identifier'])
data['Docker Architecture'] = arch
with open('metadata.yml', 'w') as f:
yaml.dump(data, f, default_flow_style=False, sort_keys=False)
"
rm arch.txt
- name: Update Metadata JSON file with DockerHub info
id: updateMetadataJSON
if: steps.checkMetadata.outcome == 'failure'
run: |
python3 -c "
import json
with open('metadata.json', 'r') as f:
data = json.load(f)
print(data)
with open('arch.txt', 'r') as f:
arch = f.read().rstrip()
arch = arch.split(',')
data['DockerHub'] = 'https://hub.docker.com/r/ersiliaos/{0}'.format(data['Identifier'])
data['Docker Architecture'] = arch
with open('metadata.json', 'w') as f:
json.dump(data, f, indent=4)
"
rm arch.txt

- name: Commit and push changes done to the Metadata file
uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # [email protected]
with:
author_name: "ersilia-bot"
author_email: "[email protected]"
message: "updating metadata [skip ci]"
repository: "ersilia-os/${{ github.event.repository.name }}"
github_token: ${{ secrets.GITHUB_TOKEN }}
amend: true
force: true

# Setup conda
- name: Setup conda
id: setupConda
uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.10.10"

# Install ersilia
- name: Install dependencies in Conda environment
id: installDependenciesInConda
run: |
conda install gh -c conda-forge
python -m pip install git+https://github.com/ersilia-os/ersilia.git
- name: Update metadata to AirTable
id: update-metadata-to-airtable
env:
USER_NAME: ${{ github.repository_owner }}
BRANCH: "main"
REPO_NAME: ${{ github.event.repository.name }}
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
run: |
echo "Updating metadata to AirTable looking at owner: $USER_NAME"
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH $AIRTABLE_API_KEY
rm update_metadata_to_airtable.py
- name: Update README file
id: update-readme-file
env:
MODEL_ID: ${{ github.event.repository.name }}
run: |
echo "Updating README file with AirTable metadata for model: $MODEL_ID"
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_readme_from_airtable.py
python3 update_readme_from_airtable.py $MODEL_ID .
rm update_readme_from_airtable.py
less README.md
- name: Commit and push changes done to the README file
uses: actions-js/push@156f2b10c3aa000c44dbe75ea7018f32ae999772 # [email protected]
with:
author_name: "ersilia-bot"
author_email: "[email protected]"
message: "updating readme [skip ci]"
repository: "ersilia-os/${{ github.event.repository.name }}"
github_token: ${{ secrets.GITHUB_TOKEN }}
amend: true
force: true

- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: ersiliaos/${{ github.event.repository.name }}
short-description: "Ersilia Model Hub Identifier: ${{ github.event.repository.name }}"

# Create an issue within the repository to track that this model is ready for testing

- name: Shuffle assignees
id: shuffle
run: |
export assignees=$(echo "${{ vars.assignees }}" | awk 'BEGIN {FS=","}; {srand();split($0,a,FS); print a[int(rand()*NF+1)]}')
echo "$assignees" >> $GITHUB_STEP_SUMMARY
echo "shuffled_assignee=$assignees" >> $GITHUB_OUTPUT
echo "shuffled_assignee=$assignees" >> $GITHUB_ENV
- name: Check for existing issue
id: check_existing_test_issue
run: |
gh auth login --with-token <<< ${{ secrets.GITHUB_TOKEN }}
issue_number=$(gh issue list --limit 100 --search "${{ vars.test_issue_title }}" --json number --jq '.[0].number')
echo "::set-output name=issue_number::$issue_number"
- name: Create a Test issue
uses: actions-ecosystem/action-create-issue@b63bc2bbacb6a838dfe4a9f70da6665ae0962a49
id: create_test_issue
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
title: ${{ vars.TEST_ISSUE_TITLE }}
assignees: |
${{ steps.shuffle.outputs.shuffled_assignee }}
body: |
This model is a new incorporation to the Ersilia Model Hub or it has been modified. If you are assigned to this issue, please try it out and ensure everything works!
To test a model, first clone it in your local system (ideally, from dockerhub) using the CLI commands:
```
ersilia -v fetch eosxxxx --from_dockerhub
ersilia serve eosxxxx
ersilia test
```
The test command will automatically check that the model can handle null outputs and whether it produces consistent results. Please copy here the result of the test command. If it passes, simply close the issue as completed. If it fails, please detail at which step and whether you have taken any steps to solve it. Please tag the original model contributor and one of Ersilia's maintainers for support.
labels: |
test
if: steps.check_existing_test_issue.outputs.issue_number == ''
37 changes: 23 additions & 14 deletions .github/workflows/test-model-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,35 @@ jobs:
USER_NAME: ${{ github.event.pull_request.head.repo.owner.login }}
BRANCH: "main"
REPO_NAME: ${{ github.event.repository.name }}
run: |
source activate
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: |
source activate
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH
- name: Predict output
env:
MODEL_ID: ${{ github.event.repository.name }}
run: |
source activate
echo "Sample model id selected: $MODEL_ID"
ersilia -v fetch $MODEL_ID --repo_path .
ersilia -v serve $MODEL_ID
ersilia sample -n 5 -f input.csv
ersilia -v api -i input.csv
ersilia close
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: |
source activate
echo "Sample model id selected: $MODEL_ID"
ersilia -v fetch $MODEL_ID --repo_path .
ersilia -v serve $MODEL_ID
ersilia example -n 5 -f input.csv --predefined
ersilia -v api -i input.csv
ersilia close
- name: Upload log output
if: always()
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb #pin v3.1.1
with:
name: debug-logs
retention-days: 1
path: /home/runner/eos/console.log
retention-days: 14
path: /home/runner/eos/*.log
60 changes: 43 additions & 17 deletions .github/workflows/test-model.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ jobs:
BRANCH: "main"
REPO_NAME: ${{ github.event.repository.name }}
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }}
run: |
source activate
echo "Updating metadata to AirTable looking at owner: $USER_NAME"
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH $AIRTABLE_API_KEY
rm update_metadata_to_airtable.py
uses: nick-fields/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
command: |
source activate
echo "Updating metadata to AirTable looking at owner: $USER_NAME"
wget https://raw.githubusercontent.com/ersilia-os/ersilia/master/.github/scripts/update_metadata_to_airtable.py
python3 update_metadata_to_airtable.py $USER_NAME $REPO_NAME $BRANCH $AIRTABLE_API_KEY
rm update_metadata_to_airtable.py
- name: Update README file
id: update-readme-file
Expand All @@ -96,22 +100,44 @@ jobs:
amend: true
force: true

- name: Predict output
- name: Fetch model
env:
MODEL_ID: ${{ github.event.repository.name }}
run: |
source activate
echo "Sample model id selected: $MODEL_ID"
ersilia -v fetch $MODEL_ID --repo_path .
ersilia -v serve $MODEL_ID
ersilia sample -n 5 -f input.csv
ersilia -v api -i input.csv
ersilia close
source activate
ersilia -v fetch $MODEL_ID --repo_path .
FOLDER="$HOME/eos/repository/$MODEL_ID"
if [ ! -d "$FOLDER" ]; then
echo "Error: Folder '$FOLDER' does not exist." >&2
exit 1
fi
- name: Serve model
env:
MODEL_ID: ${{ github.event.repository.name }}
run: |
source activate
ersilia -v serve $MODEL_ID
- name: Test model
env:
MODEL_ID: ${{ github.event.repository.name }}
run: |
source activate
ersilia example -n 5 -f input.csv --predefined
ersilia -v run -i "input.csv" -o "output.csv"
ersilia close
output=$(python .github/scripts/verify_model_outcome.py output.csv)
if echo "$output" | grep -q "All outcomes are null"; then
echo "Error in model outcome, aborting test"
exit 1
fi
rm output.csv
- name: Upload log output
if: always()
uses: actions/upload-artifact@83fd05a356d7e2593de66fc9913b3002723633cb #pin v3.1.1
with:
name: debug-logs
retention-days: 1
path: /home/runner/eos/console.log

retention-days: 14
path: /home/runner/eos/*.log
Loading

0 comments on commit 9bdb713

Please sign in to comment.