# 使用 GitHub 托管的运行器

您可以将作业分配到由 GitHub 托管的虚拟机上运行。

## 使用 GitHub 托管的运行器

若要使用 GitHub托管运行程序，请创建一个作业并用于 `runs-on` 指定将处理作业的运行程序类型，例如 `ubuntu-latest`， `windows-latest`或 `macos-latest`。 有关运行器类型的完整列表，请参阅 [GitHub 托管的运行器参考](/zh/actions/reference/runners/github-hosted-runners#supported-runners-and-hardware-resources)。 如果你对某个仓库具有 `repo: write` 访问权限，则可以查看该仓库中可在工作流里使用的运行器列表。 有关更多信息，请参阅[查看存储库的可用运行器](#viewing-available-runners-for-a-repository)。

作业开始时， GitHub 自动为该作业预配新的 VM。 作业中的所有步骤在该 VM 中执行，让该作业中的步骤使用运行器的文件系统共享信息。 可以直接在 VM 上或 Docker 容器中运行工作流。 作业完成后，VM 会自动退役。

下图演示了如何在两个不同的 GitHub托管运行程序上执行工作流中的两个作业。

![包含两个作业的工作流示意图。 一个作业在 Ubuntu 上运行，另一个在 Windows 上运行。](/assets/images/help/actions/overview-github-hosted-runner.png)

以下示例工作流有两个作业，名为 `Run-npm-on-Ubuntu` 和 `Run-PSScriptAnalyzer-on-Windows`。 触发此工作流时， GitHub 为每个作业预配一个新的虚拟机。

* 名为 `Run-npm-on-Ubuntu` 的作业在 Linux VM 上执行，因为作业 `runs-on:` 指定 `ubuntu-latest`。
* 名为 `Run-PSScriptAnalyzer-on-Windows` 的作业在 Windows VM 上执行，因为作业 `runs-on:` 指定 `windows-latest`。

```yaml copy
name: Run commands on different operating systems
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  Run-npm-on-Ubuntu:
    name: Run npm on Ubuntu
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v7
        with:
          node-version: '14'
      - run: npm help

  Run-PSScriptAnalyzer-on-Windows:
    name: Run PSScriptAnalyzer on Windows
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v6
      - name: Install PSScriptAnalyzer module
        shell: pwsh
        run: |
          Set-PSRepository PSGallery -InstallationPolicy Trusted
          Install-Module PSScriptAnalyzer -ErrorAction Stop
      - name: Get list of rules
        shell: pwsh
        run: |
          Get-ScriptAnalyzerRule
```

运行作业时，可以在 UI 中 GitHub 查看日志和输出：

![工作流的运行截图 将显示“在 Windows 上运行 PSScriptAnalyzer”作业的步骤。](/assets/images/help/repository/actions-runner-output.png)

GitHub Actions 运行器应用程序是开源的。 可以参与 [runner](https://github.com/actions/runner) 存储库并在其中提交问题。

## 查看存储库可用的运行器

如果对存储库具有 `repo: write` 访问权限，则可以查看存储库可用的运行器列表。

1. 在 GitHub 上，导航到存储库的主页面。
2. 在仓库名称下，单击“<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-play" aria-label="play" role="img"><path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Zm4.879-2.773 4.264 2.559a.25.25 0 0 1 0 .428l-4.264 2.559A.25.25 0 0 1 6 10.559V5.442a.25.25 0 0 1 .379-.215Z"></path></svg> Actions”\*\*\*\*。

   ![“github/docs”存储库的选项卡的屏幕截图。 “操作”选项卡以橙色边框突出显示。](/assets/images/help/repository/actions-tab-global-nav-update.png)
3. 在左边栏中的“Management”部分下，单击 <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-server" aria-label="server" role="img"><path d="M1.75 1h12.5c.966 0 1.75.784 1.75 1.75v4c0 .372-.116.717-.314 1 .198.283.314.628.314 1v4a1.75 1.75 0 0 1-1.75 1.75H1.75A1.75 1.75 0 0 1 0 12.75v-4c0-.358.109-.707.314-1a1.739 1.739 0 0 1-.314-1v-4C0 1.784.784 1 1.75 1ZM1.5 2.75v4c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-4a.25.25 0 0 0-.25-.25H1.75a.25.25 0 0 0-.25.25Zm.25 5.75a.25.25 0 0 0-.25.25v4c0 .138.112.25.25.25h12.5a.25.25 0 0 0 .25-.25v-4a.25.25 0 0 0-.25-.25ZM7 4.75A.75.75 0 0 1 7.75 4h4.5a.75.75 0 0 1 0 1.5h-4.5A.75.75 0 0 1 7 4.75ZM7.75 10h4.5a.75.75 0 0 1 0 1.5h-4.5a.75.75 0 0 1 0-1.5ZM3 4.75A.75.75 0 0 1 3.75 4h.5a.75.75 0 0 1 0 1.5h-.5A.75.75 0 0 1 3 4.75ZM3.75 10h.5a.75.75 0 0 1 0 1.5h-.5a.75.75 0 0 1 0-1.5Z"></path></svg>“Runners”\*\*\*\*。
4. 查看存储库可用的 GitHub 托管运行器列表。
5. （可选）要复制运行器标签以在工作流中使用，请单击运行器右侧的 <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-kebab-horizontal" aria-label="More options" role="img"><path d="M8 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3ZM1.5 9a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Zm13 0a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"></path></svg>，然后单击“复制标签”。\*\*\*\*

> \[!NOTE]
> 企业和组织所有者可以在此页面创建运行器。 若要创建新的运行器，请单击运行器列表右上角的“新建运行器”\*\*\*\*，将运行器添加到存储库。
>
> 有关详细信息，请参阅 [管理较大的运行器](/zh/actions/how-tos/manage-runners/larger-runners/manage-larger-runners) 和 [添加自托管的运行器](/zh/actions/how-tos/manage-runners/self-hosted-runners/add-runners)。