From 107c79c11d9183d48144830702da48ca97f1dfe6 Mon Sep 17 00:00:00 2001 From: Zach Hammer Date: Mon, 12 Feb 2024 13:45:56 -0500 Subject: [PATCH] ci: make sure all checked in files have SeatGeek copyright (#26) * add add-copyrights.sh script * add check copyright header job to build workflow * add nicer title here * remove copyright in file to test workflow * fix filename * only show name of files that need to be updated * tell user to run script if fails * run add copyrights script --- .github/workflows/build.yml | 7 +++++++ scripts/add-copyrights.sh | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 scripts/add-copyrights.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7c3d5a..046b6b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,13 @@ on: branches: - main jobs: + check-copyright-header: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: scripts/add-copyrights.sh + - name: Check for changes + run: git diff --name-only --exit-code || (echo "Run scripts/add-copyrights.sh locally" && exit 1) lint: runs-on: ubuntu-latest strategy: diff --git a/scripts/add-copyrights.sh b/scripts/add-copyrights.sh new file mode 100755 index 0000000..4044bde --- /dev/null +++ b/scripts/add-copyrights.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Define the copyright header +read -r -d '' COPYRIGHT_HEADER << EOM +/* + * Copyright SeatGeek + * Licensed under the terms of the Apache-2.0 license. See LICENSE file in project root for terms. + */ +EOM + +# Loop over .ts and .tsx files in the plugins/ directory +for file in $(find plugins -type f \( -name "*.ts" -o -name "*.tsx" \)); do + # Check if the file is ignored by Git + if ! git check-ignore $file > /dev/null 2>&1; then + # If it's not ignored, check if the copyright header already exists in the file + if ! [[ "$(head -n4 $file)" == *"$COPYRIGHT_HEADER"* ]]; then + echo $file Δ + echo "${COPYRIGHT_HEADER} +$(cat $file)" > $file + fi + fi +done