“in github actions, what file format is used to define workflows?”
In GitHub Actions, what file format is used to define workflows?
Key Takeaways
- GitHub Actions workflows are defined using the YAML (Yet Another Markup Language) file format.
- Workflow files must use the
.ymlor.yamlextension. - These files are stored in a specific directory:
.github/workflows/in your repository.
The file format used to define GitHub Actions workflows is YAML. This human-readable data serialization language is designed to be easy to write and understand, making it the industry standard for configuration files and CI/CD (Continuous Integration/Continuous Deployment) automation scripts.
Table of Contents
- What is YAML and Why is it Used?
- Workflow File Structure and Location
- Comparison: YAML vs. Other Formats
- Summary Table
- Frequently Asked Questions
What is YAML and Why is it Used?
YAML stands for “YAML Ain’t Markup Language” (a recursive acronym). It is the preferred format for GitHub Actions because it uses indentation to indicate structure, which avoids the clutter of braces or tags found in JSON or XML.
In the context of DevOps and GitHub, YAML allows developers to define complex automation logic—such as when to trigger a build, which operating system to use, and which commands to run—in a clean, declarative style.
Pro Tip: YAML is highly sensitive to indentation. Always use spaces (usually two) rather than tabs to prevent “invalid workflow” errors when pushing your code to GitHub.
Workflow File Structure and Location
For GitHub to recognize your automation scripts, they must be placed in a very specific location within your repository’s root directory:
[Your Repository] / .github / workflows / main.yml
A basic workflow file typically includes these key components:
- name: The label for your workflow.
- on: The specific GitHub event that triggers the workflow (e.g.,
push,pull_request). - jobs: The groups of tasks that the workflow will execute.
- steps: The individual commands or Actions to be run within a job.
Comparison Table: YAML vs. Other Formats
While other formats exist, GitHub chose YAML for its balance of readability and power.
| Feature | YAML (.yml) | JSON (.json) | XML (.xml) |
|---|---|---|---|
| Readability | High (Human-centric) | Moderate (Machine-centric) | Low (Verbose) |
| Structure | Indentation-based | Braces and Brackets | Tag-based |
| Comments | Supported (#) |
Not standard | Supported |
| GitHub Usage | Primary format | API responses | Legacy configurations |
Summary Table
| Key Point | Details |
|---|---|
| Primary Format | YAML |
| Extensions | .yml or .yaml |
| Directory Path | .github/workflows/ |
| Syntax Focus | Indentation and Key-Value pairs |
Frequently Asked Questions
1. Can I use JSON instead of YAML for GitHub Actions?
No. While GitHub’s internal APIs often use JSON, the Actions runner specifically looks for .yml or .yaml files in the .github/workflows/ directory.
2. What happens if I misspell the “.github/workflows” folder?
If the folder name is incorrect (e.g., workflow instead of workflows), GitHub will ignore the files, and your automation will never trigger.
3. Is “YAML” case-sensitive?
Yes, YAML keys (like on:, jobs:, runs-on:) are case-sensitive and must follow the specific schema defined by GitHub Actions.
Next Steps
Would you like me to provide a basic template of a YAML workflow file to show you how the indentation works?