From 353e587d4780cc9948e2dc3d524568547726b6a7 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 10 Jan 2024 17:55:01 -0800 Subject: [PATCH] Try to modernize CI --- .devcontainer/Dockerfile | 4 ++ .devcontainer/devcontainer.json | 46 ++++++++++++++ .github/workflows/build-and-test.yml | 89 ++++++++++++++++++++++++++++ .github/workflows/codecov.yml | 32 ++++++++++ .github/workflows/swift.yml | 51 ---------------- 5 files changed, 171 insertions(+), 51 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100644 .github/workflows/build-and-test.yml create mode 100644 .github/workflows/codecov.yml delete mode 100644 .github/workflows/swift.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..0426b91 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,4 @@ +ARG SWIFT_VERSION + +FROM swift:${SWIFT_VERSION} + diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..6950c41 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,46 @@ +{ + "name": "Swift", + "build": { + "dockerfile": "Dockerfile", + "args": { + "SWIFT_VERSION" : "5.8" + } + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": "false", + "username": "vscode", + "userUid": "1000", + "userGid": "1000", + "upgradePackages": "false" + }, + "ghcr.io/devcontainers/features/git:1": { + "version": "os-provided", + "ppa": "false" + } + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Set *default* container specific settings.json values on container create. + "settings": { + "lldb.library": "/usr/lib/liblldb.so" + }, + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "sswg.swift-lang" + ] + } + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..dc6d027 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,89 @@ +--- +name: Build and test + +"on": + push: + branches: [main] + pull_request: + branches: ["**"] + +jobs: + + devcontainer: + name: "Devcontainer: ${{ matrix.os }}/${{ matrix.configuration }}" + strategy: + matrix: + os: [ubuntu-latest] + configuration: [debug] + + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + show-progress: false + + - name: Build and Test + uses: devcontainers/ci@v0.3 + with: + runCmd: swift test --explicit-target-dependency-import-check=error -c ${{ matrix.configuration }} + + xcode: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + with: + show-progress: false + + - name: Build and Test + run: xcrun xcodebuild -skipPackagePluginValidation -scheme Lotsawa -destination 'platform=macOS' test + + native: + name: "Native: ${{ matrix.os }}/${{ matrix.configuration }}" + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + + configuration: [debug] + + include: + # Default values to add + - shell: 'bash -eo pipefail {0}' + - build-options: '--explicit-target-dependency-import-check=error' + + # Overrides for the defaults + - shell: pwsh + os: windows-latest + + runs-on: ${{ matrix.os }} + + defaults: + run: + shell: ${{ matrix.shell }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + show-progress: false + + + - name: Setup Swift (Unices) + if: ${{ matrix.os != 'windows-latest' }} + uses: 'swift-actions/setup-swift@v1' + with: + version: 5.9 + + - name: Setup Swift (Windows) + if: ${{ matrix.os == 'windows-latest' }} + uses: 'compnerd/gha-setup-swift@main' + with: + github-repo: thebrowsercompany/swift-build + release-asset-name: installer-amd64.exe + release-tag-name: 20231010.3 + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Test (${{ matrix.configuration }}) + run: > + swift test -c ${{ matrix.configuration }} ${{ matrix.build-options }} + --explicit-target-dependency-import-check=error diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml new file mode 100644 index 0000000..fa7fd2e --- /dev/null +++ b/.github/workflows/codecov.yml @@ -0,0 +1,32 @@ +name: Code Coverage + +on: + push: + branches: [ main ] + pull_request: + branches: [ "**" ] + +jobs: + + codecov: + runs-on: macos-latest + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + show-progress: false + + + - name: Test and generate code coverage report + run: xcrun xcodebuild -skipPackagePluginValidation -enableCodeCoverage YES -scheme Lotsawa -destination 'platform=macOS' test + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + env_vars: OS + fail_ci_if_error: true + flags: unittests + swift: true + name: codecov-umbrella + verbose: true diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml deleted file mode 100644 index fabb582..0000000 --- a/.github/workflows/swift.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Swift - -on: - push: - branches: [ main ] - pull_request: - branches: [ "**" ] - -jobs: - macos: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Build - run: swift build --build-tests - - name: Run tests - run: swift test - xcode: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Build - run: xcrun xcodebuild -skipPackagePluginValidation -scheme Lotsawa -destination 'platform=macOS' - linux: - container: - image: swift:${{ matrix.linux }} - runs-on: ubuntu-latest - strategy: - matrix: - linux: [bionic, focal] - steps: - - uses: actions/checkout@v2 - - name: Build - run: swift build --build-tests --enable-test-discovery - - name: Test - run: swift test --enable-test-discovery - codecov: - runs-on: macos-latest - steps: - - uses: actions/checkout@v2 - - name: Test and generate code coverage report - run: xcrun xcodebuild -skipPackagePluginValidation -enableCodeCoverage YES -scheme Lotsawa -destination 'platform=macOS' test - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - env_vars: OS - fail_ci_if_error: true - flags: unittests - swift: true - name: codecov-umbrella - verbose: true