From 25e32ecfb991f0ad0a786af174e2fd4357bcf7d4 Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Thu, 20 Mar 2025 22:08:41 -0600 Subject: [PATCH 1/3] feat: Adds test & lint jobs --- .github/workflows/lint.yaml | 24 +++++++++++++ .github/workflows/test.yaml | 67 +++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/test.yaml 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/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..7d60740 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,67 @@ +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 + runs-on: ubuntu-latest + steps: + - uses: swift-actions/setup-swift@v2 + - 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 || '.' }} + + backcompat-ubuntu-22_04: + name: Test Swift ${{ matrix.swift }} on Ubuntu 22.04 + runs-on: ubuntu-22.04 + strategy: + matrix: + swift: ["5.8", "5.9", "5.10", "6.0"] + steps: + - uses: swift-actions/setup-swift@v2 + with: + swift-version: ${{ matrix.swift }} + - uses: actions/checkout@v4 + - name: Test + run: | + swift test \ + --parallel \ + ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }} From ff2611e39ce080cb3ce858e3117a4306e3b910af Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Thu, 20 Mar 2025 22:09:08 -0600 Subject: [PATCH 2/3] test: Adds self-tests & example package --- .github/workflows/self-test.yaml | 19 +++++++++++++++ WorkflowTestPackage/.gitignore | 8 +++++++ WorkflowTestPackage/Package.swift | 24 +++++++++++++++++++ .../WorkflowTestPackage.swift | 9 +++++++ .../WorkflowTestPackageTests.swift | 9 +++++++ 5 files changed, 69 insertions(+) create mode 100644 .github/workflows/self-test.yaml create mode 100644 WorkflowTestPackage/.gitignore create mode 100644 WorkflowTestPackage/Package.swift create mode 100644 WorkflowTestPackage/Sources/WorkflowTestPackage/WorkflowTestPackage.swift create mode 100644 WorkflowTestPackage/Tests/WorkflowTestPackageTests/WorkflowTestPackageTests.swift 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/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") + } +} From 58e1a774e826f6d97cce5b14eeec2c5ab600060a Mon Sep 17 00:00:00 2001 From: Jay Herron Date: Thu, 20 Mar 2025 23:01:22 -0600 Subject: [PATCH 3/3] feat: Unifies linux testing --- .github/workflows/test.yaml | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7d60740..ce57fc1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,11 +28,21 @@ jobs: ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }} linux: - name: Test on 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: - - uses: swift-actions/setup-swift@v2 - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 - name: Test run: | swift test \ @@ -48,20 +58,3 @@ jobs: uses: skiptools/swift-android-action@v2 with: package-path: ${{ inputs.package_path != '' && inputs.package_path || '.' }} - - backcompat-ubuntu-22_04: - name: Test Swift ${{ matrix.swift }} on Ubuntu 22.04 - runs-on: ubuntu-22.04 - strategy: - matrix: - swift: ["5.8", "5.9", "5.10", "6.0"] - steps: - - uses: swift-actions/setup-swift@v2 - with: - swift-version: ${{ matrix.swift }} - - uses: actions/checkout@v4 - - name: Test - run: | - swift test \ - --parallel \ - ${{ inputs.package_path != '' && format('--package-path={0}', inputs.package_path) || '' }}