approve-command #248
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Approve Command Dispatch | |
on: | |
repository_dispatch: | |
types: [ approve-command ] | |
permissions: | |
issues: write | |
contents: read | |
jobs: | |
approve-command-dispatch: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # [email protected] | |
# construct the url to this workflow run | |
- name: workflow url | |
id: workflow-url | |
run: | | |
echo "workflow_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT | |
# parse the issue body from free form text to a structured JSON object | |
- name: parse issue | |
uses: GrantBirki/[email protected] | |
id: issue-parser | |
with: | |
body: ${{ github.event.client_payload.github.payload.issue.body }} | |
# echo the parsed issue body to the console for debugging if we need to | |
- name: echo body | |
run: echo $ISSUE_BODY | |
env: | |
ISSUE_BODY: ${{ steps.issue-parser.outputs.json }} | |
# setup python | |
- name: setup python | |
uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # [email protected] | |
with: | |
python-version: "3.10" | |
# cache: 'pip' # caching pip dependencies | |
# setup conda | |
- name: add conda to system path | |
run: echo $CONDA/bin >> $GITHUB_PATH | |
- name: source conda | |
run: source $CONDA/etc/profile.d/conda.sh | |
- name: install dependencies through conda | |
run: | | |
source activate | |
conda init | |
conda install git-lfs -c conda-forge | |
git-lfs install | |
conda install gh -c conda-forge | |
# add PyGithub to the conda environment | |
- name: add PyGithub and Pyyaml to conda environment | |
run: | | |
source activate | |
conda install -c conda-forge pygithub pyyaml | |
# create the model repo from the template | |
- name: create model repo | |
id: create-model-repo | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} # PAT for the ersilia-bot GitHub account | |
OWNER: ersilia-os | |
JSON: ${{ steps.issue-parser.outputs.json }} | |
TEMPLATE: ersilia-os/eos-template | |
FLAGS: --public | |
run: | | |
REPO_NAME=$(python3 .github/scripts/generate_eos_identifier.py) | |
gh repo create ${OWNER}/${REPO_NAME} --template $TEMPLATE $FLAGS | |
echo "repo_name=${REPO_NAME}" >> $GITHUB_OUTPUT | |
# commit updates to the metadata.yaml file | |
- name: commit metadata.yaml | |
id: update-metadata | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} # PAT for the ersilia-bot GitHub account | |
OWNER: ersilia-os | |
REPO: ${{ steps.create-model-repo.outputs.repo_name }} | |
JSON: ${{ steps.issue-parser.outputs.json }} | |
run: | | |
python3 .github/scripts/update_metadata.py | |
# upload git-lfs object | |
- name: checkout persist credentials | |
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # [email protected] | |
with: | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo | |
- name: remove ersilia repo | |
run: | | |
rm -rf * | |
- name: clone the repository | |
uses: GuillaumeFalourd/clone-github-repo-action@62795acaa4a02f89824de75c7025459a9cabaa45 # pin@v3 | |
with: | |
owner: 'ersilia-os' | |
repository: ${{ steps.create-model-repo.outputs.repo_name }} | |
- name: create a mock git-lfs object to enable contributions | |
id: mock-lfs | |
env: | |
REPO: ${{ steps.create-model-repo.outputs.repo_name }} | |
run: | | |
cd $REPO | |
git lfs install | |
echo "This is a mock git lfs file" > mock.txt | |
git lfs track mock.txt | |
git add .gitattributes | |
git add mock.txt | |
git lfs ls-files | |
- name: commit and push changes | |
uses: actions-js/push@5a7cbd780d82c0c937b5977586e641b2fd94acc5 # [email protected] | |
with: | |
author_name: "ersilia-bot" | |
author_email: "[email protected]" | |
message: "mock lfs [skip ci]" | |
directory: ${{ steps.create-model-repo.outputs.repo_name }} | |
repository: "ersilia-os/${{ steps.create-model-repo.outputs.repo_name }}" | |
github_token: ${{ secrets.PAT }} | |
amend: true | |
force: true | |
# sync metadata to airtable | |
# now that the repo has been created, and the metadata.json file has been updated, we can sync the metadata to airtable | |
- name: sync metadata to airtable | |
id: sync-metadata-to-airtable | |
env: | |
REPO_NAME: ${{ steps.create-model-repo.outputs.repo_name }} | |
REPO: ersilia | |
OWNER: ersilia-os | |
ISSUE_NUMBER: ${{ github.event.client_payload.github.payload.issue.number }} | |
AIRTABLE_API_KEY: ${{ secrets.AIRTABLE_API_KEY }} | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
source activate | |
ISSUE_CREATOR=$(gh api /repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER} | jq -r '.user.login') | |
echo "issue_creator=${ISSUE_CREATOR}" | |
python3 -m pip install pyairtable | |
python3 -m pip install requests | |
python3 .github/scripts/insert_metadata_to_airtable.py $REPO_NAME $ISSUE_CREATOR $AIRTABLE_API_KEY | |
# find the creator of the issue | |
- name: find original issue creator | |
id: issue-creator | |
env: | |
ISSUE_NUMBER: ${{ github.event.client_payload.github.payload.issue.number }} | |
OWNER: ersilia-os | |
REPO: ersilia | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
ISSUE_CREATOR=$(gh api /repos/${OWNER}/${REPO}/issues/${ISSUE_NUMBER} | jq -r '.user.login') | |
echo "issue_creator=${ISSUE_CREATOR}" >> $GITHUB_OUTPUT | |
# comment on the issue comment with further instructions for the user | |
- name: comment | |
uses: GrantBirki/comment@f524ee31407667c05061bad41e1758b40298bd82 # [email protected] | |
with: | |
issue-number: ${{ github.event.client_payload.github.payload.issue.number }} | |
file: .github/templates/new-model.md | |
vars: | | |
repo_name: ${{ steps.create-model-repo.outputs.repo_name }} | |
issue_creator: ${{ steps.issue-creator.outputs.issue_creator }} | |
# steps to run if the workflow fails for any reason | |
- name: comment on failure | |
if: failure() | |
uses: GrantBirki/comment@f524ee31407667c05061bad41e1758b40298bd82 # [email protected] | |
with: | |
issue-number: ${{ github.event.client_payload.github.payload.issue.number }} | |
file: .github/templates/approve-workflow-failed.md | |
vars: | | |
repo_name: ${{ steps.create-model-repo.outputs.repo_name }} | |
issue_creator: ${{ steps.issue-creator.outputs.issue_creator }} | |
workflow_url: ${{ steps.workflow-url.outputs.workflow_url }} |