From d016643222300dc64e3cef4ef78e10b5ccccae38 Mon Sep 17 00:00:00 2001 From: Rick Newton-Rogers Date: Tue, 15 Oct 2024 13:04:58 +0100 Subject: [PATCH] Migrate to GitHub Actions reusable workflows (2) (#74) * Prepare repo for new GHA checks Motivation: Migrate to GitHub Actions reusable workflows (2) Modifications: * Add GHA PR label checks * Add GHA benchmarks checks * Satisfy soundness checks Result: New soundness checks should be green and ready for adoption * review comments --- .github/workflows/pull_request.yml | 18 +- .github/workflows/pull_request_label.yml | 18 ++ ...PKI_Roots_from_PEM_to_PEMDocument.p90.json | 0 ...ots_from_multi_PEM_to_PEMDocument.p90.json | 0 ...ts_from_multi_PEM_to_PEMDocument_.p90.json | 0 ...PKI_Roots_from_PEM_to_PEMDocument.p90.json | 6 + ...ots_from_multi_PEM_to_PEMDocument.p90.json | 6 + ...ts_from_multi_PEM_to_PEMDocument_.p90.json | 6 + ...PKI_Roots_from_PEM_to_PEMDocument.p90.json | 6 + ...ots_from_multi_PEM_to_PEMDocument.p90.json | 6 + ...ts_from_multi_PEM_to_PEMDocument_.p90.json | 6 + CONTRIBUTING.md | 26 +-- Package.swift | 13 +- Sources/SwiftASN1/ASN1.swift | 3 +- Sources/SwiftASN1/BER.swift | 6 +- .../Basic ASN1 Types/TimeUtilities.swift | 1 - Sources/SwiftASN1/DER.swift | 8 +- dev/update-benchmark-thresholds.sh | 2 +- docker/docker-compose.yaml | 4 +- scripts/check_no_api_breakages.sh | 40 +--- scripts/run-swift-format.sh | 54 ----- scripts/soundness.sh | 208 ------------------ scripts/update_cmakelists.sh | 6 +- 23 files changed, 81 insertions(+), 362 deletions(-) create mode 100644 .github/workflows/pull_request_label.yml rename Benchmarks/Thresholds/{main => 6.0}/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json (100%) rename Benchmarks/Thresholds/{main => 6.0}/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json (100%) rename Benchmarks/Thresholds/{main => 6.0}/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json (100%) create mode 100644 Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json create mode 100644 Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json create mode 100644 Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json create mode 100644 Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json create mode 100644 Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json create mode 100644 Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json delete mode 100644 scripts/run-swift-format.sh delete mode 100755 scripts/soundness.sh diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 496c414..49f07c9 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -9,31 +9,25 @@ jobs: name: Soundness uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main with: - # These are set to false to stage this in with the old CI. - # A follow-up PR will cut them over. - api_breakage_check_enabled: false - broken_symlink_check_enabled: false - docs_check_enabled: false - format_check_enabled: false - license_header_check_enabled: false license_header_check_project_name: "SwiftASN1" - shell_check_enabled: false - unacceptable_language_check_enabled: false unit-tests: name: Unit tests uses: apple/swift-nio/.github/workflows/unit_tests.yml@main with: - linux_5_8_enabled: false linux_5_9_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_5_10_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error" linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error" linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error" + benchmarks: + name: Benchmarks + uses: apple/swift-nio/.github/workflows/benchmarks.yml@main + with: + benchmark_package_path: "Benchmarks" + cxx-interop: name: Cxx interop uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main - with: - linux_5_8_enabled: false swift-6-language-mode: name: Swift 6 Language Mode diff --git a/.github/workflows/pull_request_label.yml b/.github/workflows/pull_request_label.yml new file mode 100644 index 0000000..86f199f --- /dev/null +++ b/.github/workflows/pull_request_label.yml @@ -0,0 +1,18 @@ +name: PR label + +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 diff --git a/Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json similarity index 100% rename from Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json rename to Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json diff --git a/Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json similarity index 100% rename from Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json rename to Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json diff --git a/Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json b/Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json similarity index 100% rename from Benchmarks/Thresholds/main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json rename to Benchmarks/Thresholds/6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json diff --git a/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json new file mode 100644 index 0000000..0b889f2 --- /dev/null +++ b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 565, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json new file mode 100644 index 0000000..24d3a4c --- /dev/null +++ b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 572, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json new file mode 100644 index 0000000..874113d --- /dev/null +++ b/Benchmarks/Thresholds/nightly-6.0/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 967, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json new file mode 100644 index 0000000..0b889f2 --- /dev/null +++ b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_PEM_to_PEMDocument.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 565, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json new file mode 100644 index 0000000..24d3a4c --- /dev/null +++ b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 572, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json new file mode 100644 index 0000000..874113d --- /dev/null +++ b/Benchmarks/Thresholds/nightly-main/SwiftASN1Benchmark.Parse_WebPKI_Roots_from_multi_PEM_to_PEMDocument_.p90.json @@ -0,0 +1,6 @@ +{ + "mallocCountTotal" : 967, + "memoryLeaked" : 0, + "readSyscalls" : 0, + "writeSyscalls" : 0 +} \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e4683a..b7578cd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,29 +60,11 @@ We require that your commit messages match our template. The easiest way to do t git config commit.template dev/git.commit.template -### Run `./scripts/soundness.sh` +### Run CI checks locally -The scripts directory contains a [soundness.sh script](https://github.com/apple/swift-asn1/blob/main/scripts/soundness.sh) -that enforces additional checks, like license headers and formatting style. - -Please make sure to `./scripts/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail -on minor changes such as a missing `self.` or similar formatting issues. - -For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory: - -```bash -cat << EOF > .git/hooks/pre-push - -if [[ -f "scripts/soundness.sh" ]]; then - scripts/soundness.sh -fi -EOF -``` - -Which makes the script execute, and only allow the `git push` to complete if the check has passed. - -In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again. +You can run the Github Actions workflows locally using +[act](https://github.com/nektos/act). For detailed steps on how to do this please see [https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally](https://github.com/swiftlang/github-workflows?tab=readme-ov-file#running-workflows-locally). ## How to contribute your work -Please open a pull request at https://github.com/apple/swift-asn1. Make sure the CI passes, and then wait for code review. +Please open a pull request at [https://github.com/apple/swift-asn1](https://github.com/apple/swift-asn1). Make sure the CI passes, and then wait for code review. diff --git a/Package.swift b/Package.swift index 7860c0e..2f2ef40 100644 --- a/Package.swift +++ b/Package.swift @@ -17,7 +17,7 @@ import PackageDescription import class Foundation.ProcessInfo let upcomingFeatureSwiftSettings: [SwiftSetting] = [ - .enableUpcomingFeature("ExistentialAny"), + .enableUpcomingFeature("ExistentialAny") ] let package = Package( @@ -35,15 +35,6 @@ let package = Package( name: "SwiftASN1Tests", dependencies: ["SwiftASN1"], swiftSettings: upcomingFeatureSwiftSettings - ) + ), ] ) - -// If the `SWIFTCI_USE_LOCAL_DEPS` environment variable is set, -// we're building in the Swift.org CI system alongside other projects in the Swift toolchain and -// we can depend on local versions of our dependencies instead of fetching them remotely. -if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil { - package.dependencies += [ - .package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"), - ] -} diff --git a/Sources/SwiftASN1/ASN1.swift b/Sources/SwiftASN1/ASN1.swift index ed2fce7..e3dcb2f 100644 --- a/Sources/SwiftASN1/ASN1.swift +++ b/Sources/SwiftASN1/ASN1.swift @@ -12,9 +12,8 @@ // //===----------------------------------------------------------------------===// - @available(*, unavailable) -extension ASN1: Sendable { } +extension ASN1: Sendable {} public enum ASN1 {} diff --git a/Sources/SwiftASN1/BER.swift b/Sources/SwiftASN1/BER.swift index f94a72e..47fd519 100644 --- a/Sources/SwiftASN1/BER.swift +++ b/Sources/SwiftASN1/BER.swift @@ -179,7 +179,7 @@ extension BER { /// Constructs an array of `T` elements parsed from the set. /// /// - parameters: - /// - of: An optional parameter to express the type to decode. + /// - type: An optional parameter to express the type to decode. /// - identifier: The ``ASN1Identifier`` that the SET OF is expected to have. /// - rootNode: The ``ASN1Node`` to parse /// - returns: An array of elements representing the elements in the sequence. @@ -511,7 +511,7 @@ public protocol BERParseable: DERParseable { /// expected to initialize themselves if possible, or to throw if they cannot. /// /// - parameters: - /// - berEncoded: The ASN.1 node representing this object. + /// - node: The ASN.1 node representing this object. init(berEncoded node: ASN1Node) throws } @@ -588,7 +588,7 @@ extension BERImplicitlyTaggable { /// to ``BERImplicitlyTaggable/init(berEncoded:withIdentifier:)``. /// /// - parameters: - /// - berEncoded: The sequence of nodes that make up this object's parent. The first node in this collection + /// - sequenceNodeIterator: The sequence of nodes that make up this object's parent. The first node in this collection /// will be used to construct this object. /// - identifier: The ASN.1 identifier that `berEncoded` is expected to have. @inlinable diff --git a/Sources/SwiftASN1/Basic ASN1 Types/TimeUtilities.swift b/Sources/SwiftASN1/Basic ASN1 Types/TimeUtilities.swift index 2a08c23..7e878c2 100644 --- a/Sources/SwiftASN1/Basic ASN1 Types/TimeUtilities.swift +++ b/Sources/SwiftASN1/Basic ASN1 Types/TimeUtilities.swift @@ -12,7 +12,6 @@ // //===----------------------------------------------------------------------===// - @available(*, unavailable) extension TimeUtilities: Sendable {} diff --git a/Sources/SwiftASN1/DER.swift b/Sources/SwiftASN1/DER.swift index fd21053..aa6e69a 100644 --- a/Sources/SwiftASN1/DER.swift +++ b/Sources/SwiftASN1/DER.swift @@ -151,7 +151,7 @@ extension DER { /// Constructs an array of `T` elements parsed from the set. /// /// - parameters: - /// - of: An optional parameter to express the type to decode. + /// - type: An optional parameter to express the type to decode. /// - identifier: The ``ASN1Identifier`` that the SET OF is expected to have. /// - rootNode: The ``ASN1Node`` to parse /// - returns: An array of elements representing the elements in the sequence. @@ -929,7 +929,7 @@ public protocol DERParseable { /// expected to initialize themselves if possible, or to throw if they cannot. /// /// - parameters: - /// - derEncoded: The ASN.1 node representing this object. + /// - node: The ASN.1 node representing this object. init(derEncoded node: ASN1Node) throws } @@ -940,7 +940,7 @@ extension DERParseable { /// to ``DERParseable/init(derEncoded:)-7tumk``. /// /// - parameters: - /// - derEncoded: The sequence of nodes that make up this object's parent. The first node in this collection + /// - sequenceNodeIterator: The sequence of nodes that make up this object's parent. The first node in this collection /// will be used to construct this object. @inlinable public init(derEncoded sequenceNodeIterator: inout ASN1NodeCollection.Iterator) throws { @@ -1022,7 +1022,7 @@ extension DERImplicitlyTaggable { /// to ``DERImplicitlyTaggable/init(derEncoded:withIdentifier:)-7e88k``. /// /// - parameters: - /// - derEncoded: The sequence of nodes that make up this object's parent. The first node in this collection + /// - sequenceNodeIterator: The sequence of nodes that make up this object's parent. The first node in this collection /// will be used to construct this object. /// - identifier: The ASN.1 identifier that `derEncoded` is expected to have. @inlinable diff --git a/dev/update-benchmark-thresholds.sh b/dev/update-benchmark-thresholds.sh index 810c6bf..1711967 100755 --- a/dev/update-benchmark-thresholds.sh +++ b/dev/update-benchmark-thresholds.sh @@ -24,5 +24,5 @@ for f in 57 58 59 510 -nightly; do docker_file=$(if [[ "$f" == "-nightly" ]]; then f=main; fi && ls "$target_repo/docker/docker-compose."*"$f"*".yaml") - docker-compose -f docker/docker-compose.yaml -f $docker_file run update-benchmark-baseline + docker-compose -f docker/docker-compose.yaml -f "$docker_file" run update-benchmark-baseline done diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 8c7ae3c..eb4d554 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -21,11 +21,11 @@ services: soundness: <<: *common - command: /bin/bash -xcl "swift -version && uname -a && ./scripts/soundness.sh" + command: echo "skipping; moved to Github Actions" test: <<: *common - command: /bin/bash -xcl "swift $${SWIFT_TEST_VERB-test} $${WARN_AS_ERROR_ARG-} $${SANITIZER_ARG-} $${IMPORT_CHECK_ARG-} $${EXPLICIT_SENDABLE_ARG-} $${STRICT_CONCURRENCY_ARG} && cd Benchmarks && swift package benchmark baseline check --check-absolute-path Thresholds/$${SWIFT_VERSION-}/" + command: echo "skipping; moved to Github Actions" update-benchmark-baseline: <<: *common diff --git a/scripts/check_no_api_breakages.sh b/scripts/check_no_api_breakages.sh index 0067daf..7b838ce 100755 --- a/scripts/check_no_api_breakages.sh +++ b/scripts/check_no_api_breakages.sh @@ -26,42 +26,4 @@ ## ##===----------------------------------------------------------------------===## -set -eu - -function usage() { - echo >&2 "Usage: $0 REPO-GITHUB-URL NEW-VERSION OLD-VERSIONS..." - echo >&2 - echo >&2 "This script requires a Swift 5.2+ toolchain." - echo >&2 - echo >&2 "Examples:" - echo >&2 - echo >&2 "Check between main and tag 2.1.1 of swift-asn1:" - echo >&2 " $0 https://github.com/apple/swift-asn1 main 2.1.1" - echo >&2 - echo >&2 "Check between HEAD and commit 64cf63d7 using the provided toolchain:" - echo >&2 " xcrun --toolchain org.swift.5120190702a $0 ../some-local-repo HEAD 64cf63d7" -} - -if [[ $# -lt 3 ]]; then - usage - exit 1 -fi - -tmpdir=$(mktemp -d /tmp/.check-api_XXXXXX) -repo_url=$1 -new_tag=$2 -shift 2 - -repodir="$tmpdir/repo" -git clone "$repo_url" "$repodir" -git -C "$repodir" fetch -q origin '+refs/pull/*:refs/remotes/origin/pr/*' -cd "$repodir" -git checkout -q "$new_tag" - -for old_tag in "$@"; do - echo "Checking public API breakages from $old_tag to $new_tag" - - swift package diagnose-api-breaking-changes "$old_tag" -done - -echo done +exit 0 diff --git a/scripts/run-swift-format.sh b/scripts/run-swift-format.sh deleted file mode 100644 index 15425b7..0000000 --- a/scripts/run-swift-format.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftASN1 open source project -## -## Copyright (c) 2022-2023 Apple Inc. and the SwiftASN1 project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftOpenAPIGenerator open source project -## -## Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -set -euo pipefail - -function log() { printf -- "** %s\n" "$*" >&2; } -function error() { printf -- "** ERROR: %s\n" "$*" >&2; } -function fatal() { error "$*"; exit 1; } - -current_script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -repo_root="$(git -C "${current_script_dir}" rev-parse --show-toplevel)" - -swiftformat_bin=${swiftformat_bin:-$(command -v swift-format)} || fatal "❌ swiftformat_bin unset and no swift-format on PATH" - -"${swiftformat_bin}" lint \ - --parallel --recursive --strict \ - "${repo_root}/Sources" "${repo_root}/Tests" "${repo_root}/Benchmarks/Benchmarks" \ - && swift_format_rc=$? || swift_format_rc=$? - -if [[ "${swift_format_rc}" -ne 0 ]]; then - fatal "❌ Running swift-format produced errors. - - To fix, run the following command: - - % swift-format format --parallel --recursive --in-place Sources Tests Benchmarks/Benchmarks - " - exit "${swift_format_rc}" -fi - -log "✅ Ran swift-format with no errors." diff --git a/scripts/soundness.sh b/scripts/soundness.sh deleted file mode 100755 index 81fe1a2..0000000 --- a/scripts/soundness.sh +++ /dev/null @@ -1,208 +0,0 @@ -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftASN1 open source project -## -## Copyright (c) 2022-2023 Apple Inc. and the SwiftASN1 project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftNIO open source project -## -## Copyright (c) 2017-2022 Apple Inc. and the SwiftNIO project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftNIO project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## - -set -eu -here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -function replace_acceptable_years() { - # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/20[12][789012]-20[12][890123]/YEARS/' -e 's/20[12][890123]/YEARS/' -} - -printf "=> Checking for unacceptable language... " -# This greps for unacceptable terminology. The square bracket[s] are so that -# "git grep" doesn't find the lines that greps :). -unacceptable_terms=( - -e blacklis[t] - -e whitelis[t] - -e slav[e] - -e sanit[y] -) - -# We have to exclude the code of conduct as it gives examples of unacceptable -# language. -if git grep --color=never -i "${unacceptable_terms[@]}" -- . ":(exclude)CODE_OF_CONDUCT.md" > /dev/null; then - printf "\033[0;31mUnacceptable language found.\033[0m\n" - git grep -i "${unacceptable_terms[@]}" -- . ":(exclude)CODE_OF_CONDUCT.md" - exit 1 -fi -printf "\033[0;32mokay.\033[0m\n" - -# swift-format -swift_format_script="${here}/run-swift-format.sh" -if ! bash "${swift_format_script}"; then - exit 1 -fi - -printf "=> Detecting changes in source files for CMake build\n" -FIRST_OUT="$(git status --porcelain)" -out=$($here/update_cmakelists.sh 2>&1) -SECOND_OUT="$(git status --porcelain)" -if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mThere are source file changes! Have you added or renamed source files? Or did you forget to run 'update_cmakelists.sh' and commit changes?\033[0m\n" - exit 1 -fi -printf "\033[0;32mokay.\033[0m\n" - -printf "=> Checking license headers\n" -tmp=$(mktemp /tmp/.swift-asn1-soundness_XXXXXX) - -for language in swift-or-c bash dtrace python cmake; do - printf " * $language... " - declare -a matching_files - declare -a exceptions - expections=( ) - matching_files=( -name '*' ) - case "$language" in - swift-or-c) - exceptions=( -name c_nio_llhttp.c -o -name c_nio_api.c -o -name c_nio_http.c -o -name c_nio_llhttp.h -o -name cpp_magic.h -o -name Package.swift -o -name 'Package@*.swift' -o -name CNIOSHA1.h -o -name c_nio_sha1.c -o -name ifaddrs-android.c -o -name ifaddrs-android.h) - matching_files=( -name '*.swift' -o -name '*.c' -o -name '*.h' ) - cat > "$tmp" <<"EOF" -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftASN1 open source project -// -// Copyright (c) YEARS Apple Inc. and the SwiftASN1 project authors -// Licensed under Apache License v2.0 -// -// See LICENSE.txt for license information -// See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -// -// SPDX-License-Identifier: Apache-2.0 -// -//===----------------------------------------------------------------------===// -EOF - ;; - bash) - matching_files=( -name '*.sh' ) - cat > "$tmp" <<"EOF" -#!/bin/bash -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftASN1 open source project -## -## Copyright (c) YEARS Apple Inc. and the SwiftASN1 project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -EOF - ;; - python) - matching_files=( -name '*.py' ) - cat > "$tmp" <<"EOF" -#!/usr/bin/env python3 -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftASN1 open source project -## -## Copyright (c) YEARS Apple Inc. and the SwiftASN1 project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -EOF - ;; - dtrace) - matching_files=( -name '*.d' ) - cat > "$tmp" <<"EOF" -#!/usr/sbin/dtrace -q -s -/*===----------------------------------------------------------------------===* - * - * This source file is part of the SwiftASN1 open source project - * - * Copyright (c) YEARS Apple Inc. and the SwiftASN1 project authors - * Licensed under Apache License v2.0 - * - * See LICENSE.txt for license information - * See CONTRIBUTORS.txt for the list of SwiftASN1 project authors - * - * SPDX-License-Identifier: Apache-2.0 - * - *===----------------------------------------------------------------------===*/ -EOF - ;; - cmake) - matching_files=( -name 'SwiftSupport.cmake' -o -name 'CMakeLists.txt' ) - cat > "$tmp" <<"EOF" -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftASN1 open source project -## -## Copyright (c) YEARS Apple Inc. and the SwiftASN1 project authors -## Licensed under Apache License v2.0 -## -## See LICENSE.txt for license information -## See CONTRIBUTORS.txt for the list of SwiftASN1 project authors -## -## SPDX-License-Identifier: Apache-2.0 -## -##===----------------------------------------------------------------------===## -EOF - ;; - *) - echo >&2 "ERROR: unknown language '$language'" - ;; - esac - - expected_lines=$(cat "$tmp" | wc -l) - expected_sha=$(cat "$tmp" | shasum) - - ( - cd "$here/.." - { - find . \ - \( \! -path './.build/*' -a \ - \( "${matching_files[@]}" \) -a \ - \( \! \( "${exceptions[@]}" \) \) \) - - if [[ "$language" = bash ]]; then - # add everything with a shell shebang too - git grep --full-name -l '#!/bin/bash' - git grep --full-name -l '#!/bin/sh' - fi - } | while read line; do - if [[ "$(cat "$line" | replace_acceptable_years | head -n $expected_lines | shasum)" != "$expected_sha" ]]; then - printf "\033[0;31mmissing headers in file '$line'!\033[0m\n" - diff -u <(cat "$line" | replace_acceptable_years | head -n $expected_lines) "$tmp" - exit 1 - fi - done - printf "\033[0;32mokay.\033[0m\n" - ) -done - -rm "$tmp" diff --git a/scripts/update_cmakelists.sh b/scripts/update_cmakelists.sh index 0120619..4dedeca 100755 --- a/scripts/update_cmakelists.sh +++ b/scripts/update_cmakelists.sh @@ -22,7 +22,7 @@ case "$(uname -s)" in find=gfind # brew install findutils ;; *) - find=find + find='find' ;; esac @@ -32,14 +32,14 @@ function update_cmakelists_source() { # Build an array with the rest of the arguments shift src_exts=("$@") - echo "Finding source files (${src_exts[@]}) under $src_root" + echo "Finding source files (" "${src_exts[@]}" ") under $src_root" num_exts=${#src_exts[@]} # Build file extensions argument for `find` declare -a exts_arg exts_arg+=(-name "${src_exts[0]}") - for (( i=1; i<$num_exts; i++ )); + for (( i=1; i