1- # Basic ODK workflow
1+ # ==============================================================================
2+ # WORKFLOW: Build Ontology (Quality Control)
3+ # ==============================================================================
4+ # Purpose: Builds ontology release assets and performs quality control checks
5+ #
6+ # This workflow:
7+ # 1. Refreshes imports to ensure consistency with upstream ontologies
8+ # 2. Generates release artifacts (OWL, JSON-LD, Turtle, etc.)
9+ # 3. Runs quality control checks (syntax, consistency, reasoning)
10+ # 4. Commits generated assets back to the repository
11+ # 5. Triggers the documentation workflow to continue the chain
12+ #
13+ # This is the core build workflow that transforms the edit file
14+ # (*-edit.owl) into production-ready ontology releases in multiple formats.
15+ #
16+ # Execution Chain Position:
17+ # setup-repo → [BUILD/QC] → docs
18+ # update-repo → [BUILD/QC] → docs
19+ # [BUILD/QC] → docs (on direct push to main)
20+ #
21+ # Read more about ODK builds:
22+ # https://github.com/INCATools/ontology-development-kit#building-the-ontology
23+ # ==============================================================================
224
3- name : build
25+ name : Build Ontology
426
5- # Controls when the action will run.
27+ # ==============================================================================
28+ # WORKFLOW TRIGGERS
29+ # ==============================================================================
30+ # This workflow can be triggered in four ways:
31+ # 1. Via repository_dispatch from setup-repo or update-repo workflow
32+ # 2. Automatically on pushes to main that modify ontology source files
33+ # 3. Automatically on pull requests that modify ontology source files
34+ # 4. Manually via workflow_dispatch for forced builds
35+ #
36+ # Path filters ensure the workflow only runs when ontology files change,
37+ # preventing unnecessary builds on unrelated commits (README, docs, etc.).
38+ #
39+ # IMPORTANT: The push trigger here only monitors ontology source/edit files.
40+ # The refresh-imports workflow independently monitors import-related files
41+ # and is used only for standalone import refreshes (workflow_dispatch /
42+ # repository_dispatch). This prevents double-triggering on import changes.
43+ #
44+ # IMPORTANT: Push triggers skip commits made by github-actions[bot] to prevent
45+ # duplicate runs when the workflow chain is triggered via repository_dispatch.
46+ # ==============================================================================
647on :
748 # ============================================================================
849 # TRIGGER 1: Repository Dispatch (from setup-repo or update-repo workflow)
@@ -62,34 +103,200 @@ on:
62103 - ' src/ontology/Makefile'
63104 - ' src/ontology/*-Makefile'
64105
65- # Allows you to run this workflow manually from the Actions tab
106+ # ============================================================================
107+ # TRIGGER 4: Manual Trigger (for forced builds or debugging)
108+ # ============================================================================
109+ # Allows manual execution via GitHub UI or API.
110+ # Useful for:
111+ # - Forcing rebuild after external changes (e.g. upstream ontology update)
112+ # - Troubleshooting build issues without touching source files
113+ # - Testing the complete pipeline end-to-end
114+ # ============================================================================
66115 workflow_dispatch :
67116
68- # A workflow run is made up of one or more jobs that can run sequentially or in parallel
117+ # ==============================================================================
118+ # ENVIRONMENT VARIABLES
119+ # ==============================================================================
120+ # Global variables available to all jobs in this workflow
121+ # ==============================================================================
122+ env :
123+ # Default branch for git operations (used in some ODK make targets)
124+ DEFAULT_BRANCH : main
125+
126+ # ==============================================================================
127+ # JOBS
128+ # ==============================================================================
69129jobs :
70- # This workflow contains a single job called "ontology_qc"
130+ # ============================================================================
131+ # JOB: ontology_qc
132+ # ============================================================================
133+ # Main job that performs the complete build and QC process.
134+ #
135+ # Process Flow:
136+ # 1. Checkout repository with full history
137+ # 2. Build ontology (runs make refresh-imports + all_assets inside ODK container)
138+ # 3. Commit generated release files back to the repository
139+ # 4. Trigger documentation generation workflow (docs.yml)
140+ #
141+ # Container: obolibrary/odkfull:v1.6
142+ # - Includes ROBOT, OWLTools, make, Java, Python, reasoning tools
143+ # - Version pinned for reproducibility
144+ #
145+ # Permissions: contents: write (required for committing release artifacts)
146+ # ============================================================================
71147 ontology_qc :
72- # The type of runner that the job will run on
73148 runs-on : ubuntu-latest
149+
150+ # Grant write permissions for committing generated release assets back to repo
151+ permissions :
152+ contents : write
153+
154+ # Use ODK container for a consistent, reproducible build environment.
155+ # odkfull includes: ROBOT (OWL reasoner + transformer), make, Java, Python,
156+ # yq (YAML processor), and all ODK tooling required for ontology builds.
74157 container : obolibrary/odkfull:v1.6
75158
76- # Steps represent a sequence of tasks that will be executed as part of the job
77159 steps :
78- # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
79- - uses : actions/checkout@v4
80-
81- - name : ODK update
82- run : cd src/ontology && odk.py update
160+ # ========================================================================
161+ # STEP 1: Checkout Repository
162+ # ========================================================================
163+ # Fetch complete repository with full git history.
164+ #
165+ # Why fetch-depth: 0 (full history)?
166+ # - ODK make targets may inspect git history for versioning
167+ # - Ensures accurate version numbers in release artifacts
168+ # - Allows git operations (log, describe) within build scripts
169+ # ========================================================================
170+ - name : Checkout repository
171+ uses : actions/checkout@v4
172+ with :
173+ fetch-depth : 0 # Full git history required for ODK builds
83174
84- - name : Build ontology
175+ # ========================================================================
176+ # STEP 2: Build Ontology (Refresh Imports + Generate All Artifacts)
177+ # ========================================================================
178+ # Runs two ODK make targets inside the odkfull container:
179+ #
180+ # Target 1: refresh-imports
181+ # - Downloads and extracts terms from upstream ontologies
182+ # - Updates all import module OWL files (imports/*_import.owl)
183+ # - Uses SLME (Syntactic Locality Module Extraction) for minimal imports
184+ # - Reads term lists from imports/*_terms.txt
185+ #
186+ # Target 2: all_assets
187+ # Generates all release artifacts:
188+ # - {id}-full.owl : Complete ontology (all imports merged)
189+ # - {id}-base.owl : Core ontology without transitive imports
190+ # - {id}.owl : Main release file
191+ # - {id}.json : JSON-LD serialization
192+ # - {id}.ttl : Turtle serialization
193+ # - {id}-simple.owl : Simplified version (if configured)
194+ # - {id}-non-classified.owl : Pre-reasoning version (if configured)
195+ # - Component OWL files, QC reports, statistics
196+ #
197+ # Memory configuration (ROBOT_ENV):
198+ # ROBOT_ENV is consumed by the ODK Makefile as a prefix to the ROBOT
199+ # command: `$(ROBOT_ENV) robot ...`. Setting ROBOT_JAVA_ARGS=-Xmx6G
200+ # allocates 6GB Java heap to ROBOT, which is required for reasoning
201+ # over large ontologies. Increase to -Xmx8G if you see OutOfMemory errors.
202+ # ========================================================================
203+ - name : Build ontology (refresh imports + generate all release assets)
85204 env :
86- CRYO_TOKEN : ${{ secrets.CRYO_TOKEN }}
87- DEFAULT_BRANCH : main
88- run : cd src/ontology && make refresh-imports all_assets ROBOT_ENV='ROBOT_JAVA_ARGS=-Xmx6G' -vvv
89- - name : Commit files # commit the src folder
205+ # Configure ROBOT Java heap: 6GB is sufficient for most ontologies.
206+ # Increase to -Xmx8G or -Xmx12G if OOM errors occur during reasoning.
207+ ROBOT_ENV : ' ROBOT_JAVA_ARGS=-Xmx6G'
208+ run : |
209+ # Navigate to the ODK ontology source directory
210+ cd src/ontology
211+
212+ echo "=== Starting ODK build ==="
213+ echo "Step 2a: Refreshing ontology imports..."
214+ echo "Step 2b: Generating all release assets..."
215+
216+ # Run both ODK targets:
217+ # - refresh-imports : Mirrors external ontologies and extracts SLME modules
218+ # - all_assets : Generates all release serializations and runs QC
219+ make refresh-imports all_assets
220+
221+ echo "=== Build complete ==="
222+
223+ # ========================================================================
224+ # STEP 3: Commit Ontology Release Assets
225+ # ========================================================================
226+ # Commits the generated release files back to the repository so they are
227+ # versioned alongside the source and available for the docs workflow.
228+ #
229+ # Conditions:
230+ # - SKIPPED for pull requests: PR contributors should review changes manually
231+ # before merge; artifacts are not committed on PR runs.
232+ # - Only commits if there are actual changes (EndBug/add-and-commit@v9
233+ # automatically skips empty commits).
234+ #
235+ # Files committed:
236+ # - src/ontology/*.owl : All OWL serializations (full, base, simple, etc.)
237+ # - src/ontology/*.json : JSON-LD serializations
238+ # - src/ontology/*.ttl : Turtle serializations
239+ # - src/ontology/imports/*.owl : Updated import modules
240+ #
241+ # Why --force?
242+ # - ODK generates these files but they may be listed in .gitignore
243+ # - --force overrides .gitignore so release artifacts are versioned
244+ # - This is intentional: release assets should be tracked for distribution
245+ #
246+ # Commit identity:
247+ # - Author set to github-actions[bot] to distinguish automated commits
248+ # from human developer commits in git log
249+ # ========================================================================
250+ - name : Commit ontology release assets
251+ # Only commit for push and dispatch events — skip for pull requests
252+ if : github.event_name != 'pull_request'
90253 uses : EndBug/add-and-commit@v9
91254 with :
92- message : " updated ontology"
93- cwd : " ." # Crucial: Look at the whole repo
94- add : " *.owl src/**/* --force" # Capture root owls and src folder
255+ # Descriptive message — visible in git log, easy to filter
256+ message : " Building the ontology from the edits"
257+
258+ # Repository root as working directory
259+ cwd : " ."
260+
261+ # Add all generated files; --force bypasses .gitignore for artifacts
262+ add : " src/ontology/*.owl src/ontology/*.json src/ontology/*.ttl src/ontology/imports/*.owl --force"
263+
264+ # Commit as the GitHub Actions bot (standard identity for CI commits)
95265 default_author : github_actions
266+
267+ # Push directly to the current branch
268+ push : true
269+
270+ # ========================================================================
271+ # STEP 4: Trigger Documentation Workflow
272+ # ========================================================================
273+ # After the ontology is successfully built and committed, dispatch a
274+ # repository event to start the Widoco documentation generation workflow.
275+ #
276+ # Workflow chain:
277+ # setup-repo ─→ [this: BUILD/QC] ─→ docs
278+ # update-repo ─→ [this: BUILD/QC] ─→ docs
279+ # push to main ─→ [this: BUILD/QC] ─→ docs
280+ #
281+ # Why repository_dispatch and not a direct workflow call?
282+ # - Maintains clean separation between workflow stages
283+ # - Avoids nested workflow complexity (GitHub has limits on chained calls)
284+ # - Ensures docs always build from the committed artifact, not mid-run state
285+ # - Prevents race conditions between build commit and docs generation
286+ #
287+ # The 'trigger-docs' event is listened for by docs.yml.
288+ #
289+ # Condition: Only dispatch for non-PR events.
290+ # - PRs do not deploy to Pages; docs are rebuilt after PR merge to main.
291+ # ========================================================================
292+ - name : Trigger Documentation Workflow
293+ # Skip for pull requests — docs will be regenerated after PR merge
294+ if : github.event_name != 'pull_request'
295+ uses : peter-evans/repository-dispatch@v3
296+ with :
297+ # GITHUB_TOKEN is automatically available with the 'contents: write'
298+ # permission set on this job. No PAT required.
299+ token : ${{ secrets.GITHUB_TOKEN }}
300+
301+ # Event type that docs.yml listens for via repository_dispatch trigger
302+ event-type : trigger-docs
0 commit comments