Skip to content

Commit b586735

Browse files
v-abissSarah Edwards
andauthored
Add Actions guide for building and testing Swift (github#18663)
Co-authored-by: Sarah Edwards <skedwards88@github.com>
1 parent d35dab0 commit b586735

File tree

3 files changed

+131
-1
lines changed

3 files changed

+131
-1
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Building and testing Swift
3+
intro: You can create a continuous integration (CI) workflow to build and test your Swift project.
4+
product: '{% data reusables.gated-features.actions %}'
5+
versions:
6+
free-pro-team: '*'
7+
enterprise-server: '>=2.22'
8+
github-ae: '*'
9+
type: 'tutorial'
10+
topics:
11+
- 'CI'
12+
- 'Swift'
13+
---
14+
15+
{% data reusables.actions.enterprise-beta %}
16+
{% data reusables.actions.enterprise-github-hosted-runners %}
17+
{% data reusables.actions.ae-beta %}
18+
19+
### Introduction
20+
21+
This guide shows you how to build and test a Swift package.
22+
23+
{% 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)."
24+
{% 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 %}
25+
26+
### Prerequisites
27+
28+
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)."
29+
30+
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.
31+
32+
### Starting with the Swift workflow template
33+
34+
{% 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).
35+
36+
To get started quickly, add the template to the `.github/workflows` directory of your repository.
37+
38+
{% raw %}
39+
```yaml{:copy}
40+
name: Swift
41+
42+
on: [push]
43+
44+
jobs:
45+
build:
46+
47+
runs-on: macos-latest
48+
49+
steps:
50+
- uses: actions/checkout@v2
51+
- name: Build
52+
run: swift build
53+
- name: Run tests
54+
run: swift test
55+
```
56+
{% endraw %}
57+
58+
### Specifying a Swift version
59+
60+
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.
61+
62+
If you are using a self-hosted runner, you must install your desired Swift versions and add them to `PATH`.
63+
64+
The examples below demonstrate using the `fwal/setup-swift` action.
65+
66+
#### Using multiple Swift versions
67+
68+
You can configure your job to use a multiple versions of Swift in a build matrix.
69+
70+
{% raw %}
71+
```yaml{:copy}
72+
name: Swift
73+
74+
on: [push]
75+
76+
jobs:
77+
build:
78+
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
79+
strategy:
80+
matrix:
81+
os: [ubuntu-latest, macos-latest]
82+
swift: ["5.2", "5.3"]
83+
runs-on: ${{ matrix.os }}
84+
steps:
85+
- uses: fwal/setup-swift@v1
86+
with:
87+
swift-version: ${{ matrix.swift }}
88+
- uses: actions/checkout@v2
89+
- name: Build
90+
run: swift build
91+
- name: Run tests
92+
run: swift test
93+
```
94+
{% endraw %}
95+
96+
#### Using a single specific Swift version
97+
98+
You can configure your job to use a single specific version of Swift, such as `5.3.3`.
99+
100+
{% raw %}
101+
```yaml{:copy}
102+
steps:
103+
- uses: fwal/setup-swift@v1
104+
with:
105+
swift-version: "5.3.3"
106+
- name: Get swift version
107+
run: swift --version # Swift 5.3.3
108+
```
109+
{% endraw %}
110+
111+
### Building and testing your code
112+
113+
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:
114+
115+
{% raw %}
116+
```yaml{:copy}
117+
steps:
118+
- uses: actions/checkout@v2
119+
- uses: fwal/setup-swift@v1
120+
with:
121+
swift-version: "5.3.3"
122+
- name: Build
123+
run: swift build
124+
- name: Run tests
125+
run: swift test
126+
```
127+
{% endraw %}

content/actions/guides/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ includeGuides:
4242
- /actions/guides/building-and-testing-java-with-maven
4343
- /actions/guides/building-and-testing-java-with-gradle
4444
- /actions/guides/building-and-testing-java-with-ant
45-
- /actions/guides/building-and-testing-xamarin-applications
45+
- /actions/guide/building-and-testing-swift
4646
- /actions/guides/installing-an-apple-certificate-on-macos-runners-for-xcode-development
47+
- /actions/guides/building-and-testing-xamarin-applications
4748
- /actions/guides/publishing-nodejs-packages
4849
- /actions/guides/publishing-java-packages-with-maven
4950
- /actions/guides/publishing-java-packages-with-gradle
@@ -84,6 +85,7 @@ includeGuides:
8485
<!-- {% link_in_list /building-and-testing-java-with-maven %} -->
8586
<!-- {% link_in_list /building-and-testing-java-with-gradle %} -->
8687
<!-- {% link_in_list /building-and-testing-java-with-ant %} -->
88+
<!-- {% link_in_list /building-and-testing-swift %}-->
8789
<!-- {% link_in_list /installing-an-apple-certificate-on-macos-runners-for-xcode-development %} -->
8890
<!-- {% link_in_list /building-and-testing-xamarin-applications %} -->
8991
<!-- {% link_in_list /about-packaging-with-github-actions %} -->

data/allowed-topics.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ module.exports = [
5151
'Security',
5252
'Sponsors payments',
5353
'Sponsors profile',
54+
'Swift',
5455
'Travis CI',
5556
'User account',
5657
'Webhooks',

0 commit comments

Comments
 (0)