Skip to content

Commit 8178f92

Browse files
committed
Soundness workflow
This includes multiple checks: * API breakage check * Documentation check * Unacceptable language check * License headers check * Broken symlinks check * Format check * Shell check This was copied from the swift-nio repository to help centralize the workflows.
1 parent fa04e06 commit 8178f92

File tree

6 files changed

+401
-0
lines changed

6 files changed

+401
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# ===----------------------------------------------------------------------===//
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
#
12+
# ===----------------------------------------------------------------------===//
13+
14+
set -euo pipefail
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
log "Checking for broken symlinks..."
21+
num_broken_symlinks=0
22+
while read -r -d '' file; do
23+
if ! test -e "./${file}"; then
24+
error "Broken symlink: ${file}"
25+
((num_broken_symlinks++))
26+
fi
27+
done < <(git ls-files -z)
28+
29+
if [ "${num_broken_symlinks}" -gt 0 ]; then
30+
fatal "❌ Found ${num_broken_symlinks} symlinks."
31+
fi
32+
33+
log "✅ Found 0 symlinks."
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
# ===----------------------------------------------------------------------===//
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
#
12+
# ===----------------------------------------------------------------------===//
13+
14+
set -euo pipefail
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
log "Editing Package.swift..."
21+
cat <<EOF >> "Package.swift"
22+
package.dependencies.append(
23+
.package(url: "https://github.com/apple/swift-docc-plugin", "1.0.0"..<"1.4.0")
24+
)
25+
EOF
26+
27+
log "Checking documentation targets..."
28+
for target in $(yq -r '.builder.configs[].documentation_targets[]' .spi.yml); do
29+
log "Checking target $target..."
30+
swift package plugin generate-documentation --target "$target" --warnings-as-errors --analyze --level detailed
31+
done
32+
33+
log "✅ Found no documentation issues."
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# ===----------------------------------------------------------------------===//
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
#
12+
# ===----------------------------------------------------------------------===//
13+
14+
set -euo pipefail
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
test -n "${PROJECT_NAME:-}" || fatal "PROJECT_NAME unset"
21+
22+
expected_file_header_template="@@===----------------------------------------------------------------------===@@
23+
@@
24+
@@ This source file is part of the ${PROJECT_NAME} open source project
25+
@@
26+
@@ Copyright (c) YEARS Apple Inc. and the ${PROJECT_NAME} project authors
27+
@@ Licensed under Apache License v2.0
28+
@@
29+
@@ See LICENSE.txt for license information
30+
@@ See CONTRIBUTORS.txt for the list of ${PROJECT_NAME} project authors
31+
@@
32+
@@ SPDX-License-Identifier: Apache-2.0
33+
@@
34+
@@===----------------------------------------------------------------------===@@"
35+
36+
paths_with_missing_license=( )
37+
38+
file_paths=$(tr '\n' '\0' < .licenseignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files)
39+
40+
while IFS= read -r file_path; do
41+
file_basename=$(basename -- "${file_path}")
42+
file_extension="${file_basename##*.}"
43+
44+
# shellcheck disable=SC2001 # We prefer to use sed here instead of bash search/replace
45+
case "${file_extension}" in
46+
swift) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
47+
h) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
48+
c) expected_file_header=$(sed -e 's|@@|//|g' <<<"${expected_file_header_template}") ;;
49+
sh) expected_file_header=$(cat <(echo '#!/bin/bash') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
50+
py) expected_file_header=$(cat <(echo '#!/usr/bin/env python3') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
51+
rb) expected_file_header=$(cat <(echo '#!/usr/bin/env ruby') <(sed -e 's|@@|##|g' <<<"${expected_file_header_template}")) ;;
52+
in) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;;
53+
cmake) expected_file_header=$(sed -e 's|@@|##|g' <<<"${expected_file_header_template}") ;;
54+
*) fatal "Unsupported file extension for file (exclude or update this script): ${file_path}" ;;
55+
esac
56+
expected_file_header_linecount=$(wc -l <<<"${expected_file_header}")
57+
58+
file_header=$(head -n "${expected_file_header_linecount}" "${file_path}")
59+
normalized_file_header=$(
60+
echo "${file_header}" \
61+
| sed -e 's/20[12][0123456789]-20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/' \
62+
)
63+
64+
if ! diff -u \
65+
--label "Expected header" <(echo "${expected_file_header}") \
66+
--label "${file_path}" <(echo "${normalized_file_header}")
67+
then
68+
paths_with_missing_license+=("${file_path} ")
69+
fi
70+
done <<< "$file_paths"
71+
72+
if [ "${#paths_with_missing_license[@]}" -gt 0 ]; then
73+
fatal "❌ Found missing license header in files: ${paths_with_missing_license[*]}."
74+
fi
75+
76+
log "✅ Found no files with missing license header."
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# ===----------------------------------------------------------------------===//
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
#
12+
# ===----------------------------------------------------------------------===//
13+
14+
set -euo pipefail
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
21+
if [[ -f .swiftformatignore ]]; then
22+
log "Found swiftformatignore file..."
23+
24+
log "Running swift format format..."
25+
tr '\n' '\0' < .swiftformatignore| xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
26+
27+
log "Running swift format lint..."
28+
29+
tr '\n' '\0' < .swiftformatignore | xargs -0 -I% printf '":(exclude)%" '| xargs git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
30+
else
31+
log "Running swift format format..."
32+
git ls-files -z '*.swift' | xargs -0 swift format format --parallel --in-place
33+
34+
log "Running swift format lint..."
35+
36+
git ls-files -z '*.swift' | xargs -0 swift format lint --strict --parallel
37+
fi
38+
39+
40+
41+
log "Checking for modified files..."
42+
43+
GIT_PAGER='' git diff --exit-code '*.swift'
44+
45+
log "✅ Found no formatting issues."
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
# ===----------------------------------------------------------------------===//
3+
#
4+
# This source file is part of the Swift.org open source project
5+
#
6+
# Copyright (c) 2024 Apple Inc. and the Swift project authors
7+
# Licensed under Apache License v2.0 with Runtime Library Exception
8+
#
9+
# See https://swift.org/LICENSE.txt for license information
10+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
11+
#
12+
# ===----------------------------------------------------------------------===//
13+
14+
set -euo pipefail
15+
16+
log() { printf -- "** %s\n" "$*" >&2; }
17+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
18+
fatal() { error "$@"; exit 1; }
19+
20+
test -n "${UNACCEPTABLE_WORD_LIST:-}" || fatal "UNACCEPTABLE_WORD_LIST unset"
21+
22+
log "Checking for unacceptable language..."
23+
unacceptable_language_lines=$(git grep \
24+
-i -I -w \
25+
-H -n --column \
26+
-E "${UNACCEPTABLE_WORD_LIST// /|}" | grep -v "ignore-unacceptable-language"
27+
) || true | /usr/bin/paste -s -d " " -
28+
29+
if [ -n "${unacceptable_language_lines}" ]; then
30+
fatal " ❌ Found unacceptable language:
31+
${unacceptable_language_lines}
32+
"
33+
fi
34+
35+
log "✅ Found no unacceptable language."

0 commit comments

Comments
 (0)