Diese Version von GitHub Enterprise wird eingestellt am 2021-09-23. Es wird keine Patch-Freigabe vorgenommen, auch nicht für kritische Sicherheitsprobleme. Für eine bessere Leistung, verbesserte Sicherheit und neue Features nimm ein Upgrade auf die neueste Version von GitHub Enterprise vor. Wende Dich an den GitHub Enterprise-Support, um Hilfe beim Upgrade zu erhalten.

Building and testing Swift

You can create a continuous integration (CI) workflow to build and test your Swift project.

GitHub Actions ist verfügbar mit GitHub Free, GitHub Pro, GitHub Free für Organisationen, GitHub Team, GitHub Enterprise Cloud, und GitHub AE. GitHub Actions ist nicht verfügbar für private Repositorys, die im Besitz von Konten mit älteren Pro-Repository-Plänen sind.

Note: GitHub Actions was available for GitHub Enterprise Server 2.22 as a limited beta. The beta has ended. GitHub Actions is now generally available in GitHub Enterprise Server 3.0 or later. For more information, see the GitHub Enterprise Server 3.0 release notes.


Note: GitHub-hosted runners are not currently supported on GitHub Enterprise Server. You can see more information about planned future support on the GitHub public roadmap.

Einführung

This guide shows you how to build and test a Swift package.

GitHub-hosted runners have a tools cache with preinstalled software, and the Ubuntu and macOS runners include the dependencies for building Swift packages. For a full list of up-to-date software and the preinstalled versions of Swift and Xcode, see "About GitHub-hosted runners."

Vorrausetzungen

You should already be familiar with YAML syntax and how it's used with GitHub Actions. Weitere Informationen findest Du unter „Workflow-Syntax für GitHub Actions“.

We recommend that you have a basic understanding of Swift packages. For more information, see "Swift Packages" in the Apple developer documentation.

Starting with the Swift workflow template

GitHub provides a Swift workflow template that should work for most Swift projects, and this guide includes examples that show you how to customize this template. For more information, see the Swift workflow template.

Um schnell loszulegen, füge die Vorlage in das Verzeichnis .github/workflows Deines Repositorys ein.

YAML
name: Swift

on: [push]

jobs:
  build:

    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2
      - name: Build
        run: swift build
      - name: Run tests
        run: swift test

Specifying a Swift version

To use a specific preinstalled version of Swift on a GitHub-hosted runner, use the fwal/setup-swift action. This action finds a specific version of Swift from the tools cache on the runner and adds the necessary binaries to PATH. These changes will persist for the remainder of a job. For more information, see the fwal/setup-swift action.

If you are using a self-hosted runner, you must install your desired Swift versions and add them to PATH.

The examples below demonstrate using the fwal/setup-swift action.

Using multiple Swift versions

You can configure your job to use a multiple versions of Swift in a build matrix.

YAML
name: Swift

on: [push]

jobs:
  build:
    name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        swift: ["5.2", "5.3"]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: fwal/setup-swift@v1
        with:
          swift-version: ${{ matrix.swift }}
      - uses: actions/checkout@v2
      - name: Build
        run: swift build
      - name: Run tests
        run: swift test

Using a single specific Swift version

You can configure your job to use a single specific version of Swift, such as 5.3.3.

YAML
steps:
  - uses: fwal/setup-swift@v1
    with:
      swift-version: "5.3.3"
  - name: Get swift version
    run: swift --version # Swift 5.3.3

Deinen Code bauen und testen

You can use the same commands that you use locally to build and test your code using Swift. This example demonstrates how to use swift build and swift test in a job:

YAML
steps:
  - uses: actions/checkout@v2
  - uses: fwal/setup-swift@v1
    with:
      swift-version: "5.3.3"
  - name: Build
    run: swift build
  - name: Run tests
    run: swift test

Did this doc help you?Privacy policy

Help us make these docs great!

All GitHub docs are open source. See something that's wrong or unclear? Submit a pull request.

Make a contribution

Oder, learn how to contribute.