Skip to content

Commit

Permalink
Merge pull request #71 from WCRP-CORDEX/workflow
Browse files Browse the repository at this point in the history
Workflow
  • Loading branch information
larsbuntemeyer authored Apr 11, 2024
2 parents 4126c30 + 9584518 commit c6d064e
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 8 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/add-id.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Process registration
on:
repository_dispatch:
types: [register-command]
concurrency: 'main'
jobs:
add_id:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
contents: write
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: '16'

- name: Setup Python
uses: actions/[email protected]
with:
python-version: 3.9
- name: Show info
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo ${{ github.event.label.name }}
#echo ${{ github.event.client_payload.github.payload.issue.label }}
gh api --jq '.labels.[].name' /repos/{owner}/{repo}/issues/${{ github.event.number }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
cd scripts; pip install -e . --no-deps
- name: check labels
id: label
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
table=`python labels.py /repos/{owner}/{repo}/issues/${{ github.event.client_payload.github.payload.issue.number }}`
echo $table
echo "table=$table" >> $GITHUB_OUTPUT
- uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
template-path: .github/ISSUE_TEMPLATE/${{ steps.label.outputs.table }}.yaml
issue-body: ${{ github.event.client_payload.github.payload.issue.body }}

- name: update table
id: update
run: |
id_added=`python scripts/update-${{ steps.label.outputs.table }}.py '${{ steps.issue-parser.outputs.jsonString }}'`
echo "id_added=$id_added" >> $GITHUB_OUTPUT
# - name: Create Pull Request
# uses: peter-evans/create-pull-request@v5
# with:
# title: add ${{ steps.issue-parser.outputs.issueparser_source_id }}
# commit-message: add-${{ steps.issue-parser.outputs.issueparser_source_id }}
# branch: add-${{ steps.issue-parser.outputs.issueparser_source_id }}
# body: |
# Closes #${{ github.event.issue.number }}
# Request to add ${{ steps.issue-parser.outputs.issueparser_source_id }}
# delete-branch: true
2 changes: 1 addition & 1 deletion .github/workflows/add-institution-id.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Process institution id
on:
repository_dispatch:
types: [register-command]
types: [register2-command]
concurrency: 'main'
jobs:
add_institution_id:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/add-source-id.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Process source id
on:
repository_dispatch:
types: [register-command]
types: [register2-command]
concurrency: 'main'
jobs:
add_source_id:
Expand Down
1 change: 1 addition & 0 deletions scripts/cordex_cv/cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ def update_table(entry, filename, table_name, style=None):
pprint.pprint(current)
with open(filename, "w", encoding="utf8") as f:
json.dump(current, f, indent=4)
return new_id
13 changes: 13 additions & 0 deletions scripts/labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
import subprocess

issue = sys.argv[1]
command = ["gh", "api", "--jq", ".labels.[].name", issue]
result = subprocess.run(command, stdout=subprocess.PIPE)
labels = result.stdout.decode("utf-8").splitlines()

for lb in labels:
table = lb.split("register")[1].strip() if "register" in lb else None
if table:
break
print(f"{table}")
6 changes: 3 additions & 3 deletions scripts/update-institution_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def update_institution_id(entry):
update_table(entry, table, table_name, style="flat")
return update_table(entry, table, table_name, style="flat")


def get_entries(content):
Expand All @@ -23,5 +23,5 @@ def get_entries(content):
content = sys.argv[1]
# content = '{"institution_id": "INSTITUTE", "institution": "My institute"}'
entry = get_entries(content)
print(entry)
update_institution_id(entry)
new_id = update_institution_id(entry)
print(new_id)
6 changes: 3 additions & 3 deletions scripts/update-source_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def update_source_id(entry):
update_table(entry, table, table_name)
return update_table(entry, table, table_name)


def get_entries(content):
Expand All @@ -30,5 +30,5 @@ def get_entries(content):
# '"source_id": "SUPER-RCM", "source_type": "ARCM"}'
# )
entry = get_entries(content)
print(entry)
update_source_id(entry)
new_id = update_source_id(entry)
print(new_id)

0 comments on commit c6d064e

Please sign in to comment.