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
This commit is contained in:
Rick Newton-Rogers authored and GitHub committed 2024-10-15 13:04:58 +01:00
1 parent 7faebca1ea
commit d016643222
23 files changed
+81 -362

No files matched your search

+6 -12
View File
@@ -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
+18
View File
@@ -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
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 565,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 572,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 967,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 565,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 572,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
@@ -0,0 +1,6 @@
{
"mallocCountTotal" : 967,
"memoryLeaked" : 0,
"readSyscalls" : 0,
"writeSyscalls" : 0
}
+4 -22
View File
@@ -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.
+2 -11
View File
@@ -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"),
]
}
+1 -2
View File
@@ -12,9 +12,8 @@
//
//===----------------------------------------------------------------------===//
@available(*, unavailable)
extension ASN1: Sendable { }
extension ASN1: Sendable {}
public enum ASN1 {}
+3 -3
View File
@@ -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
@@ -12,7 +12,6 @@
//
//===----------------------------------------------------------------------===//
@available(*, unavailable)
extension TimeUtilities: Sendable {}
+4 -4
View File
@@ -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
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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
+1 -39
View File
@@ -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
-54
View File
@@ -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."
-208
View File
@@ -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"
+3 -3
View File
@@ -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<num_exts; i++ ));
do
exts_arg+=(-o -name "${src_exts[$i]}")
done