Skip to content

Commit

Permalink
[#135] CI: add stylish-haskell and shellcheck
Browse files Browse the repository at this point in the history
Problem: We should add stylish-haskell and shellcheck to our pipline.

Solution: Add stylish-haskell and shellcheck. Use stylish-haskell on repo.
  • Loading branch information
Sereja313 committed Sep 14, 2022
1 parent aa18a05 commit 9ed9c54
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 25 deletions.
6 changes: 6 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ steps:
- command: nix-build ci.nix -A trailing-whitespace-check
label: Check trailing whitespaces

- label: shellcheck
command: nix run -f ci.nix pkgs.shellcheck -c find . -name '*.sh' -exec shellcheck {} +

- label: stylish
command: nix run -f ci.nix pkgs.gnumake pkgs-stylish.stylish-haskell -c ./scripts/validate-stylish.sh

- command: nix-build ci.nix -A xrefcheck-lib-and-tests
label: Library and tests

Expand Down
1 change: 0 additions & 1 deletion .stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ language_extensions:
- MultiParamTypeClasses
- MultiWayIf
- NamedFieldPuns
- NoImplicitPrelude
- NumericUnderscores
- OverloadedLabels
- OverloadedStrings
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: MPL-2.0

.PHONY: xrefcheck test lint clean bats all
.PHONY: xrefcheck test lint stylish clean bats all

# Build target from the common utility Makefile
MAKEU = $(MAKE) -C make/
Expand Down Expand Up @@ -30,6 +30,9 @@ clean:
lint:
hlint .

stylish:
find . -name '.stack-work' -prune -o -name '.dist-newstyle' -prune -o -name '*.hs' -exec stylish-haskell -i '{}' \;

####################################
# Individual test suites

Expand Down
3 changes: 3 additions & 0 deletions ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ rec {
};
};

# TODO: drop this when `serokell/nixpkgs` acquires stylish-haskell >= 0.13.0.0.
pkgs-stylish = import sources.nixpkgs-stylish {};

