Skip to content

Commit a1a3d21

Browse files
committed
[GHA] Broken symlink and format check
# Motivation The next two reusable checks that we need to create are for broken symlinks and formatting. The latter is disabled for this repo for now since we need to discuss the formatting rules separately. # Modification This PR adds two new checks - broken symlinks and formatting. # Result Closer to having everything on GitHub actions.
1 parent 654bf41 commit a1a3d21

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ jobs:
1111
with:
1212
benchmarks_linux_package_path: "Benchmarks"
1313
license_header_check_project_name: "SwiftNIO"
14+
format_check_enabled: false

.github/workflows/reusable_pull_request.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ on:
3939
type: string
4040
description: "Name of the project called out in the license header."
4141
required: true
42+
broken_symlink_check_enabled:
43+
type: boolean
44+
description: "Boolean to enable the broken symlink check job. Defaults to true."
45+
default: true
46+
format_check_enabled:
47+
type: boolean
48+
description: "Boolean to enable the format check job. Defaults to true."
49+
default: true
4250

4351
## We are cancelling previously triggered workflow runs
4452
concurrency:
@@ -159,3 +167,27 @@ jobs:
159167
env:
160168
PROJECT_NAME: ${{ inputs.license_header_check_project_name }}
161169
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-license-header.sh | bash
170+
171+
broken-symlink-check:
172+
name: Broken symlinks check
173+
if: ${{ inputs.broken_symlink_check_enabled }}
174+
runs-on: ubuntu-latest
175+
timeout-minutes: 1
176+
steps:
177+
- name: Checkout repository
178+
uses: actions/checkout@v4
179+
- name: Run broken symlinks check
180+
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-broken-symlinks.sh | bash
181+
182+
format-check:
183+
name: Format check
184+
if: ${{ inputs.format_check_enabled }}
185+
runs-on: ubuntu-latest
186+
container:
187+
image: swiftlang/swift:nightly-6.0-jammy
188+
timeout-minutes: 5
189+
steps:
190+
- name: Checkout repository
191+
uses: actions/checkout@v4
192+
- name: Run format check
193+
run: swift format lint --parallel --recursive --strict

scripts/check-broken-symlinks.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftNIO open source project
5+
##
6+
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
set -euo pipefail
16+
17+
log() { printf -- "** %s\n" "$*" >&2; }
18+
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
19+
fatal() { error "$@"; exit 1; }
20+
21+
log "Checking for broken symlinks..."
22+
num_broken_symlinks=0
23+
while read -r -d '' file; do
24+
if ! test -e "./${file}"; then
25+
error "Broken symlink: ${file}"
26+
((num_broken_symlinks++))
27+
fi
28+
done < <(git ls-files -z)
29+
30+
if [ "${num_broken_symlinks}" -gt 0 ]; then
31+
fatal "❌ Found ${num_broken_symlinks} symlinks."
32+
fi
33+
34+
log "✅ Found 0 symlinks."

0 commit comments

Comments
 (0)