Skip to content

Commit 6740209

Browse files
committed
feat: flush out common github action code snippets
1 parent e210eaa commit 6740209

File tree

3 files changed

+313
-3
lines changed

3 files changed

+313
-3
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
*
3+
* Copyright 2025 Robert Lindley
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
{
19+
"GitHub Actions - Action - Branding": {
20+
"prefix": "gha-action-branding",
21+
"body": [
22+
"branding:",
23+
" color: ${1|blue,green,orange,purple,red,yellow,gray-dark|}",
24+
" icon: ${2|alert,arrow-down-circle,arrow-right-circle,arrow-up-circle,bar-chart,bell,book,bookmark,briefcase,calendar,check-circle,check-square,chevron-down,chevron-left,chevron-right,chevron-up,clock,cloud,code,codesandbox,coffee,columns,command,cpu,credit-card,crosshair,disc,dollar-sign,download,edit,file,file-text,flag,folder,git-branch,git-commit,git-merge,git-pull-request,globe,grid,heart,help-circle,home,image,inbox,info,layout,life-buoy,link,list,lock,mail,map,menu,message-circle,message-square,minus-circle,minus-square,monitor,music,package,paperclip,pen-tool,percent,phone,pie-chart,play,plus-circle,plus-square,pocket,printer,radio,refresh-cloud,repeat,save,search,send,server,settings,shield,shopping-cart,shuffle,sidebar,sliders,smartphone,speaker,star,stop-circle,sun,tag,target,terminal,thumbs-down,thumbs-up,trash,triangle,truck,tv,umbrella,upload,user,users,video,watch,wifi,x-circle,x-square,zoom-in,zoom-out|}"
25+
],
26+
"description": "Insert GitHub Action branding with predefined color and icon options."
27+
},
28+
"GitHub Actions - Action - Step Env": {
29+
"prefix": "gha-action-step-env",
30+
"body": [
31+
"env:",
32+
" GITHUB_ACTOR: ${{ github.actor }}",
33+
" GITHUB_REF: ${{ github.ref }}",
34+
" GITHUB_REPOSITORY: ${{ github.repository }}",
35+
" GITHUB_SHA: ${{ github.sha }}",
36+
" GITHUB_WORKSPACE: ${{ github.workspace }}",
37+
" RUNNER_ARCH: ${{ runner.arch }}",
38+
" RUNNER_OS: ${{ runner.os }}",
39+
],
40+
"description": "Insert commonly used GitHub Actions step environment variables."
41+
},
42+
"GitHub Actions - Composite Action": {
43+
"prefix": "gha-composite-action",
44+
"body": [
45+
"name: ${1:GitHub Composite Action}",
46+
"author: ${2:Your Name}",
47+
"description: ${3:Describe the composite action}",
48+
"",
49+
"inputs:",
50+
" ${4:input_name}:",
51+
" description: ${5:Input description}",
52+
" required: ${6|true,false|}",
53+
" default: ${7:default_value}",
54+
"",
55+
"outputs:",
56+
" ${8:output_name}:",
57+
" description: ${9:Output description}",
58+
" value: ${{ steps.${10:step_id}.outputs.result }}",
59+
"",
60+
"runs:",
61+
" using: composite",
62+
" steps:",
63+
" - name: Checkout Repository",
64+
" id: checkout-repository",
65+
" uses: actions/checkout@v4",
66+
"",
67+
" - name: ${11:Your Step Name}",
68+
" id: ${12:your-step-id}",
69+
" run: ${13:echo 'Hello World'}",
70+
" shell: ${14|bash,pwsh,sh|}",
71+
""
72+
],
73+
"description": "Boilerplate template for a GitHub Composite Action."
74+
},
75+
"GitHub Actions - Composite Action 'run' Step": {
76+
"prefix": "gha-composite-action-run-step",
77+
"body": [
78+
"- name: ${1:Run Command}",
79+
" id: ${2:step_id}",
80+
" if: ${{ ${3:true} }}",
81+
" shell: ${4|bash,pwsh,sh|}",
82+
" run: |",
83+
" ${5:echo 'Hello World'}"
84+
],
85+
"description": "Insert a 'run' step for a GitHub Composite Action."
86+
},
87+
"GitHub Actions - Composite Action 'uses' Step": {
88+
"prefix": "gha-composite-action-uses-step",
89+
"body": [
90+
"- name: ${1:Use Existing Action}",
91+
" id: ${2:step_id}",
92+
" uses: ${3:actions/checkout@v4}",
93+
" with:",
94+
" ${4:input_name}: ${5:input_value}"
95+
],
96+
"description": "Insert a 'uses' step for a GitHub Composite Action."
97+
},
98+
"GitHub Actions - Docker Action": {
99+
"prefix": "gha-docker-action",
100+
"body": [
101+
"name: ${1:Docker GitHub Action}",
102+
"author: ${2:Your Name}",
103+
"description: ${3:Describe the Docker-based action}",
104+
"",
105+
"inputs:",
106+
" ${4:input_name}:",
107+
" description: ${5:Input description}",
108+
" required: ${6|true,false|}",
109+
" default: ${7:default_value}",
110+
"",
111+
"outputs:",
112+
" ${8:output_name}:",
113+
" description: ${9:Output description}",
114+
"",
115+
"runs:",
116+
" using: docker",
117+
" image: ${10:Dockerfile}",
118+
" args:",
119+
" - ${11:--arg value}"
120+
],
121+
"description": "Insert a template for a Docker-based GitHub Action."
122+
},
123+
"GitHub Actions - Node Action": {
124+
"prefix": "gha-node20-action",
125+
"body": [
126+
"name: ${1:Node.js GitHub Action}",
127+
"author: ${2:Your Name}",
128+
"description: ${3:Describe the Node.js action}",
129+
"",
130+
"inputs:",
131+
" ${4:input_name}:",
132+
" description: ${5:Input description}",
133+
" required: ${6|true,false|}",
134+
" default: ${7:default_value}",
135+
"",
136+
"outputs:",
137+
" ${8:output_name}:",
138+
" description: ${9:Output description}",
139+
"",
140+
"runs:",
141+
" using: node20",
142+
" main: ${10:./dist/index.js}"
143+
],
144+
"description": "Insert a template for a Node.js 20.x GitHub Action."
145+
},
146+
"GitHub Actions - Workflow": {
147+
"prefix": "gha-workflow",
148+
"body": [
149+
"name: ${1:GitHub Workflow}",
150+
"",
151+
"on:",
152+
" - push",
153+
" - pull_request",
154+
"",
155+
"jobs:",
156+
" ${2:build}:",
157+
" runs-on: ${3|ubuntu-latest,windows-latest,macos-latest|}",
158+
" steps:",
159+
" - name: Checkout Repository",
160+
" id: checkout-repository",
161+
" uses: actions/checkout@v4",
162+
"",
163+
" - name: Setup Node.js",
164+
" id: setup-node",
165+
" uses: actions/setup-node@v4",
166+
" with:",
167+
" node-version: '${4|16,18,20|}'",
168+
"",
169+
" - name: Install Dependencies",
170+
" id: install-dependencies",
171+
" run: npm install",
172+
"",
173+
" - name: Run Tests",
174+
" id: run-tests",
175+
" run: npm test",
176+
"",
177+
],
178+
"description": "Boilerplate for a GitHub Actions workflow."
179+
},
180+
"GitHub Actions - Workflow Job": {
181+
"prefix": "gha-workflow-job",
182+
"body": [
183+
"jobs:",
184+
" ${1:job_name}:",
185+
" runs-on: ${2|ubuntu-latest,windows-latest,macos-latest|}",
186+
" steps:",
187+
" - name: Print Job Status",
188+
" run: echo \"Job Status: ${{ job.status }}\""
189+
],
190+
"description": "Insert a GitHub Actions job with status reference."
191+
}
192+
}

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2025 Robert Lindley
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,120 @@
1-
# github-action-snippets
2-
GitHub Action Visual Studio Code Snippets
1+
# GitHub Actions VS Code Snippets
2+
3+
This repository provides a collection of **Visual Studio Code snippets** for **GitHub Actions** and **GitHub Actions Workflows**. These snippets simplify the process of writing, editing, and managing **GitHub Actions YAML files**, ensuring correctness and completeness with predefined property selections.
4+
5+
## 🚀 Features
6+
7+
- **Predefined GitHub Action Templates** for Composite, Docker, and Node.js Actions.
8+
- **Workflow Boilerplate** to quickly set up CI/CD pipelines.
9+
- **Environment Variables** to insert commonly used GitHub Actions context values.
10+
- **Comprehensive Properties** for branding, inputs, outputs, and steps.
11+
- **Auto-completion and Selection Options** for colors, icons, and OS environments.
12+
- **Error-Free YAML Formatting** for valid and structured configurations.
13+
14+
## 📌 Installation
15+
16+
1. Open **Visual Studio Code**.
17+
2. Go to **User Snippets**:
18+
- Press `Ctrl + Shift + P` (Windows/Linux) or `Cmd + Shift + P` (Mac) and search for **"Configure User Snippets"**.
19+
3. Select **YAML (`.yaml`)** or **GitHub Actions (`.github/workflows/*.yml`)**.
20+
4. Copy and paste the snippets into the selected file.
21+
5. Save and start using the snippets in your GitHub Actions workflows!
22+
23+
## 🔥 Available Snippets
24+
25+
### 1️⃣ GitHub Actions - Branding
26+
27+
- **Prefix:** `gha-action-branding`
28+
- **Description:** Inserts branding details for a custom GitHub Action.
29+
- **Properties:** `color`, `icon` (predefined values for easy selection).
30+
31+
### 2️⃣ GitHub Actions - Common Environment Variables
32+
33+
- **Prefix:** `gha-action-step-env`
34+
- **Description:** Inserts commonly used GitHub Actions step environment variables.
35+
- **Includes:** `GITHUB_ACTOR`, `GITHUB_REPOSITORY`, `GITHUB_REF`, `GITHUB_SHA`, `GITHUB_WORKSPACE`, `RUNNER_OS`, `RUNNER_ARCH`.
36+
37+
### 3️⃣ GitHub Actions - Composite Action
38+
39+
- **Prefix:** `gha-composite-action`
40+
- **Description:** Creates a Composite GitHub Action with configurable inputs, outputs, and steps.
41+
42+
### 4️⃣ GitHub Actions - Composite Action 'run' Step
43+
44+
- **Prefix:** `gha-composite-action-run-step`
45+
- **Description:** Inserts a 'run' step for Composite Actions with optional **`if`, `env`, `shell`, and `working-directory`** properties.
46+
47+
### 5️⃣ GitHub Actions - Composite Action 'uses' Step
48+
49+
- **Prefix:** `gha-composite-action-uses-step`
50+
- **Description:** Inserts a 'uses' step for referencing other actions.
51+
52+
### 6️⃣ GitHub Actions - Docker Action
53+
54+
- **Prefix:** `gha-docker-action`
55+
- **Description:** Provides a template for creating a **Docker-based GitHub Action**.
56+
57+
### 7️⃣ GitHub Actions - Node.js Action
58+
59+
- **Prefix:** `gha-node20-action`
60+
- **Description:** Provides a template for creating a **Node.js 20.x GitHub Action**.
61+
62+
### 8️⃣ GitHub Actions - Workflow Boilerplate
63+
64+
- **Prefix:** `gha-workflow`
65+
- **Description:** Inserts a **GitHub Actions Workflow** template with `push` and `pull_request` triggers.
66+
- **Includes:** `checkout`, `setup-node`, `install dependencies`, and `run tests` steps.
67+
68+
### 9️⃣ GitHub Actions - Workflow Job
69+
70+
- **Prefix:** `gha-job`
71+
- **Description:** Inserts a job structure with `runs-on` options and a **job status reference**.
72+
73+
## 🛠 How to Use
74+
75+
1. Open a `.yml` file inside the `.github/workflows/` directory.
76+
2. Type the **prefix** (e.g., `gha-workflow`) and select the snippet from the suggestions.
77+
3. Use the placeholders and tab through the fields to customize.
78+
4. Save the file and push it to GitHub to trigger the workflow.
79+
80+
## 📖 Example Usage
81+
82+
**Using the `gha-workflow` snippet:**
83+
84+
```yaml
85+
name: Example Workflow
86+
87+
on:
88+
- push
89+
- pull_request
90+
91+
jobs:
92+
build:
93+
runs-on: ubuntu-latest
94+
steps:
95+
- name: Checkout Repository
96+
uses: actions/checkout@v4
97+
98+
- name: Setup Node.js
99+
uses: actions/setup-node@v4
100+
with:
101+
node-version: "20"
102+
103+
- name: Install Dependencies
104+
run: npm install
105+
106+
- name: Run Tests
107+
run: npm test
108+
```
109+
110+
## 🔍 Contributing
111+
112+
Feel free to contribute by submitting a **Pull Request (PR)** or opening an **Issue** to suggest improvements or report any bugs.
113+
114+
## 🎯 License
115+
116+
This project is licensed under the **Apache License V2.0 License**.
117+
118+
---
119+
120+
📢 **Follow GitHub Actions best practices to ensure optimal CI/CD performance!** 🚀

0 commit comments

Comments
 (0)