Skip to content

Commit

Permalink
Merge pull request #441 from ncihtan/action-dependencies-table
Browse files Browse the repository at this point in the history
Add action to build dependencies table
  • Loading branch information
aditigopalan authored Sep 10, 2024
2 parents e7582d3 + ec6f560 commit 04559a1
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 10 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build-dependencies-table.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build Dependencies Table

on:
release:
types: [published]

jobs:
update-table:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pandas
- name: Fetch attribute table
run: |
python - <<EOF
import requests
import pandas as pd
url = "https://schematic.api.sagebionetworks.org/v1/ui/" # Endpoint URL
jsonld_url = "https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld"
response = requests.get(jsonld_url)
response.raise_for_status()
model_jsonld = response.json()
response = requests.post(url, json=model_jsonld)
response.raise_for_status()
attribute_table = response.json() # Adjust this line based on the actual response format
df = pd.DataFrame(attribute_table)
df.to_csv('HTAN.dependencies.csv', index=False)
EOF
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add HTAN.dependencies.csv
git commit -m "Update HTAN.dependencies.csv with the latest attribute table"
- name: Create Pull Request
uses: aditigopalan/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update HTAN.dependencies.csv"
branch: update-attribute-table
title: "Update HTAN.dependencies.csv"
body: "This PR updates HTAN.dependencies.csv with the latest attribute table."
83 changes: 73 additions & 10 deletions .github/workflows/ci-lint-validate-convert.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
name: Make JSON-LD
name: Make JSON-LD and Build Dependencies Table

on:
pull_request:
branches: 'main'
paths: 'HTAN.model.csv'
release:
types: [published]
workflow_dispatch:

concurrency:
# cancel the current running workflow from the same branch, PR when a new workflow is triggered
# when the trigger is not a PR but a push, it will use the commit sha to generate the concurrency group
# {{ github.workflow }}: the workflow name is used to generate the concurrency group. This allows you to have more than one workflows
# {{ github.ref_type }}: the type of Git ref object created in the repository. Can be either branch or tag
# {{ github.sha }}: full commit sha
# credit: https://github.com/Sage-Bionetworks-Workflows/sagetasks/blob/main/.github/workflows/ci.yml
group: >-
${{ github.workflow }}-${{ github.ref_type }}-${{ github.sha }}
group: ${{ github.workflow }}-${{ github.ref_type }}-${{ github.sha }}
cancel-in-progress: true

env:
Expand Down Expand Up @@ -87,11 +82,79 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit the changes
run: |
# Specifying the full email allows the avatar to show up: https://github.com/orgs/community/discussions/26560
git add HTAN.model.jsonld
git commit -m "GitHub Action: convert *.model.csv to *.model.jsonld" || echo "No changes to commit"
- name: Push changes back to PR
if: github.event_name == 'pull_request'
uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

build-dependencies:
name: Build Dependencies Table
needs: convert
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Fetch latest changes
run: git pull origin main

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests pandas
- name: Fetch attribute table
run: |
python - <<EOF
import requests
import pandas as pd
url = "https://schematic.api.sagebionetworks.org/v1/ui/" # Endpoint URL
if "${{ github.event_name }}" == "pull_request":
jsonld_url = "https://raw.githubusercontent.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }}/head/HTAN.model.jsonld"
else:
jsonld_url = "https://raw.githubusercontent.com/${{ github.repository }}/main/HTAN.model.jsonld"
response = requests.get(jsonld_url)
response.raise_for_status()
model_jsonld = response.json()
response = requests.post(url, json=model_jsonld)
response.raise_for_status()
attribute_table = response.json() # Adjust this line based on the actual response format
df = pd.DataFrame(attribute_table)
df.to_csv('HTAN.dependencies.csv', index=False)
EOF
- name: Commit changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add HTAN.dependencies.csv
git commit -m "Update HTAN.dependencies.csv with the latest attribute table"
- name: Create Pull Request
if: github.event_name == 'pull_request'
uses: r-lib/actions/pr-push@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Create Pull Request
if: github.event_name != 'pull_request'
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update HTAN.dependencies.csv"
branch: update-attribute-table
title: "Update HTAN.dependencies.csv"
body: "This PR updates HTAN.dependencies.csv with the latest attribute table."

0 comments on commit 04559a1

Please sign in to comment.