From 702f8e562fb831bf4c91bc0208b0ac9260961ab7 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Thu, 18 Feb 2021 21:43:56 -0500 Subject: [PATCH] Update formatting script and use GitHub Actions --- .gitattributes | 2 ++ .github/dependabot.yml | 6 ++++++ .github/workflows/static_checks.yml | 19 +++++++++++++++++++ appveyor.yml | 13 ------------- format.sh => file_format.sh | 26 ++++++++++++++++---------- 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/static_checks.yml rename format.sh => file_format.sh (60%) diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..8ad74f78 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Normalize EOL for all files that Git considers text files. +* text=auto eol=lf diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..12301490 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/static_checks.yml b/.github/workflows/static_checks.yml new file mode 100644 index 00000000..ba5a24b2 --- /dev/null +++ b/.github/workflows/static_checks.yml @@ -0,0 +1,19 @@ +name: 📊 Static Checks +on: [push, pull_request] + +jobs: + format: + name: File formatting (file_format.sh) + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -qq dos2unix recode + + - name: File formatting checks (file_format.sh) + run: | + bash ./file_format.sh diff --git a/appveyor.yml b/appveyor.yml index d790c2e5..c12d6645 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -10,13 +10,6 @@ configuration: Release environment: APPVEYOR_YML_DISABLE_PS_LINUX: true -install: -- sh: | - if [ "$(uname)" != "Darwin" ]; then - sudo apt-get update -y - sudo apt-get install -y dos2unix recode - fi - build_script: - ps: | New-Item -Path . -Name "build" -ItemType "directory" @@ -33,12 +26,6 @@ build_script: cmake --build . --config ${CONFIGURATION} cd ../ -test_script: - - sh: | - if [ "$(uname)" != "Darwin" ]; then - bash ./format.sh - fi - artifacts: # Linux - path: bin/basisu diff --git a/format.sh b/file_format.sh similarity index 60% rename from format.sh rename to file_format.sh index 5d90393a..873b2951 100755 --- a/format.sh +++ b/file_format.sh @@ -1,4 +1,9 @@ -#!/bin/bash +#!/usr/bin/env bash + +# This script ensures proper POSIX text file formatting and a few other things. + +set -uo pipefail +IFS=$'\n\t' # Loops through all text files tracked by Git. git grep -zIl '' | @@ -15,18 +20,19 @@ while IFS= read -rd '' f; do elif [[ $f == *"min.js" ]]; then continue fi - # Ensures that files are UTF-8 formatted. - recode UTF-8 $f 2> /dev/null - # Ensures that files have LF line endings. - dos2unix $f 2> /dev/null - # Ensures that files do not contain a BOM. - sed -i '1s/^\xEF\xBB\xBF//' "$f" - # Ensures that files end with newline characters. - tail -c1 < "$f" | read -r _ || echo >> "$f"; + # Ensure that files are UTF-8 formatted. + recode UTF-8 "$f" 2> /dev/null + # Ensure that files have LF line endings and do not contain a BOM. + dos2unix "$f" 2> /dev/null + # Remove trailing space characters and ensures that files end + # with newline characters. -l option handles newlines conveniently. + perl -i -ple 's/\s*$//g' "$f" + # Remove the character sequence "== true" if it has a leading space. + perl -i -pe 's/\x20== true//g' "$f" done git diff > patch.patch -FILESIZE=$(stat -c%s patch.patch) +FILESIZE="$(stat -c%s patch.patch)" MAXSIZE=5 # If no patch has been generated all is OK, clean up, and exit.