xrefcheck-lib-and-tests = (import ./xrefcheck.nix { linux = true; });
xrefcheck-static = (import ./xrefcheck.nix { linux-static = true; }).components.exes.xrefcheck;
xrefcheck-windows = (import ./xrefcheck.nix { windows = true; }).components.exes.xrefcheck;
Expand Down
12 changes: 12 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
"url": "https://github.com/serokell/nixpkgs/archive/1714a2ead1a18678afa3cbf75dff3f024c579061.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"nixpkgs-stylish": {
"branch": "master",
"description": "Nix Packages collection",
"homepage": "",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "19574af0af3ffaf7c9e359744ed32556f34536bd",
"sha256": "0v3c4r8v40jimicdxqvxnzmdypnafm2baam7z131zk6ljhb8jpg9",
"type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/19574af0af3ffaf7c9e359744ed32556f34536bd.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
},
"serokell.nix": {
"branch": "master",
"description": "Serokell Nix infrastructure library",
Expand Down
30 changes: 30 additions & 0 deletions scripts/validate-stylish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io>
#
# SPDX-License-Identifier: MPL-2.0

# This script verifies that the repo adheres to the stylish-haskell rules.
#
# It does this by running `make stylish` on the repo and checking
# that no files were affected.

set -euo pipefail

make stylish

# Note: we temporarily disable `-e`;
# otherwise the script would exit when `git diff` returns 1.
set +e
diff=$(git diff --exit-code --name-only)
exitCode=$?
set -e

if [ "$exitCode" != 0 ]; then
echo "Found files that do not adhere to stylish-haskell."
echo "Run 'make stylish' on the repository to fix this."
echo ""
echo "Offending files:"
echo "$diff"
exit 1
fi
2 changes: 1 addition & 1 deletion src/Xrefcheck/CLI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import Paths_xrefcheck (version)
import Xrefcheck.Config (VerifyConfig (..))
import Xrefcheck.Core
import Xrefcheck.Scan
import Xrefcheck.Util (normaliseWithNoTrailing)
import Xrefcheck.System (RelGlobPattern (..))
import Xrefcheck.Util (normaliseWithNoTrailing)

modeReadM :: ReadM VerifyMode
modeReadM = eitherReader $ \s ->
Expand Down
8 changes: 4 additions & 4 deletions src/Xrefcheck/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

module Xrefcheck.Config where

import qualified Universum.Unsafe as Unsafe
import Universum.Unsafe qualified as Unsafe

import Universum

Expand All @@ -22,15 +22,15 @@ import Text.Regex.TDFA qualified as R
import Text.Regex.TDFA.ByteString ()
import Text.Regex.TDFA.Text qualified as R

import Time (KnownRatName, Second, Time(..), unitsP)
import Time (KnownRatName, Second, Time (..), unitsP)

import Text.Regex.TDFA.Common
import Xrefcheck.Config.Default
import Xrefcheck.Core
import Xrefcheck.Scan
import Xrefcheck.Scanners.Markdown
import Xrefcheck.System (RelGlobPattern, normaliseGlobPattern)
import Xrefcheck.Util (aesonConfigOption, postfixFields, (-:))
import Xrefcheck.Config.Default
import Text.Regex.TDFA.Common

-- | Overall config.
data Config = Config
Expand Down
4 changes: 2 additions & 2 deletions src/Xrefcheck/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import System.FilePath (isPathSeparator, pathSeparator)
import Text.Numeral.Roman (toRoman)
import Time (Second, Time)

import Xrefcheck.Progress
import Xrefcheck.Util
import Data.DList (DList)
import Data.DList qualified as DList
import Xrefcheck.Progress
import Xrefcheck.Util

-----------------------------------------------------------
-- Types
Expand Down
4 changes: 2 additions & 2 deletions src/Xrefcheck/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ module Xrefcheck.Orphans () where

import Universum

import qualified Data.ByteString.Char8 as C
import Data.ByteString.Char8 qualified as C

import Fmt (Buildable (..), unlinesF, (+|), (|+))
import Network.FTP.Client
(FTPException (..), FTPMessage (..), FTPResponse (..), ResponseStatus (..))
import Text.URI (RText, unRText)
import URI.ByteString (URIParseError (..), SchemaError (..))
import URI.ByteString (SchemaError (..), URIParseError (..))

instance ToString (RText t) where
toString = toString . unRText
Expand Down
4 changes: 2 additions & 2 deletions src/Xrefcheck/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import Data.Foldable qualified as F
import Data.Map qualified as M
import System.Directory (doesDirectoryExist)
import System.Directory.Tree qualified as Tree
import System.FilePath (dropTrailingPathSeparator, takeDirectory, takeExtension, equalFilePath)
import System.FilePath (dropTrailingPathSeparator, equalFilePath, takeDirectory, takeExtension)

import Xrefcheck.Core
import Xrefcheck.Progress
import Xrefcheck.System (readingSystem, RelGlobPattern, normaliseGlobPattern, matchesGlobPatterns)
import Xrefcheck.System (RelGlobPattern, matchesGlobPatterns, normaliseGlobPattern, readingSystem)
import Xrefcheck.Util (aesonConfigOption, normaliseWithNoTrailing)

-- | Config of repositry traversal.
Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import Universum

import Data.Aeson (FromJSON (..), withText)
import Data.Char qualified as C
import Data.Coerce (coerce)
import GHC.IO.Unsafe (unsafePerformIO)
import System.Directory (canonicalizePath)
import System.Environment (lookupEnv)
import System.FilePath ((</>))
import System.FilePath.Glob qualified as Glob
import Data.Coerce (coerce)
import Xrefcheck.Util (normaliseWithNoTrailing)

-- | We can quite safely treat surrounding filesystem as frozen,
Expand Down
8 changes: 4 additions & 4 deletions src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Universum

import Control.Concurrent.Async (wait, withAsync)
import Control.Exception (throwIO)
import Control.Monad.Catch (handleJust)
import Control.Monad.Except (MonadError (..))
import Data.ByteString qualified as BS
import Data.List qualified as L
Expand All @@ -44,7 +45,7 @@ import Data.Text.Metrics (damerauLevenshteinNorm)
import Data.Time (UTCTime, defaultTimeLocale, formatTime, readPTime, rfc822DateFormat)
import Data.Time.Clock.POSIX (getPOSIXTime)
import Data.Traversable (for)
import Fmt (Buildable (..), blockListF', listF, maybeF, nameF, (+|), (|+), unlinesF, indentF)
import Fmt (Buildable (..), blockListF', indentF, listF, maybeF, nameF, unlinesF, (+|), (|+))
import GHC.Exts qualified as Exts
import GHC.Read (Read (readPrec))
import Network.FTP.Client
Expand All @@ -58,13 +59,12 @@ import Network.HTTP.Types.Header (hRetryAfter)
import Network.HTTP.Types.Status (Status, statusCode, statusMessage)
import System.Console.Pretty (Style (..), style)
import System.Directory (doesDirectoryExist, doesFileExist)
import System.FilePath (takeDirectory, (</>), normalise)
import System.FilePath (normalise, takeDirectory, (</>))
import Text.ParserCombinators.ReadPrec qualified as ReadPrec (lift)
import Text.Regex.TDFA.Text (Regex, regexec)
import Text.URI (Authority (..), URI (..), mkURIBs, ParseExceptionBs)
import Text.URI (Authority (..), ParseExceptionBs, URI (..), mkURIBs)
import Time (RatioNat, Second, Time (..), ms, sec, threadDelay, timeout, (+:+), (-:-))
import URI.ByteString qualified as URIBS
import Control.Monad.Catch (handleJust)

import Data.Bits (toIntegralSized)
import Xrefcheck.Config
Expand Down
10 changes: 5 additions & 5 deletions tests/Test/Xrefcheck/TooManyRequestsSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import Control.Concurrent (forkIO, killThread)
import Control.Exception qualified as E
import Data.CaseInsensitive qualified as CI
import Data.Map qualified as M
import Data.Time (addUTCTime, formatTime, getCurrentTime, defaultTimeLocale, rfc822DateFormat)
import Data.Time (addUTCTime, defaultTimeLocale, formatTime, getCurrentTime, rfc822DateFormat)
import Data.Time.Clock.POSIX (getPOSIXTime)
import Fmt (indentF, pretty, unlinesF)
import Network.HTTP.Types (Status (..), ok200, serviceUnavailable503, tooManyRequests429)
import Network.HTTP.Types.Header (hRetryAfter)
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.HUnit (assertBool)
import Test.Hspec (Spec, describe, it, shouldBe)
import Time (sec, (-:-))
import Web.Firefly (ToResponse (toResponse), route, run, getMethod)
import Web.Firefly (ToResponse (toResponse), getMethod, route, run)

import Xrefcheck.Config
import Xrefcheck.Core
Expand Down Expand Up @@ -133,9 +133,9 @@ spec = do
callCount <- atomicModifyIORef' callCountRef $ \cc -> (cc + 1, cc)
atomicModifyIORef' infoReverseAccumulatorRef $ \lst ->
( ( m
, if | m == "GET" -> ok200
, if | m == "GET" -> ok200
| callCount == 0 -> tooManyRequests429
| otherwise -> serviceUnavailable503
| otherwise -> serviceUnavailable503
) : lst
, ()
)
Expand Down
4 changes: 2 additions & 2 deletions tests/Test/Xrefcheck/URIParsingSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Universum
import Test.Hspec (Spec, describe, it, shouldReturn)
import Text.URI (URI)
import Text.URI.QQ (uri)
import URI.ByteString (URIParseError (..), SchemaError (..))
import URI.ByteString (SchemaError (..), URIParseError (..))

import Xrefcheck.Verify (parseUri, VerifyError (..))
import Xrefcheck.Verify (VerifyError (..), parseUri)

spec :: Spec
spec = do
Expand Down

0 comments on commit 9ed9c54

Please sign in to comment.