Skip to content

Commit 8310197

Browse files
Merge pull request #1 from GraphQLSwift/feat/test-and-lint
Adds test and lint workflows
2 parents 5046c55 + 58e1a77 commit 8310197

File tree

7 files changed

+153
-0
lines changed

7 files changed

+153
-0
lines changed

.github/workflows/lint.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
package_path:
7+
type: string
8+
required: false
9+
default: ''
10+
description: "Specifies a subpath of the checkout that the package is contained in."
11+
12+
jobs:
13+
format:
14+
name: Format linting
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
- name: Pull formatting docker image
22+
run: docker pull ghcr.io/nicklockwood/swiftformat:latest
23+
- name: Run format linting
24+
run: docker run --rm -v ${{ github.workspace }}:/repo ghcr.io/nicklockwood/swiftformat:latest /repo/${{ inputs.package_path }} --lint

.github/workflows/self-test.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Self-test the CI workflows
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
uses: ./.github/workflows/lint.yaml
14+
with:
15+
package_path: WorkflowTestPackage
16+
test:
17+
uses: ./.github/workflows/test.yaml
18+
with:
19+
package_path: WorkflowTestPackage

.github/workflows/test.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
package_path:
7+
type: string
8+
required: false
9+
default: ''
10+
description: "Specifies a subpath of the checkout that the package is contained in."
11+
12+
env:
13+
PACKAGE_PATH: ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }}
14+
15+
jobs:
16+
macos:
17+
name: Test on macOS
18+
runs-on: macos-latest
19+
steps:
20+
- uses: maxim-lobanov/setup-xcode@v1
21+
with:
22+
xcode-version: latest-stable
23+
- uses: actions/checkout@v4
24+
- name: Build and test
25+
run: |
26+
swift test \
27+
--parallel \
28+
${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }}
29+
30+
linux:
31+
name: Test on Linux - ${{ matrix.swift-image }}
32+
strategy:
33+
matrix:
34+
swift-image:
35+
- "swift:5.8-jammy"
36+
- "swift:5.9-jammy"
37+
- "swift:5.10-jammy"
38+
- "swift:5.10-noble"
39+
- "swift:6.0-jammy"
40+
- "swift:6.0-noble"
41+
runs-on: ubuntu-latest
42+
container: ${{ matrix.swift-image }}
43+
steps:
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
- name: Test
47+
run: |
48+
swift test \
49+
--parallel \
50+
${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }}
51+
52+
android:
53+
name: Test on Android
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- name: Test
58+
uses: skiptools/swift-android-action@v2
59+
with:
60+
package-path: ${{ inputs.package_path != '' && inputs.package_path || '.' }}

WorkflowTestPackage/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc

WorkflowTestPackage/Package.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// swift-tools-version:5.8
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "WorkflowTestPackage",
7+
products: [
8+
.library(
9+
name: "WorkflowTestPackage",
10+
targets: ["WorkflowTestPackage"]
11+
),
12+
],
13+
targets: [
14+
// Targets are the basic building blocks of a package, defining a module or a test suite.
15+
// Targets can depend on other targets in this package and products from dependencies.
16+
.target(
17+
name: "WorkflowTestPackage"
18+
),
19+
.testTarget(
20+
name: "WorkflowTestPackageTests",
21+
dependencies: ["WorkflowTestPackage"]
22+
),
23+
]
24+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public struct WorkflowTest {
2+
public let foo = "bar"
3+
4+
public init() {}
5+
6+
public func hello() -> String {
7+
return "world"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@testable import WorkflowTestPackage
2+
3+
import XCTest
4+
5+
class WorkflowTestPackageTests: XCTestCase {
6+
func testHello() async throws {
7+
XCTAssertEqual(WorkflowTest().hello(), "world")
8+
}
9+
}

0 commit comments

Comments
 (0)