Skip to content

Commit

Permalink
[GHA] Unacceptable language check (#2766)
Browse files Browse the repository at this point in the history
* [GHA] Unacceptable language check

# Motivation

Next up replacing part of our soundness script that checked for unacceptable language.

# Modification

This PR adds a new GH action that checks for unacceptable language.

# Result

One more script replaced

* PR review

* Change homepage link to repo
FranzBusch authored Jul 9, 2024
1 parent e947421 commit 5cc0549
Showing 22 changed files with 101 additions and 52 deletions.
35 changes: 28 additions & 7 deletions .github/workflows/reusable_pull_request.yml
Original file line number Diff line number Diff line change
@@ -3,18 +3,26 @@ name: Pull Request
on:
workflow_call:
inputs:
enable_unit_tests:
unit_tests_enabled:
type: boolean
description: "Boolean to enable the unit tests job. Defaults to true."
default: true
enable_api_breakage_check:
api_breakage_check_enabled:
type: boolean
description: "Boolean to enable the API breakage check job. Defaults to true."
default: true
enable_docs_check:
docs_check_enabled:
type: boolean
description: "Boolean to enable the docs check job. Defaults to true."
default: true
unacceptable_language_check_enabled:
type: boolean
description: "Boolean to enable the acceptable language check job. Defaults to true."
default: true
unacceptable_language_check_word_list:
type: string
description: "List of unacceptable words. Defaults to a sensible list of words."
default: "blacklist whitelist slave master sane sanity insane insanity kill killed killing hang hung hanged hanging" #ignore-unacceptable-language

## We are cancelling previously triggered workflow runs
concurrency:
@@ -24,7 +32,7 @@ concurrency:
jobs:
unit-tests:
name: Unit tests
if: ${{ inputs.enable_unit_tests }}
if: ${{ inputs.unit_tests_enabled }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
@@ -46,7 +54,7 @@ jobs:

api-breakage-check:
name: API breakage check
if: ${{ inputs.enable_api_breakage_check }}
if: ${{ inputs.api_breakage_check_enabled }}
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
@@ -65,7 +73,7 @@ jobs:

docs-check:
name: Documentation check
if: ${{ inputs.enable_docs_check }}
if: ${{ inputs.docs_check_enabled }}
runs-on: ubuntu-latest
container:
image: swift:5.10-noble
@@ -83,4 +91,17 @@ jobs:
for target in "${targets[@]}"; do
swift package plugin generate-documentation --target "$target" --warnings-as-errors --analyze --level detailed
done
done
unacceptable-language-check:
name: Unacceptable language check
if: ${{ inputs.unacceptable_language_check_enabled }}
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run unacceptable language check
env:
UNACCEPTABLE_WORD_LIST: ${{ inputs.unacceptable_language_check_word_list}}
run: ./scripts/unacceptable_language_check.sh
4 changes: 2 additions & 2 deletions IntegrationTests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -143,9 +143,9 @@ fi

# report
if [[ $cnt_fail > 0 ]]; then
# kill leftovers (the whole process group)
# terminate leftovers (the whole process group)
trap '' TERM
kill 0
kill 0 # ignore-unacceptable-language

plugins_do summary_fail "$cnt_ok" "$cnt_fail"
else
11 changes: 6 additions & 5 deletions IntegrationTests/tests_01_http/defines.sh
Original file line number Diff line number Diff line change
@@ -141,17 +141,18 @@ function stop_server() {
do_netstat "$token_type"
assert_number_of_open_fds_for_pid_equals "$token_pid" "$token_open_fds"
fi
kill -0 "$token_pid" # assert server is still running
###kill -INT "$token_pid" # tell server to shut down gracefully
kill "$token_pid" # tell server to shut down gracefully
# assert server is still running
kill -0 "$token_pid" # ignore-unacceptable-language
# tell server to shut down gracefully
kill "$token_pid" # ignore-unacceptable-language
for f in $(seq 20); do
if ! kill -0 "$token_pid" 2> /dev/null; then
if ! kill -0 "$token_pid" 2> /dev/null; then # ignore-unacceptable-language
break # good, dead
fi
ps auxw | grep "$token_pid" || true
sleep 0.1
done
if kill -0 "$token_pid" 2> /dev/null; then
if kill -0 "$token_pid" 2> /dev/null; then # ignore-unacceptable-language
fail "server $token_pid still running"
fi
}
10 changes: 5 additions & 5 deletions IntegrationTests/tests_01_http/test_08_survive_signals.sh
Original file line number Diff line number Diff line change
@@ -23,15 +23,15 @@ echo FOO BAR > "$htdocs/some_file.txt"

for f in $(seq 20); do
# send some signals that are usually discarded
kill -CHLD "$server_pid"
kill -URG "$server_pid"
kill -CONT "$server_pid"
kill -WINCH "$server_pid"
kill -CHLD "$server_pid" # ignore-unacceptable-language
kill -URG "$server_pid" # ignore-unacceptable-language
kill -CONT "$server_pid" # ignore-unacceptable-language
kill -WINCH "$server_pid" # ignore-unacceptable-language

do_curl "$token" "http://foobar.com/fileio/some_file.txt" > "$tmp/out.txt" &
curl_pid=$!
for g in $(seq 20); do
kill -URG "$server_pid"
kill -URG "$server_pid" # ignore-unacceptable-language
done
wait $curl_pid
cmp "$htdocs/some_file.txt" "$tmp/out.txt"
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ htdocs=$(get_htdocs "$token")
server_pid=$(get_server_pid "$token")
socket=$(get_socket "$token")

kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language
(
echo -e 'POST /dynamic/echo HTTP/1.1\r\nContent-Length: 400000\r\n\r\nsome_bytes'
for f in $(seq 5); do
@@ -30,5 +30,5 @@ kill -0 $server_pid
done
) | do_nc -U "$socket"
sleep 0.1
kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language
stop_server "$token"
2 changes: 1 addition & 1 deletion IntegrationTests/tests_01_http/test_13_http_pipelining.sh
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ htdocs=$(get_htdocs "$token")
server_pid=$(get_server_pid "$token")
socket=$(get_socket "$token")

kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language

echo -e 'GET /dynamic/count-to-ten HTTP/1.1\r\n\r\nGET /dynamic/count-to-ten HTTP/1.1\r\n\r\n' | \
do_nc -U "$socket" > "$tmp/actual"
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ htdocs=$(get_htdocs "$token")
server_pid=$(get_server_pid "$token")
socket=$(get_socket "$token")

kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language

echo -e 'GET /dynamic/count-to-ten HTTP/1.1\r\nConnection: close\r\n\r\n' | \
do_nc -U "$socket" > "$tmp/actual"
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ start_server --disable-half-closure "$token"
server_pid=$(get_server_pid "$token")
socket=$(get_socket "$token")

kill -0 "$server_pid"
kill -0 "$server_pid" # ignore-unacceptable-language
echo -e 'GET /dynamic/write-delay/10000 HTTP/1.1\r\n\r\n' | do_nc -w1 -U "$socket"
sleep 0.2

Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ server_pid=$(get_server_pid "$token")
ip=$(get_server_ip "$token")
port=$(get_server_port "$token")

kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language
echo -e 'GET /dynamic/write-delay/10000 HTTP/1.1\r\n\r\n' | do_nc -w1 "$ip" "$port"
sleep 0.2
stop_server "$token"
Original file line number Diff line number Diff line change
@@ -22,11 +22,11 @@ server_pid=$(get_server_pid "$token")
ip=$(get_server_ip "$token")
port=$(get_server_port "$token")

kill -0 $server_pid
kill -0 $server_pid # ignore-unacceptable-language
# try to simulate a TCP connection reset, works really well on Darwin but not on
# Linux over loopback. On Linux however
# `test_19_connection_drop_while_waiting_for_response_uds.sh` tests a very
# similar situation.
yes "$( echo -e 'GET /dynamic/write-delay HTTP/1.1\r\n\r\n')" | nc "$ip" "$port" > /dev/null & sleep 0.5; kill -9 $!
yes "$( echo -e 'GET /dynamic/write-delay HTTP/1.1\r\n\r\n')" | nc "$ip" "$port" > /dev/null & sleep 0.5; kill -9 $! # ignore-unacceptable-language
sleep 0.2
stop_server "$token"
18 changes: 4 additions & 14 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -35,20 +35,10 @@ This product is heavily influenced by Netty.

---

This product contains a derivation of the Tony Stone's 'process_test_files.rb'.

* LICENSE (Apache License 2.0):
* https://www.apache.org/licenses/LICENSE-2.0
* HOMEPAGE:
* https://github.com/tonystone/build-tools/commit/6c417b7569df24597a48a9aa7b505b636e8f73a1
* https://github.com/tonystone/build-tools/blob/master/source/xctest_tool.rb

---

This product contains NodeJS's llhttp.

* LICENSE (MIT):
* https://github.com/nodejs/llhttp/blob/master/LICENSE-MIT
* https://github.com/nodejs/llhttp/blob/1e1c5b43326494e97cf8244ff57475eb72a1b62c/LICENSE-MIT
* HOMEPAGE:
* https://github.com/nodejs/llhttp

@@ -57,7 +47,7 @@ This product contains NodeJS's llhttp.
This product contains "cpp_magic.h" from Thomas Nixon & Jonathan Heathcote's uSHET

* LICENSE (MIT):
* https://github.com/18sg/uSHET/blob/master/LICENSE
* https://github.com/18sg/uSHET/blob/c09e0acafd86720efe42dc15c63e0cc228244c32/lib/cpp_magic.h
* HOMEPAGE:
* https://github.com/18sg/uSHET

@@ -68,14 +58,14 @@ This product contains "sha1.c" and "sha1.h" from FreeBSD (Copyright (C) 1995, 19
* LICENSE (BSD-3):
* https://opensource.org/licenses/BSD-3-Clause
* HOMEPAGE:
* https://github.com/freebsd/freebsd/tree/master/sys/crypto
* https://github.com/freebsd/freebsd-src

---

This product contains a derivation of Fabian Fett's 'Base64.swift'.

* LICENSE (Apache License 2.0):
* https://github.com/fabianfett/swift-base64-kit/blob/master/LICENSE
* https://github.com/swift-extras/swift-extras-base64/blob/b8af49699d59ad065b801715a5009619100245ca/LICENSE
* HOMEPAGE:
* https://github.com/fabianfett/swift-base64-kit

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@ One major difference between writing concurrent code and writing synchronous cod

An [`EventLoopFuture<T>`][elf] is essentially a container for the return value of a function that will be populated *at some time in the future*. Each [`EventLoopFuture<T>`][elf] has a corresponding [`EventLoopPromise<T>`][elp], which is the object that the result will be put into. When the promise is succeeded, the future will be fulfilled.

If you had to poll the future to detect when it completed that would be quite inefficient, so [`EventLoopFuture<T>`][elf] is designed to have managed callbacks. Essentially, you can hang callbacks off the future that will be executed when a result is available. The [`EventLoopFuture<T>`][elf] will even carefully arrange the scheduling to ensure that these callbacks always execute on the event loop that initially created the promise, which helps ensure that you don't need too much synchronization around [`EventLoopFuture<T>`][elf] callbacks.
If you had to poll the future to detect when it completed that would be quite inefficient, so [`EventLoopFuture<T>`][elf] is designed to have managed callbacks. Essentially, you can chain callbacks off the future that will be executed when a result is available. The [`EventLoopFuture<T>`][elf] will even carefully arrange the scheduling to ensure that these callbacks always execute on the event loop that initially created the promise, which helps ensure that you don't need too much synchronization around [`EventLoopFuture<T>`][elf] callbacks.

Another important topic for consideration is the difference between how the promise passed to `close` works as opposed to `closeFuture` on a [`Channel`][c]. For example, the promise passed into `close` will succeed after the [`Channel`][c] is closed down but before the [`ChannelPipeline`][cp] is completely cleared out. This will allow you to take action on the [`ChannelPipeline`][cp] before it is completely cleared out, if needed. If it is desired to wait for the [`Channel`][c] to close down and the [`ChannelPipeline`][cp] to be cleared out without any further action, then the better option would be to wait for the `closeFuture` to succeed.

2 changes: 1 addition & 1 deletion Sources/CNIOAtomics/src/cpp_magic.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// this is https://github.com/18sg/uSHET/blob/master/lib/cpp_magic.h
// this is https://github.com/18sg/uSHET/blob/c09e0acafd86720efe42dc15c63e0cc228244c32/lib/cpp_magic.h
// LICENSE: MIT
//
//
2 changes: 1 addition & 1 deletion Sources/CNIOLinux/shim.c
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ int CNIOLinux_pthread_setname_np(pthread_t thread, const char *name) {

int CNIOLinux_pthread_getname_np(pthread_t thread, char *name, size_t len) {
#ifdef __ANDROID__
// https://android.googlesource.com/platform/bionic/+/master/libc/bionic/pthread_setname_np.cpp#51
// https://android.googlesource.com/platform/bionic/+/8a18af52d9b9344497758ed04907a314a083b204/libc/bionic/pthread_setname_np.cpp#51
if (thread == pthread_self()) {
return TEMP_FAILURE_RETRY(prctl(PR_GET_NAME, name)) == -1 ? -1 : 0;
}
2 changes: 1 addition & 1 deletion Sources/CNIOSHA1/update_and_patch_sha1.sh
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ for f in sha1.c sha1.h; do
echo " - use welcoming language (soundness check)"
echo " - ensure BYTE_ORDER is defined"
echo "*/"
curl -Ls "https://raw.githubusercontent.com/freebsd/freebsd/master/sys/crypto/$f"
curl -Ls "https://raw.githubusercontent.com/freebsd/freebsd/master/sys/crypto/$f" # ignore-unacceptable-language
) > "$here/c_nio_$f"

for func in sha1_init sha1_pad sha1_loop sha1_result; do
2 changes: 1 addition & 1 deletion Sources/NIO/Docs.docc/index.md
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ One major difference between writing concurrent code and writing synchronous cod

An [`EventLoopFuture<T>`][elf] is essentially a container for the return value of a function that will be populated *at some time in the future*. Each [`EventLoopFuture<T>`][elf] has a corresponding [`EventLoopPromise<T>`][elp], which is the object that the result will be put into. When the promise is succeeded, the future will be fulfilled.

If you had to poll the future to detect when it completed that would be quite inefficient, so [`EventLoopFuture<T>`][elf] is designed to have managed callbacks. Essentially, you can hang callbacks off the future that will be executed when a result is available. The [`EventLoopFuture<T>`][elf] will even carefully arrange the scheduling to ensure that these callbacks always execute on the event loop that initially created the promise, which helps ensure that you don't need too much synchronization around [`EventLoopFuture<T>`][elf] callbacks.
If you had to poll the future to detect when it completed that would be quite inefficient, so [`EventLoopFuture<T>`][elf] is designed to have managed callbacks. Essentially, you can chain callbacks off the future that will be executed when a result is available. The [`EventLoopFuture<T>`][elf] will even carefully arrange the scheduling to ensure that these callbacks always execute on the event loop that initially created the promise, which helps ensure that you don't need too much synchronization around [`EventLoopFuture<T>`][elf] callbacks.

Another important topic for consideration is the difference between how the promise passed to `close` works as opposed to `closeFuture` on a [`Channel`][c]. For example, the promise passed into `close` will succeed after the [`Channel`][c] is closed down but before the [`ChannelPipeline`][cp] is completely cleared out. This will allow you to take action on the [`ChannelPipeline`][cp] before it is completely cleared out, if needed. If it is desired to wait for the [`Channel`][c] to close down and the [`ChannelPipeline`][cp] to be cleared out without any further action, then the better option would be to wait for the `closeFuture` to succeed.

2 changes: 1 addition & 1 deletion Sources/NIOCore/SystemCallHelpers.swift
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ enum SystemCalls {
let err = errno
#endif

// There is really nothing "sane" we can do when EINTR was reported on close.
// There is really nothing "good" we can do when EINTR was reported on close.
// So just ignore it and "assume" everything is fine == we closed the file descriptor.
//
// For more details see:
2 changes: 1 addition & 1 deletion Sources/NIOPosix/System.swift
Original file line number Diff line number Diff line change
@@ -463,7 +463,7 @@ internal enum Posix {
let err = errno
#endif

// There is really nothing "sane" we can do when EINTR was reported on close.
// There is really nothing "good" we can do when EINTR was reported on close.
// So just ignore it and "assume" everything is fine == we closed the file descriptor.
//
// For more details see:
2 changes: 1 addition & 1 deletion Tests/NIOPosixTests/ChannelTests.swift
Original file line number Diff line number Diff line change
@@ -2991,7 +2991,7 @@ final class ReentrantWritabilityChangingHandler: ChannelInboundHandler {

func channelActive(context: ChannelHandlerContext) {
// We want to enqueue at least two pending writes before flushing. Neither of which
// should cause writability to change. However, we'll hang a callback off the first
// should cause writability to change. However, we'll chain a callback off the first
// write which will make the channel unwritable and a writability change to be
// emitted. The flush for that write should result in the writability flipping back
// again.
2 changes: 1 addition & 1 deletion scripts/nio-diagnose
Original file line number Diff line number Diff line change
@@ -355,7 +355,7 @@ function analyse_process() {
output "## Analysing pid $pid"
output

if ! kill -0 "$pid" 2> /dev/null; then
if ! kill -0 "$pid" 2> /dev/null; then # ignore-unacceptable-language
output "pid $pid is dead, skipping"
return 0
fi
4 changes: 2 additions & 2 deletions scripts/soundness.sh
Original file line number Diff line number Diff line change
@@ -33,9 +33,9 @@ unacceptable_terms=(

# 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
if git grep --color=never -i "${unacceptable_terms[@]}" -- . ":(exclude).github/workflows/reusable_pull_request.yml" > /dev/null; then
printf "\033[0;31mUnacceptable language found.\033[0m\n"
git grep -i "${unacceptable_terms[@]}" -- . ":(exclude)CODE_OF_CONDUCT.md"
git grep -i "${unacceptable_terms[@]}" -- . ":(exclude).github/workflows/reusable_pull_request.yml"
exit 1
fi
printf "\033[0;32mokay.\033[0m\n"
37 changes: 37 additions & 0 deletions scripts/unacceptable_language_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2024 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 -euo pipefail

log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }

test -n "${UNACCEPTABLE_WORD_LIST:-}" || fatal "UNACCEPTABLE_WORD_LIST unset"

log "Checking for unacceptable language..."
unacceptable_language_lines=$(git grep \
-i -I -w \
-H -n --column \
-E "${UNACCEPTABLE_WORD_LIST// /|}" | grep -v "ignore-unacceptable-language"
) || true | /usr/bin/paste -s -d " " -

if [ -n "${unacceptable_language_lines}" ]; then
fatal " ❌ Found unacceptable language:
${unacceptable_language_lines}
"
fi

log "✅ Found no unacceptable language."

0 comments on commit 5cc0549

Please sign in to comment.