Skip to content

Commit e255333

Browse files
salmanmkcjc-clark
andauthored
Add examples and metadata guidance to "Creating workflow templates" doc (#58161)
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
1 parent ca6a460 commit e255333

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed

content/actions/how-tos/reuse-automations/create-workflow-templates.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,47 @@ This procedure demonstrates how to create a workflow template and metadata file.
2828
1. If it doesn't already exist, create a new repository named `.github` in your organization.
2929
1. Create a directory named `workflow-templates`.
3030
1. Create your new workflow file inside the `workflow-templates` directory.
31-
1. Create a metadata file inside the `workflow-templates` directory.
31+
32+
If you need to refer to a repository's default branch, you can use the `$default-branch` placeholder. When a workflow is created the placeholder will be automatically replaced with the name of the repository's default branch.
33+
34+
{% ifversion ghes %}
35+
36+
> [!NOTE]
37+
> The following values in the `runs-on` key are also treated as placeholders:
38+
>
39+
> * `ubuntu-latest` is replaced with `[ self-hosted ]`
40+
> * `windows-latest` is replaced with `[ self-hosted, windows ]`
41+
> * `macos-latest` is replaced with `[ self-hosted, macOS ]`
42+
{% endif %}
43+
44+
For example, this file named `octo-organization-ci.yml` demonstrates a basic workflow.
45+
46+
```yaml copy
47+
name: Octo Organization CI
48+
49+
on:
50+
push:
51+
branches: [ $default-branch ]
52+
pull_request:
53+
branches: [ $default-branch ]
54+
55+
jobs:
56+
build:
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- uses: {% data reusables.actions.action-checkout %}
61+
62+
- name: Run a one-line script
63+
run: echo Hello from Octo Organization
64+
```
65+
66+
1. Create a metadata file inside the `workflow-templates` directory. The metadata file must have the same name as the workflow file, but instead of the `.yml` extension, it must be appended with `.properties.json`. For example, this file named `octo-organization-ci.properties.json` contains the metadata for a workflow file named `octo-organization-ci.yml`:
67+
68+
{% data reusables.actions.workflow-templates-metadata-example %}
69+
70+
{% data reusables.actions.workflow-templates-metadata-keys %}
71+
3272
1. To add another workflow template, add your files to the same `workflow-templates` directory.
3373

3474
## Next steps

content/actions/reference/workflows-and-actions/reusing-workflow-configurations.md

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -170,33 +170,9 @@ jobs:
170170
171171
The metadata file must have the same name as the workflow file, but instead of the `.yml` extension, it must be appended with `.properties.json`. For example, this file named `octo-organization-ci.properties.json` contains the metadata for a workflow file named `octo-organization-ci.yml`:
172172

173-
```json copy
174-
{
175-
"name": "Octo Organization Workflow",
176-
"description": "Octo Organization CI workflow template.",
177-
"iconName": "example-icon",
178-
"categories": [
179-
"Go"
180-
],
181-
"filePatterns": [
182-
"package.json$",
183-
"^Dockerfile",
184-
".*\\.md$"
185-
]
186-
}
187-
```
188-
189-
* `name` - **Required.** The name of the workflow. This is displayed in the list of available workflows.
190-
* `description` - **Required.** The description of the workflow. This is displayed in the list of available workflows.
191-
* `iconName` - _Optional._ Specifies an icon for the workflow that is displayed in the list of workflows. `iconName` can one of the following types:
192-
* An SVG file that is stored in the `workflow-templates` directory. To reference a file, the value must be the file name without the file extension. For example, an SVG file named `example-icon.svg` is referenced as `example-icon`.
193-
* An icon from {% data variables.product.prodname_dotcom %}'s set of [Octicons](https://primer.style/octicons/). To reference an octicon, the value must be `octicon <icon name>`. For example, `octicon smiley`.
194-
* `categories` - **Optional.** Defines the categories that the workflow is shown under. You can use category names from the following lists:
195-
* General category names from the [starter-workflows](https://github.com/actions/starter-workflows/blob/main/README.md#categories) repository.
196-
* Linguist languages from the list in the [linguist](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml) repository.
197-
* Supported tech stacks from the list in the [starter-workflows](https://github.com/github-starter-workflows/repo-analysis-partner/blob/main/tech_stacks.yml) repository.
198-
199-
* `filePatterns` - **Optional.** Allows the workflow to be used if the user's repository has a file in its root directory that matches a defined regular expression.
173+
{% data reusables.actions.workflow-templates-metadata-example %}
174+
175+
{% data reusables.actions.workflow-templates-metadata-keys %}
200176

201177
{% ifversion fpt or ghec %}
202178

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```json copy
2+
{
3+
"name": "Octo Organization Workflow",
4+
"description": "Octo Organization CI workflow template.",
5+
"iconName": "example-icon",
6+
"categories": [
7+
"Go"
8+
],
9+
"filePatterns": [
10+
"package.json$",
11+
"^Dockerfile",
12+
".*\\.md$"
13+
]
14+
}
15+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
* `name` - **Required.** The name of the workflow. This is displayed in the list of available workflows.
2+
* `description` - **Required.** The description of the workflow. This is displayed in the list of available workflows.
3+
* `iconName` - **Optional.** Specifies an icon for the workflow that is displayed in the list of workflows. `iconName` can be one of the following types:
4+
* An SVG file that is stored in the `workflow-templates` directory. To reference a file, the value must be the file name without the file extension. For example, an SVG file named `example-icon.svg` is referenced as `example-icon`.
5+
* An icon from {% data variables.product.prodname_dotcom %}'s set of [Octicons](https://primer.style/octicons/). To reference an octicon, the value must be `octicon <icon name>`. For example, `octicon smiley`.
6+
* `categories` - **Optional.** Defines the categories that the workflow is shown under. You can use category names from the following lists:
7+
* General category names from the [starter-workflows](https://github.com/actions/starter-workflows/blob/main/README.md#categories) repository.
8+
* Linguist languages from the list in the [linguist](https://github.com/github-linguist/linguist/blob/main/lib/linguist/languages.yml) repository.
9+
* Supported tech stacks from the list in the [starter-workflows](https://github.com/github-starter-workflows/repo-analysis-partner/blob/main/tech_stacks.yml) repository.
10+
11+
* `filePatterns` - **Optional.** Allows the workflow to be used if the user's repository has a file in its root directory that matches a defined regular expression.

0 commit comments

Comments
 (0)