Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions content/actions/guides/building-and-testing-swift.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
title: Building and testing Swift
intro: You can create a continuous integration (CI) workflow to build and test your Swift project.
product: '{% data reusables.gated-features.actions %}'
versions:
free-pro-team: '*'
enterprise-server: '>=2.22'
github-ae: '*'
type: 'tutorial'
topics:
- 'CI'
- 'Swift'
---

{% data reusables.actions.enterprise-beta %}
{% data reusables.actions.enterprise-github-hosted-runners %}
{% data reusables.actions.ae-beta %}

### Introduction

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

{% if currentVersion == "github-ae@latest" %} To build and test your Swift project on {% data variables.product.prodname_ghe_managed %}, you will need to create a custom operating system image that includes the necessary Swift dependencies. For instructions on how to make sure your {% data variables.actions.hosted_runner %} has the required software installed, see "[Creating custom images](/actions/using-github-hosted-runners/creating-custom-images)."
{% else %}{% data variables.product.prodname_dotcom %}-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](/actions/using-github-hosted-runners/about-github-hosted-runners#supported-software)."{% endif %}

### Prerequisites

You should already be familiar with YAML syntax and how it's used with {% data variables.product.prodname_actions %}. For more information, see "[Workflow syntax for {% data variables.product.prodname_actions %}](/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions)."

We recommend that you have a basic understanding of Swift packages. For more information, see "[Swift Packages](https://developer.apple.com/documentation/swift_packages)" in the Apple developer documentation.

### Starting with the Swift workflow template

{% data variables.product.prodname_dotcom %} 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](https://github.com/actions/starter-workflows/blob/main/ci/swift.yml).

To get started quickly, add the template to the `.github/workflows` directory of your repository.

{% raw %}
```yaml{:copy}
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
```
{% endraw %}

### Specifying a Swift version

To use a specific preinstalled version of Swift on a {% data variables.product.prodname_dotcom %}-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`](https://github.com/marketplace/actions/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.

{% raw %}
```yaml{:copy}
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
```
{% endraw %}

#### Using a single specific Swift version

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

{% raw %}
```yaml{:copy}
steps:
- uses: fwal/setup-swift@v1
with:
swift-version: "5.3.3"
- name: Get swift version
run: swift --version # Swift 5.3.3
```
{% endraw %}

### Building and testing your code

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:

{% raw %}
```yaml{:copy}
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
```
{% endraw %}
4 changes: 3 additions & 1 deletion content/actions/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ includeGuides:
- /actions/guides/building-and-testing-java-with-maven
- /actions/guides/building-and-testing-java-with-gradle
- /actions/guides/building-and-testing-java-with-ant
- /actions/guides/building-and-testing-xamarin-applications
- /actions/guide/building-and-testing-swift
- /actions/guides/installing-an-apple-certificate-on-macos-runners-for-xcode-development
- /actions/guides/building-and-testing-xamarin-applications
- /actions/guides/publishing-nodejs-packages
- /actions/guides/publishing-java-packages-with-maven
- /actions/guides/publishing-java-packages-with-gradle
Expand Down Expand Up @@ -84,6 +85,7 @@ includeGuides:
<!-- {% link_in_list /building-and-testing-java-with-maven %} -->
<!-- {% link_in_list /building-and-testing-java-with-gradle %} -->
<!-- {% link_in_list /building-and-testing-java-with-ant %} -->
<!-- {% link_in_list /building-and-testing-swift %}-->
<!-- {% link_in_list /installing-an-apple-certificate-on-macos-runners-for-xcode-development %} -->
<!-- {% link_in_list /building-and-testing-xamarin-applications %} -->
<!-- {% link_in_list /about-packaging-with-github-actions %} -->
Expand Down
1 change: 1 addition & 0 deletions data/allowed-topics.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module.exports = [
'Security',
'Sponsors payments',
'Sponsors profile',
'Swift',
'Travis CI',
'User account',
'Webhooks',
Expand Down