Posts
GitHub Actions YAML Made Easier with VS Code Snippets
Use my VS Code snippets to build GitHub Actions workflows and custom actions from reusable YAML templates with editable placeholders.
In this article
Writing GitHub Actions workflows involves a lot of repeated YAML. Triggers, jobs, runners, steps, inputs, outputs… the names change, but you keep typing the same structure.
I created GitHub Actions VS Code Snippets to make that work simpler. Type a prefix, insert a template, and tab through the values you need to change.
Cookie-cutter is exactly what I want for this part of development. I can spend my time deciding what the workflow should do instead of remembering where permissions belongs.
Add the Snippets to Your Project
The project is a collection of VS Code snippet definitions. To use it, copy github-actions.code-snippets into your project’s .vscode directory:
your-project/
.vscode/
github-actions.code-snippets
.github/
workflows/
ci.yml
Then:
- Open the Command Palette and run Developer: Reload Window.
- Open a workflow
.ymlor.yamlfile. - Type
gha-, or pressCtrl+Spaceto see matching completions. - Accept a snippet and use
Tabto move through its placeholders.
The current definitions support the YAML and GitHub Actions workflow language modes. If suggestions do not appear, check the file’s language mode. The README also lists the recommended GitHub Actions and YAML extensions.
Keeping the snippet file in the repository gives contributors the same starting templates when they open the project in VS Code. You can also edit that file to match your team’s conventions.
Start With a Workflow
Create .github/workflows/ci.yml, then insert gha-workflow.
That snippet gives you a workflow name, push and pull-request triggers, a job, a runner choice, a timeout, read-only contents permission, and a command step. Here is an example after filling its placeholders:
name: CI
on:
- push
- pull_request
jobs:
verify:
name: Verify runner
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
steps:
- name: Check Git version
run: git --version
That is deliberately a small starting point. The generic template leaves you to choose the commands your repository needs.
For a Node.js project, gha-workflow-node-ci goes further: checkout, Node setup, npm caching, npm ci, and npm test, along with concurrency controls. It lets you choose the runner, timeout, and Node version. Those commands assume your project has the npm lockfile and test script they need.
Both templates are in the snippet definitions. You can read exactly what will be inserted before using them.
Add the Piece You Need
Most workflow edits involve adding a job or a few steps to an existing file. The collection currently includes 42 snippets, with prefixes that describe the structure they insert.
Here are a few useful ones from the snippet catalog:
| Prefix | Inserts |
|---|---|
gha-workflow-job | A job under an existing jobs map |
gha-workflow-job-step-run | A command step with shell, environment, and working-directory fields |
gha-workflow-job-step-uses | A step that calls an action |
gha-workflow-trigger-dispatch | A manual trigger with a choice input |
gha-workflow-job-matrix-node | A Node.js version and operating-system matrix |
gha-workflow-jobs-output | Producer and consumer jobs connected by an output |
gha-workflow-step-output | A step that writes to $GITHUB_OUTPUT |
gha-workflow-step-summary | A step that appends Markdown to the job summary |
For example, gha-workflow-step-output can produce this step after you fill in the name, ID, output name, and value:
- name: Set package name
id: package-info
run: echo "package_name=web-app" >> "$GITHUB_OUTPUT"
The fragment includes indentation for a workflow job’s steps list. Insert fragments at the location described by the snippet, then check the surrounding YAML. A snippet saves typing; it cannot know which level of your file you intended to edit.
Create Custom Actions Too
The collection also covers action metadata files. You can start a composite, Docker, or JavaScript action, then add inputs, outputs, steps, and branding.
gha-composite-action includes an input, a step that uses it, and an output mapped from that step. Its linked placeholders keep repeated identifiers together: change the input name once and the matching input reference changes with it. The step ID is linked to its output reference as well.
That is a small convenience until you have copied an example, renamed half of it, and spent twenty minutes finding the reference you missed. Then it feels fairly substantial.
There are also separate snippets for reusable workflows and their callers. The README’s catalog groups these by purpose so you can find the right starting point.
Make the Repetition Consistent
The templates include defaults such as job timeouts, explicit permissions, and action references pinned to full commit SHAs with release-version comments. You still need to choose permissions, runner versions, paths, and commands appropriate to your repository.
The project includes a validator for the snippet definitions:
node .github/scripts/validate-snippets.mjs
It checks JSON structure, required fields, unique prefixes, placeholder numbering, action pinning, branding options, composite output wiring, and README coverage. The validation documentation explains its scope. Your completed workflow still needs its own review and testing.
Once inserted, the YAML is part of your workflow file. Updating the snippet collection will not update workflows you previously created from it. Keep maintaining those files as your dependencies and build requirements change.
Less Typing, Fewer Forgotten Fields
You can find the collection on GitHub, under the Apache 2.0 license. Copy the snippet file into a project and try gha-workflow or one of the step templates the next time you edit a workflow.
If you repeatedly write a useful pattern that is missing, open an issue or contribute a snippet with a clear description and placeholders.
I want the repeated YAML to take less effort. Insert the structure, fill in the details, and get back to the work the pipeline is supposed to automate.
-Rob