cenki-tok-2020-crustal-roots-in-stable-continents #320
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 Label Trigger | |
on: | |
issues: | |
types: | |
- labeled | |
jobs: | |
parseNewIssue: | |
if: contains(github.event.label.name, 'new model') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Create m@te-bot token | |
- name: create token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
# Comment on issue | |
- name: Comment on submission | |
id: submission-comment | |
uses: GrantBirki/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
issue-number: ${{ github.event.issue.number }} | |
file: .github/templates/new-model.md | |
# setup python | |
- name: setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
cache: "pip" | |
- run: pip install -r requirements.txt | |
# generate report | |
- name: generate report | |
env: | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
COMMENT_ID: ${{ steps.submission-comment.outputs.comment-id }} | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
run: | | |
python3 .github/scripts/write_report.py | |
# steps if failure | |
- name: workflow url | |
if: failure() | |
id: workflow-url | |
run: | | |
echo "workflow_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT | |
- name: comment on failure | |
if: failure() | |
uses: GrantBirki/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
issue-number: ${{ github.event.issue.number }} | |
file: .github/templates/parse-workflow-fail.md | |
vars: | | |
workflow_url: ${{ steps.workflow-url.outputs.workflow_url }} | |
- name: add fail label | |
if: failure() | |
uses: actions-ecosystem/[email protected] | |
with: | |
github_token: ${{ steps.app-token.outputs.token }} | |
labels: workflow_error | |
requestReview: | |
if: contains(github.event.label.name, 'review requested') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Create m@te-bot token | |
- name: create token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
# Create notification comment | |
- name: notify | |
uses: GrantBirki/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
issue-number: ${{ github.event.issue.number }} | |
file: .github/templates/review-request.md | |
vars: | | |
recipients: "@ModelAtlasofTheEarth/model_reviewers" | |
createRepoAuthorization: | |
if: contains(github.event.label.name, 'model approved') | |
runs-on: ubuntu-latest | |
outputs: | |
authorized: ${{ steps.verify_labeler.outputs.authorized }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# setup python | |
- name: setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
cache: "pip" | |
- run: pip install -r requirements.txt | |
- name: create token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner}} | |
- name: Verify Labeler | |
id: verify_labeler | |
env: | |
TOKEN: ${{ steps.app-token.outputs.token }} | |
USER: ${{ github.event.sender.login }} | |
OWNER: ${{ github.event.repository.owner.login }} | |
REPO: ${{ github.event.repository.name }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
run: | | |
AUTHORIZED=$(python3 .github/scripts/approval_authorization.py) | |
echo "authorized=${AUTHORIZED}" >> $GITHUB_OUTPUT | |
- name: comment if unauthorized | |
if: ${{ steps.verify_labeler.outputs.authorized == 'False' }} | |
uses: GrantBirki/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
issue-number: ${{ github.event.issue.number }} | |
file: .github/templates/unauthorized-approval.md | |
createNewRepo: | |
needs: createRepoAuthorization | |
if: ${{ needs.createRepoAuthorization.outputs.authorized == 'True' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# setup python | |
- name: setup python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
cache: "pip" | |
- run: pip install -r requirements.txt | |
- name: create token | |
uses: actions/create-github-app-token@v1 | |
id: app-token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
owner: ${{ github.repository_owner}} | |
# create the model repo from the template | |
- name: create model repo | |
id: create-model-repo | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
OWNER: ${{ github.event.repository.owner.login }} | |
SUBMITTER: ${{ github.event.issue.user.login }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
TEMPLATE: mate-model-template | |
FLAGS: --public | |
run: | | |
REPO_NAME=$(python3 .github/scripts/generate_identifier.py) | |
gh repo create ${OWNER}/${REPO_NAME} --template ${OWNER}/$TEMPLATE $FLAGS | |
echo "repo_name=${REPO_NAME}" >> $GITHUB_OUTPUT | |
gh api --method=PUT "repos/${OWNER}/${REPO_NAME}/collaborators/${SUBMITTER}" -f permission=admin | |
gh api --method=POST "repos/${OWNER}/${REPO_NAME}/labels" -f name='model published' -f description='Model published' -f color=B93BCB | |
# parse metadata and write files to repo | |
- name: write metadata | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
OWNER: ${{ github.event.repository.owner.login }} | |
REPO: ${{ steps.create-model-repo.outputs.repo_name }} | |
ISSUE_NUMBER: ${{ github.event.issue.number }} | |
run: | | |
python3 .github/scripts/write_repo_contents.py | |
# steps if failure | |
- name: workflow url | |
if: failure() | |
id: workflow-url | |
run: | | |
echo "workflow_url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT | |
# remove created repo | |
- name: remove repo | |
if: failure() | |
env: | |
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
OWNER: ${{ github.event.repository.owner.login }} | |
REPO_NAME: ${{ steps.create-model-repo.outputs.repo_name }} | |
run: | | |
gh api --method=DELETE "repos/${OWNER}/${REPO_NAME}" | |
- name: comment on failure | |
if: failure() | |
uses: GrantBirki/[email protected] | |
with: | |
token: ${{ steps.app-token.outputs.token }} | |
issue-number: ${{ github.event.issue.number }} | |
file: .github/templates/repo-workflow-fail.md | |
vars: | | |
repo_name: ${{ steps.create-model-repo.outputs.repo_name }} | |
workflow_url: ${{ steps.workflow-url.outputs.workflow_url }} | |
- name: add fail label | |
if: failure() | |
uses: actions-ecosystem/[email protected] | |
with: | |
github_token: ${{ steps.app-token.outputs.token }} | |
labels: workflow_error | |
- name: add model created label | |
uses: actions-ecosystem/[email protected] | |
with: | |
github_token: ${{ steps.app-token.outputs.token }} | |
labels: model created |