Skip to content

Export and Publish Taxonomy #4510

Export and Publish Taxonomy

Export and Publish Taxonomy #4510

name: Export and Publish Taxonomy
permissions: write-all
on:
schedule:
- cron: '0 * * * *'
workflow_dispatch:
jobs:
export_publish:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10' ]
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository.
- name: Set up Python environment
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tdta cas-tools requests
- name: Google sheets to tsv
run: python src/google_sheets_to_tsv.py
- name: Identify JSON file and Taxonomy ID
id: set_vars
run: |
set -e
# Locate the first JSON file found in the root directory
cas_json_file=$(ls *.json 2>/dev/null | head -n 1)
if [ -z "$cas_json_file" ]; then
echo "No JSON file found in the repository root." >&2
exit 1
fi
taxonomy_id=$(basename "$cas_json_file" .json)
echo "cas_json_file=$cas_json_file" >> $GITHUB_OUTPUT
echo "taxonomy_id=$taxonomy_id" >> $GITHUB_OUTPUT
echo "Found JSON file: $cas_json_file with taxonomy_id: $taxonomy_id"
- name: Run tdta export
run: |
tdta export -f ./curation_tables -o "${{ steps.set_vars.outputs.cas_json_file }}" -c ./
- name: Run cas2rdf conversion
run: |
cas cas2rdf --schema bican \
--data "${{ steps.set_vars.outputs.cas_json_file }}" \
--ontology_ns "${{ steps.set_vars.outputs.taxonomy_id }}" \
--ontology_iri "https://purl.brain-bican.org/ontology/${{ steps.set_vars.outputs.taxonomy_id }}/" \
--out "${{ steps.set_vars.outputs.taxonomy_id }}.rdf" \
--exclude_cells
- name: Commit and push changes
run: |
set -e
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Normalize TSVs to LF (safe on Linux runner)
if compgen -G "curation_tables/*.tsv" > /dev/null; then
sed -i 's/\r$//' curation_tables/*.tsv || true
git add curation_tables/*.tsv
fi
# Add generated CAS JSON and RDF (if present)
git add "${{ steps.set_vars.outputs.cas_json_file }}" "${{ steps.set_vars.outputs.taxonomy_id }}.rdf" || true
# Commit only if there are staged changes
if git diff --staged --quiet; then
echo "No changes to commit."
exit 0
fi
git commit -m "chore: update TSVs, CAS JSON, and RDF artifacts"
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{secrets.TDT_TOKEN}}
branch: ${{ github.head_ref }}