-
Notifications
You must be signed in to change notification settings - Fork 7
165 lines (146 loc) · 5.48 KB
/
ci-lint-validate-convert.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Make JSON-LD and Build Dependencies Table
on:
pull_request:
branches: 'main'
paths: 'HTAN.model.csv'
release:
types: [published]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_type }}-${{ github.sha }}
cancel-in-progress: true
env:
SCHEMATIC_VERSION: '24.2.1'
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
jobs:
lint:
name: Lint CSV
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: csvlinter
uses: kcheriyath/[email protected]
with:
find_pattern: "*.csv"
validate:
name: Validate CSV
if: always()
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install IPython
run: |
pip install ipython==8.18.1
- name: Install Schematic
run: |
pip install schematicpy==$SCHEMATIC_VERSION
- name: Convert CSV schema
run: |
schematic schema convert .github/CSV.model.csv
- name: Validate data model CSV
run: |
schematic model -c .github/CSV_schematic_config.yml validate -mp HTAN.model.csv -dt "DataModel" |
grep "Your manifest has been validated successfully. There are no errors in your manifest, and it can be submitted without any modifications."
convert:
name: Convert CSV to JSON-LD
needs:
- lint
- validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install IPython
run: |
pip install ipython==8.18.1
- name: Install Schematic
run: |
pip install schematicpy==$SCHEMATIC_VERSION
- name: Convert .csv to .jsonld
run: |
schematic schema convert HTAN.model.csv
- name: Set up Git user
run: |
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Fetch PR details
if: github.event_name == 'pull_request'
uses: r-lib/actions/pr-fetch@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Commit the changes
run: |
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
from io import StringIO
def fetch_and_save_attribute_table():
url = "https://schematic.api.sagebionetworks.org/v1/visualize/attributes"
jsonld_url = "https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld"
params = {'schema_url': jsonld_url}
print("Fetching attribute table...")
response = requests.get(url, params=params)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
content_type = response.headers.get('Content-Type', '')
if 'text/html' in content_type:
print("Response in text/html format, converting to CSV...")
try:
df = pd.read_csv(StringIO(response.text))
print("Fetched attribute table.")
df.to_csv('HTAN.dependencies.csv', index=False)
print("Saved to HTAN.dependencies.csv.")
except Exception as e:
print(f"Error processing CSV: {e}")
else:
print("Unexpected content type. Expected text/html but got:", content_type)
else:
print(f"Failed to fetch data. Status Code: {response.status_code}")
fetch_and_save_attribute_table()
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" || echo "No changes to commit"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
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."