diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..74e3a18 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,24 @@ +name: Lint + +on: + workflow_call: + inputs: + package_path: + type: string + required: false + default: '' + description: "Specifies a subpath of the checkout that the package is contained in." + +jobs: + format: + name: Format linting + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Pull formatting docker image + run: docker pull ghcr.io/nicklockwood/swiftformat:latest + - name: Run format linting + run: docker run --rm -v ${{ github.workspace }}:/repo ghcr.io/nicklockwood/swiftformat:latest /repo/${{ inputs.package_path }} --lint diff --git a/.github/workflows/self-test.yaml b/.github/workflows/self-test.yaml new file mode 100644 index 0000000..9204657 --- /dev/null +++ b/.github/workflows/self-test.yaml @@ -0,0 +1,19 @@ +name: Self-test the CI workflows + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + lint: + uses: ./.github/workflows/lint.yaml + with: + package_path: WorkflowTestPackage + test: + uses: ./.github/workflows/test.yaml + with: + package_path: WorkflowTestPackage diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..ce57fc1 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,60 @@ +name: Test + +on: + workflow_call: + inputs: + package_path: + type: string + required: false + default: '' + description: "Specifies a subpath of the checkout that the package is contained in." + +env: + PACKAGE_PATH: ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }} + +jobs: + macos: + name: Test on macOS + runs-on: macos-latest + steps: + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: latest-stable + - uses: actions/checkout@v4 + - name: Build and test + run: | + swift test \ + --parallel \ + ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }} + + linux: + name: Test on Linux - ${{ matrix.swift-image }} + strategy: + matrix: + swift-image: + - "swift:5.8-jammy" + - "swift:5.9-jammy" + - "swift:5.10-jammy" + - "swift:5.10-noble" + - "swift:6.0-jammy" + - "swift:6.0-noble" + runs-on: ubuntu-latest + container: ${{ matrix.swift-image }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Test + run: | + swift test \ + --parallel \ + ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }} + + android: + name: Test on Android + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Test + uses: skiptools/swift-android-action@v2 + with: + package-path: ${{ inputs.package_path != '' && inputs.package_path || '.' }} diff --git a/WorkflowTestPackage/.gitignore b/WorkflowTestPackage/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/WorkflowTestPackage/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/WorkflowTestPackage/Package.swift b/WorkflowTestPackage/Package.swift new file mode 100644 index 0000000..15aa85e --- /dev/null +++ b/WorkflowTestPackage/Package.swift @@ -0,0 +1,24 @@ +// swift-tools-version:5.8 + +import PackageDescription + +let package = Package( + name: "WorkflowTestPackage", + products: [ + .library( + name: "WorkflowTestPackage", + targets: ["WorkflowTestPackage"] + ), + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target( + name: "WorkflowTestPackage" + ), + .testTarget( + name: "WorkflowTestPackageTests", + dependencies: ["WorkflowTestPackage"] + ), + ] +) diff --git a/WorkflowTestPackage/Sources/WorkflowTestPackage/WorkflowTestPackage.swift b/WorkflowTestPackage/Sources/WorkflowTestPackage/WorkflowTestPackage.swift new file mode 100644 index 0000000..2b38863 --- /dev/null +++ b/WorkflowTestPackage/Sources/WorkflowTestPackage/WorkflowTestPackage.swift @@ -0,0 +1,9 @@ +public struct WorkflowTest { + public let foo = "bar" + + public init() {} + + public func hello() -> String { + return "world" + } +} diff --git a/WorkflowTestPackage/Tests/WorkflowTestPackageTests/WorkflowTestPackageTests.swift b/WorkflowTestPackage/Tests/WorkflowTestPackageTests/WorkflowTestPackageTests.swift new file mode 100644 index 0000000..f020c0d --- /dev/null +++ b/WorkflowTestPackage/Tests/WorkflowTestPackageTests/WorkflowTestPackageTests.swift @@ -0,0 +1,9 @@ +@testable import WorkflowTestPackage + +import XCTest + +class WorkflowTestPackageTests: XCTestCase { + func testHello() async throws { + XCTAssertEqual(WorkflowTest().hello(), "world") + } +}