Skip to content

Commit

Permalink
[GHA] Broken symlink and format check
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
FranzBusch committed Jul 12, 2024
1 parent 654bf41 commit 77fb043
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ jobs:
with:
benchmarks_linux_package_path: "Benchmarks"
license_header_check_project_name: "SwiftNIO"
format_check_enabled: false
32 changes: 32 additions & 0 deletions .github/workflows/reusable_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ on:
type: string
description: "Name of the project called out in the license header."
required: true
broken_symlink_check_enabled:
type: boolean
description: "Boolean to enable the broken symlink check job. Defaults to true."
default: true
format_check_enabled:
type: boolean
description: "Boolean to enable the format check job. Defaults to true."
default: true

## We are cancelling previously triggered workflow runs
concurrency:
Expand Down Expand Up @@ -159,3 +167,27 @@ jobs:
env:
PROJECT_NAME: ${{ inputs.license_header_check_project_name }}
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-license-header.sh | bash

broken-symlink-check:
name: Broken symlinks check
if: ${{ inputs.broken_symlink_check_enabled }}
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run broken symlinks check
run: curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/check-broken-symlinks.sh | bash

formatk-check:
name: Format check
if: ${{ inputs.format_check_enabled }}
runs-on: ubuntu-latest
container:
image: swiftlang/swift:nightly-6.0-jammy
timeout-minutes: 5
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run format check
run: swift format format --parallel --recursive --in-place
34 changes: 34 additions & 0 deletions scripts/check-broken-symlinks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/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; }

log "Checking for broken symlinks..."
num_broken_symlinks=0
while read -r -d '' file; do
if ! test -e "./${file}"; then
error "Broken symlink: ${file}"
((num_broken_symlinks++))
fi
done < <(git ls-files -z)

if [ "${num_broken_symlinks}" -gt 0 ]; then
fatal "❌ Found ${num_broken_symlinks} symlinks."
fi

log "✅ Found 0 symlinks."

0 comments on commit 77fb043

Please sign in to comment.