4.8 KiB
title, shortTitle, intro, redirect_from, versions, type, topics
| title | shortTitle | intro | redirect_from | versions | type | topics | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Creating workflow templates | Creating templates | Learn how you can create workflow templates to help people in your team add new workflows more easily. |
|
|
tutorial |
|
{% data reusables.actions.enterprise-beta %} {% data reusables.actions.enterprise-github-hosted-runners %} {% data reusables.actions.ae-beta %}
Overview
{% data reusables.actions.workflow-organization-templates %}
Creating a workflow template
Workflow templates can be created by users with write access to the organization's .github repository. The templates can then be used by organization members who have permission to create workflows.
{% ifversion fpt %} Your workflow templates can be used to create workflows in public repositories only. Organizations using {% data variables.product.prodname_ghe_cloud %} can also use workflow templates to create workflows in private repositories. For more information, see the {% data variables.product.prodname_ghe_cloud %} documentation. {% endif %}
{% ifversion fpt or ghes > 3.3 or ghae-issue-4757 or ghec %} {% note %}
Note: To avoid duplication in workflows created from a template you can call reusable workflows from within a workflow template. This can help make your workflows easier to maintain. For more information, see "Reusing workflows."
{% endnote %} {% endif %}
This procedure demonstrates how to create a workflow template and metadata file. The metadata file describes how the template is presented to users when they are creating a new workflow.
-
If it doesn't already exist, create a new public repository named
.githubin your organization. -
Create a directory named
workflow-templates. -
Create your new workflow file inside the
workflow-templatesdirectory.If you need to refer to a repository's default branch, you can use the
$default-branchplaceholder. When a workflow is created using your template, the placeholder will be automatically replaced with the name of the repository's default branch.For example, this file named
octo-organization-ci.ymldemonstrates a basic workflow.name: Octo Organization CI on: push: branches: [ $default-branch ] pull_request: branches: [ $default-branch ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Run a one-line script run: echo Hello from Octo Organization -
Create a metadata file inside the
workflow-templatesdirectory. The metadata file must have the same name as the workflow file, but instead of the.ymlextension, it must be appended with.properties.json. For example, this file namedocto-organization-ci.properties.jsoncontains the metadata for a workflow file namedocto-organization-ci.yml:{ "name": "Octo Organization Workflow", "description": "Octo Organization CI workflow template.", "iconName": "example-icon", "categories": [ "Go" ], "filePatterns": [ "package.json$", "^Dockerfile", ".*\\.md$" ] }name- Required. The name of the workflow template. This is displayed in the list of available templates.description- Required. The description of the workflow template. This is displayed in the list of available templates.iconName- Optional. Defines an icon for the workflow's entry in the template list. TheiconNamemust be an SVG icon of the same name, and must be stored in theworkflow-templatesdirectory. For example, a SVG file namedexample-icon.svgis referenced asexample-icon.categories- Optional. Defines the language category of the workflow. When a user views the available templates, those templates that match the same language will feature more prominently. For information on the available language categories, see https://github.com/github/linguist/blob/master/lib/linguist/languages.yml.filePatterns- Optional. Allows the template to be used if the user's repository has a file in its root directory that matches a defined regular expression.
To add another workflow template, add your files to the same workflow-templates directory. For example:
Next steps
To continue learning about {% data variables.product.prodname_actions %}, see "Using workflow templates."
