Skip to main content

此版本的 GitHub Enterprise 已停止服务 2022-10-12. 即使针对重大安全问题,也不会发布补丁。 为了获得更好的性能、更高的安全性和新功能,请升级到最新版本的 GitHub Enterprise。 如需升级帮助,请联系 GitHub Enterprise 支持

Creating starter workflows for your organization

Learn how you can create starter workflows to help people in your team add new workflows more easily.

注意:GitHub Enterprise Server 目前不支持 GitHub 托管的运行器。 可以在 GitHub public roadmap 上查看有关未来支持计划的更多信息。

Overview

组织中所有有权创建工作流的人员可利用入门工作流,更快、更轻松地创建工作流。 创建新工作流时,� 可以选择入门工作流,系统将为� 完成编写工作流的部分或全部工作。 � 可以使用入门工作流作为基础来构建自定义工作流,或按原� �使用。 这不仅可以节省时间,而且促进了整个组织的一致性和最佳做法。

GitHub 为以下高级类别提供现成的入门工作流:

  • 部署 (CD) 。 有关详细信息,请参阅“关于持续部署”。
  • 持续集成 (CI) 。 有关详细信息,请参阅“关于持续集成”。
  • 自动化. 自动化入门工作流提供了自动化工作流的解决方案,例如,对拉取请求分类并� �据拉取请求中修改的路径对拉取请求应用� �签,或问候首次参与存储库的用户。

Creating a starter workflow

Starter workflows can be created by users with write access to the organization's .github repository. These can then be used by organization members who have permission to create workflows.

This procedure demonstrates how to create a starter workflow and metadata file. The metadata file describes how the starter workflows will be presented to users when they are creating a new workflow.

  1. If it doesn't already exist, create a new public repository named .github in your organization.

  2. Create a directory named workflow-templates.

  3. Create your new workflow file inside the workflow-templates directory.

    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.

    For example, this file named octo-organization-ci.yml demonstrates 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
    
  4. 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:

    {
        "name": "Octo Organization Workflow",
        "description": "Octo Organization CI starter workflow.",
        "iconName": "example-icon",
        "categories": [
            "Go"
        ],
        "filePatterns": [
            "package.json$",
            "^Dockerfile",
            ".*\\.md$"
        ]
    }
    
    • name - Required. The name of the workflow. This is displayed in the list of available workflows.
    • description - Required. The description of the workflow. This is displayed in the list of available workflows.
    • iconName - Optional. Specifies an icon for the workflow that's displayed in the list of workflows. The iconName must be the name of an SVG file, without the file name extension, stored in the workflow-templates directory. For example, an SVG file named example-icon.svg is referenced as example-icon.
    • categories - Optional. Defines the language category of the workflow. When a user views the available starter workflows for a repository, the workflows that match the identified language for the project are featured 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 workflow to be used if the user's repository has a file in its root directory that matches a defined regular expression.

To add another starter workflow, add your files to the same workflow-templates directory. For example:

Workflow files

Next steps

To continue learning about GitHub Actions, see "Using starter workflows."