Skip to content

approve-command

approve-command #217

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@9bb56186c3b09b4f86b1c65136769dd318469633 # pin@v3.5.3
# 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/issue-template-parser@v7.0.1
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@82c7e631bb3cdc910f68e0081d67478d79c6982d # pin@v5.1.0
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 to conda environment
run: |
source activate
conda install -c conda-forge pygithub
# 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.json file
- name: commit metadata.json
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@9bb56186c3b09b4f86b1c65136769dd318469633 # pin@v3.5.3
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@156f2b10c3aa000c44dbe75ea7018f32ae999772 # pin@v1.4
with:
author_name: "ersilia-bot"
author_email: "ersilia-bot@users.noreply.github.com"
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@d5cdf0243751ca01060946b2cae3722e508b7b16 # pin@v2.0.9
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@d5cdf0243751ca01060946b2cae3722e508b7b16 # pin@v2.0.9
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 }}