-
Notifications
You must be signed in to change notification settings - Fork 21
133 lines (116 loc) · 4.52 KB
/
generate_templates.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
# ------------------------------------------------------------------------------
# Generate template excel sheets from a data model using schematic
# Then open a PR to incorporate them into the repo
# ------------------------------------------------------------------------------
name: generate-templates
on:
repository_dispatch:
types: generate_templates
workflow_dispatch:
inputs:
data_model:
description: URL to a jsonld data model file
required: true
data_types:
description: One or more data types to create a template separated by a space
required: false
community_dir:
description: Directory to save the template files
required: true
jobs:
generate-template-and-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v3
- name: Checkout schematic
uses: actions/checkout@v3
with:
repository: 'Sage-Bionetworks/schematic'
ref: '37d23342f15f3b8c3f3932da173ee5b8e34408fc'
path: './schematic'
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y pip
- name: Install python dependencies
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.10'
cache: 'poetry'
- run: |
cd schematic
poetry install
- name: Set Configurations for Schematic
shell: bash
run: |
echo "${{ secrets.SCHEMATIC_SYNAPSE_CONFIG }}" > schematic/.synapseConfig
- name: Save service account credentials for Schematic
id: create-json
uses: jsdaniell/[email protected]
with:
name: 'schematic/schematic_service_account_creds.json'
json: ${{ secrets.SCHEMATIC_SERVICE_ACCT_CREDS }}
- name: Set variables for schematic
shell: bash
run: |
echo ${{ github.event_name }}
if ${{ github.event_name == 'repository_dispatch' }}
then
echo Using variables from repository_dispatch
echo 'data_model=${{ github.event.client_payload.data_model }}' >> $GITHUB_ENV
echo 'data_types=${{ github.event.client_payload.data_types }}' >> $GITHUB_ENV
echo 'community_dir=${{ github.event.client_payload.community_dir }}' >> $GITHUB_ENV
else
echo Using variables from manual input
echo 'data_model=${{ inputs.data_model }}' >> $GITHUB_ENV
echo 'data_types=${{ inputs.data_types }}' >> $GITHUB_ENV
echo 'community_dir=${{ inputs.community_dir }}' >> $GITHUB_ENV
fi
- name: Download data model
run: |
curl ${{ env.data_model }} > schematic/data-model.jsonld
- uses: fjogeleit/yaml-update-action@main
with:
commitChange: false
valueFile: schematic/config.yml
changes: |
{
"model.input.download_url": "${{ env.data_model }}",
"model.input.location": "./data-model.jsonld"
}
- name: Make template directory
run: |
mkdir -p ${{ env.community_dir }}/templates
- name: Set Configurations for Data Model
run: |
cd schematic
poetry run python3 ../.github/config_schema.py \
-c config.yml \
--service_repo 'Sage-Bionetworks/schematic' \
-o ../ \
--overwrite
cp ../config.json "../${{ env.community_dir }}/dca-template-config.json"
- name: Get template types to generate
if: "${{ env.data_types == '' }}"
id: data_types
run: |
echo "data_types=$(jq -r '[.manifest_schemas[].schema_name] | join(" ")' config.json)" >> $GITHUB_ENV
- name: Generate templates
run: |
cd schematic
for i in ${{ env.data_types }};
do
poetry run schematic manifest -c config.yml get -dt "$i" -oxlsx "../${{ env.community_dir }}/templates/$i.xlsx" || continue
done
- name: Open PR
uses: peter-evans/create-pull-request@v5
with:
title: Automatic Template Updates
body: Template updates triggered by repository dispatch from a data model repository.
delete-branch: true
branch-suffix: timestamp
add-paths: |
${{ env.community_dir }}/templates/*.xlsx
${{ env.community_dir }}/dca-template-config.json