From 77fb0434e79eeb8b7d2667e53ff2dc6e364480a3 Mon Sep 17 00:00:00 2001 From: Franz Busch Date: Fri, 12 Jul 2024 12:23:55 +0200 Subject: [PATCH] [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. --- .github/workflows/pull_request.yml | 1 + .github/workflows/reusable_pull_request.yml | 32 +++++++++++++++++++ scripts/check-broken-symlinks.sh | 34 +++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100755 scripts/check-broken-symlinks.sh diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6d19bb7b49..23c4ce3b64 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -11,3 +11,4 @@ jobs: with: benchmarks_linux_package_path: "Benchmarks" license_header_check_project_name: "SwiftNIO" + format_check_enabled: false diff --git a/.github/workflows/reusable_pull_request.yml b/.github/workflows/reusable_pull_request.yml index b34e0c6c77..b3a1d71844 100644 --- a/.github/workflows/reusable_pull_request.yml +++ b/.github/workflows/reusable_pull_request.yml @@ -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: @@ -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 diff --git a/scripts/check-broken-symlinks.sh b/scripts/check-broken-symlinks.sh new file mode 100755 index 0000000000..0c65d99df2 --- /dev/null +++ b/scripts/check-broken-symlinks.sh @@ -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."