Explorar o código

Migrate CI to use swiftlang / SwiftNIO common GitHub Actions. (#10)

### Motivation:

* Reduce duplication
* Centralise boilerplate changes when new Swift versions are picked up.
* Benefit from centralised work to add new linting / test
infrastructure.

### Modifications:

Changes of note:
* Use soundness checks from swiftlang/github-workflows.
* Retain bespoke license-checking code for .swift files as the gRPC
header style is very different to most templates.

### Result:

More test, linting, formatting coverage. More common CI with other Swift
on Server projects.
Rick Newton-Rogers hai 1 ano
pai
achega
c7ab0b3091

+ 14 - 0
.github/release.yml

@@ -0,0 +1,14 @@
+changelog:
+  categories:
+    - title: SemVer Major
+      labels:
+        - ⚠️ semver/major
+    - title: SemVer Minor
+      labels:
+        - semver/minor
+    - title: SemVer Patch
+      labels:
+        - semver/patch
+    - title: Other Changes
+      labels:
+        - semver/none

+ 0 - 37
.github/workflows/ci.yaml

@@ -1,37 +0,0 @@
-name: CI
-on:
-  pull_request:
-    branches: [main]
-jobs:
-  preflight:
-    name: License Header and Formatting Checks
-    runs-on: ubuntu-latest
-    container:
-      image: swift:6.0-jammy
-    steps:
-    - name: "Checkout repository"
-      uses: actions/checkout@v4
-    - name: Mark the workspace as safe
-      run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
-    - name: "Formatting, License Headers, and Generated Code check"
-      run: |
-        ./dev/sanity.sh
-  unit-tests:
-    strategy:
-      fail-fast: false
-      matrix:
-        include:
-          - image: swiftlang/swift:nightly-jammy
-          - image: swift:6.0-jammy
-    name: Build and Test on ${{ matrix.image }}
-    runs-on: ubuntu-latest
-    container:
-      image: ${{ matrix.image }}
-    steps:
-    - uses: actions/checkout@v4
-    - name: 🔧 Build
-      run: swift build ${{ matrix.swift-build-flags }}
-      timeout-minutes: 20
-    - name: 🧪 Test
-      run: swift test ${{ matrix.swift-test-flags }}
-      timeout-minutes: 20

+ 18 - 0
.github/workflows/main.yml

@@ -0,0 +1,18 @@
+name: Main
+
+on:
+  push:
+    branches: [main]
+  schedule:
+    - cron: "0 8,20 * * *"
+
+jobs:
+  unit-tests:
+    name: Unit tests
+    uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
+    with:
+      linux_5_9_enabled: false
+      linux_5_10_enabled: false
+      linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
+      linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
+      linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"

+ 34 - 0
.github/workflows/pull_request.yml

@@ -0,0 +1,34 @@
+name: PR
+
+on:
+  pull_request:
+    branches: [main]
+    types: [opened, reopened, synchronize]
+
+jobs:
+  soundness:
+    name: Soundness
+    uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
+    with:
+      license_header_check_project_name: "gRPC"
+
+  grpc-soundness:
+    name: Soundness
+    uses: ./.github/workflows/soundness.yml
+
+  unit-tests:
+    name: Unit tests
+    uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
+    with:
+      linux_5_9_enabled: false
+      linux_5_10_enabled: false
+      linux_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
+      linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
+      linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error -Xswiftc -require-explicit-sendable"
+
+  cxx-interop:
+    name: Cxx interop
+    uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
+    with:
+      linux_5_9_enabled: false
+      linux_5_10_enabled: false

+ 18 - 0
.github/workflows/pull_request_label.yml

@@ -0,0 +1,18 @@
+name: PR
+
+on:
+  pull_request:
+    types: [labeled, unlabeled, opened, reopened, synchronize]
+
+jobs:
+  semver-label-check:
+    name: Semantic version label check
+    runs-on: ubuntu-latest
+    timeout-minutes: 1
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v4
+        with:
+          persist-credentials: false
+      - name: Check for Semantic Version label
+        uses: apple/swift-nio/.github/actions/pull_request_semver_label_checker@main

+ 19 - 0
.github/workflows/soundness.yml

@@ -0,0 +1,19 @@
+name: Soundness
+
+on:
+  workflow_call:
+
+jobs:
+  swift-license-check:
+    name: Swift license headers check
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v4
+        with:
+          persist-credentials: false
+      - name: Mark the workspace as safe
+        run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
+      - name: Run license check
+        run: |
+          ./dev/license-check.sh

+ 13 - 0
.license_header_template

@@ -0,0 +1,13 @@
+@@ Copyright YEARS, gRPC Authors All rights reserved.
+@@
+@@ Licensed under the Apache License, Version 2.0 (the "License");
+@@ you may not use this file except in compliance with the License.
+@@ You may obtain a copy of the License at
+@@
+@@     http://www.apache.org/licenses/LICENSE-2.0
+@@
+@@ Unless required by applicable law or agreed to in writing, software
+@@ distributed under the License is distributed on an "AS IS" BASIS,
+@@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@@ See the License for the specific language governing permissions and
+@@ limitations under the License.

+ 39 - 0
.licenseignore

@@ -0,0 +1,39 @@
+.gitignore
+**/.gitignore
+.licenseignore
+.gitattributes
+.git-blame-ignore-revs
+.mailfilter
+.mailmap
+.spi.yml
+.swift-format
+.swiftformatignore
+.editorconfig
+.github/*
+*.md
+*.txt
+*.yml
+*.yaml
+*.json
+Package.swift
+**/Package.swift
+Package@-*.swift
+**/Package@-*.swift
+Package.resolved
+**/Package.resolved
+Makefile
+*.modulemap
+**/*.modulemap
+**/*.docc/*
+*.xcprivacy
+**/*.xcprivacy
+*.symlink
+**/*.symlink
+Dockerfile
+**/Dockerfile
+Snippets/*
+dev/git.commit.template
+dev/version-bump.commit.template
+.unacceptablelanguageignore
+LICENSE
+**/*.swift

+ 2 - 0
.swiftformatignore

@@ -0,0 +1,2 @@
+*.grpc.swift
+*.pb.swift

+ 3 - 0
.unacceptablelanguageignore

@@ -0,0 +1,3 @@
+**/*.pb.swift
+**/*.grpc.swift
+dev/protos/upstream/**/*.proto

+ 2 - 2
Package.swift

@@ -42,7 +42,7 @@ let dependencies: [Package.Dependency] = [
 let defaultSwiftSettings: [SwiftSetting] = [
   .swiftLanguageMode(.v6),
   .enableUpcomingFeature("ExistentialAny"),
-  .enableUpcomingFeature("InternalImportsByDefault")
+  .enableUpcomingFeature("InternalImportsByDefault"),
 ]
 
 let targets: [Target] = [
@@ -95,7 +95,7 @@ let targets: [Target] = [
       .product(name: "SwiftProtobufPluginLibrary", package: "swift-protobuf"),
     ],
     swiftSettings: defaultSwiftSettings
-  )
+  ),
 ]
 
 let package = Package(

+ 14 - 16
dev/format.sh

@@ -1,18 +1,17 @@
 #!/bin/bash
-
-# Copyright 2020, gRPC Authors All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+## Copyright 2020, gRPC Authors All rights reserved.
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
 
 set -eu
 
@@ -69,8 +68,7 @@ if "$lint"; then
     To fix, run the following command:
 
     % $THIS_SCRIPT -f
-    "
-    exit "${SWIFT_FORMAT_RC}"
+    " "${SWIFT_FORMAT_RC}"
   fi
 
   log "Ran swift format lint with no errors."

+ 15 - 20
dev/license-check.sh

@@ -1,18 +1,17 @@
 #!/bin/bash
-
-# Copyright 2019, gRPC Authors All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+## Copyright 2019, gRPC Authors All rights reserved.
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
 
 # This script checks the copyright headers in source *.swift source files and
 # exits if they do not match the expected header. The year, or year range in
@@ -38,10 +37,6 @@ read -r -d '' COPYRIGHT_HEADER_SWIFT << 'EOF'
 EOF
 SWIFT_SHA=$(echo "$COPYRIGHT_HEADER_SWIFT" | shasum | awk '{print $1}')
 
-replace_years() {
-  sed -e 's/201[56789]-20[12][0-9]/YEARS/' -e 's/201[56789]/YEARS/'
-}
-
 # Checks the Copyright headers for *.swift files in this repository against the
 # expected headers.
 #
@@ -74,12 +69,12 @@ check_copyright_headers() {
         drop_first=1
         expected_lines=15
         ;;
-      */Package@swift-*.swift)
+      */Package@swift-*.*.swift)
         expected_sha="$SWIFT_SHA"
         drop_first=1
         expected_lines=15
         ;;
-      */Package@swift-*.*.swift)
+      */Package@swift-*.swift)
         expected_sha="$SWIFT_SHA"
         drop_first=1
         expected_lines=15

+ 13 - 14
dev/sanity.sh → dev/soundness.sh

@@ -1,18 +1,17 @@
 #!/bin/bash
-
-# Copyright 2020, gRPC Authors All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
+## Copyright 2020, gRPC Authors All rights reserved.
+##
+## Licensed under the Apache License, Version 2.0 (the "License");
+## you may not use this file except in compliance with the License.
+## You may obtain a copy of the License at
+##
+##     http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing, software
+## distributed under the License is distributed on an "AS IS" BASIS,
+## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+## See the License for the specific language governing permissions and
+## limitations under the License.
 
 set -eu