generate_templates #48
Workflow file for this run
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
# ------------------------------------------------------------------------------ | |
# 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 | |