Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#164] Improve Windows support #191

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# SPDX-FileCopyrightText: 2020 Kowainik
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io/>
#
# SPDX-License-Identifier: MPL-2.0

# Sources:
# • https://github.com/kowainik/validation-selective/blob/5b46cd4810bbaa09b704062ebbfa2bb47137425d/.github/workflows/ci.yml
# • https://kodimensional.dev/github-actions
# • https://github.com/serokell/tztime/blob/336f585c2c7125a8ba58ffbf3dbea4f36a7c40e7/.github/workflows/ci.yml

name: CI

on: [push]

jobs:
xrefcheck-build-and-test:
runs-on: windows-latest
strategy:
matrix:
stack: ["2.7.5"]
ghc: ["9.0.2"]
include:
- ghc: "9.0.2"
stackyaml: stack.yaml
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'

- uses: haskell/actions/setup@v2.0.1
id: setup-haskell-stack
name: Setup Haskell Stack
with:
ghc-version: ${{ matrix.ghc }}
stack-version: ${{ matrix.stack }}

- uses: actions/cache@v3
name: Cache stack root
with:
path: ~/AppData/Roaming/stack
key: ${{ runner.os }}-${{ matrix.ghc }}-stack

- uses: actions/cache@v3
name: Cache AppData/Local/Programs/stack
with:
path: ~/AppData/Local/Programs/stack
key: ${{ runner.os }}-${{ matrix.ghc }}-appdata-stack


# When editing this action, make sure it can run without using cached folders.
# Yes, it tries to install mingw-w64-x86_64-pcre twice
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pacman does not feel too well? 🧌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just recorded my shell history, and then realized it's the way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a bit of torture to see a mention of some magic without an explanation of why it is needed / why it works 😅

On the other hand, if all the possible explanation is "doing it once fails with X error, but somehow repeat helps both locally and in CI, no one knows why", then maybe it's really not necessary to provide.

- name: install pacman dependencies
run: |
stack --system-ghc exec -- pacman -S --needed --noconfirm pkgconf;
stack --system-ghc exec -- pacman -S --needed --noconfirm msys2-keyring;
stack --system-ghc exec -- pacman --noconfirm -Syuu;
stack --system-ghc exec -- pacman -S --needed --noconfirm mingw-w64-x86_64-pcre;
stack --system-ghc exec -- pacman --noconfirm -Syuu;
stack --system-ghc exec -- pacman -S --needed --noconfirm mingw-w64-x86_64-pcre;
stack --system-ghc exec -- pacman -S --needed --noconfirm pcre-devel;
- name: Build
run: |
stack build --system-ghc --stack-yaml ${{ matrix.stackyaml }} --test --bench --no-run-tests --no-run-benchmarks --ghc-options '-Werror'
- name: stack test xrefcheck:xrefcheck-tests
run: |
stack test --system-ghc --stack-yaml ${{ matrix.stackyaml }} xrefcheck:xrefcheck-tests
- name: install xrefcheck to use with golden tests
run: |
stack --system-ghc --stack-yaml ${{ matrix.stackyaml }} install;
- uses: mig4/setup-bats@v1
name: Setup bats

- name: Golden tests
run: |
export PATH=$PATH:/c/Users/runneradmin/AppData/Roaming/local/bin;
bats ./tests/golden/**
shell: bash
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Unreleased
+ Now we notify user when there are scannable files that were not added to Git
yet. Also added CLI option `--include-untracked` to scan such files and treat
as existing.
* [#191](https://github.com/serokell/xrefcheck/pull/191)
+ Now we consider slash `/` (and only it) as path separator in local links for all OS,
so xrefcheck's report is OS-independent
+ Use utf-8 compatible codepage on Windows

0.2.2
==========
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ This file should be committed to your repository.
Run `stack install` to build everything and install the executable.
If you wish to use `cabal`, you need to run [`stack2cabal`](https://hackage.haskell.org/package/stack2cabal) first!

### Run on Windows [↑](#xrefcheck)
On Windows, executable requires some dynamic libraries (DLLs).
They are shipped together with executable in [releases page](https://github.com/serokell/xrefcheck/releases).
If you have built executable from source using `stack install`,
those DLLs are downloaded by stack to a location that is not on `%PATH%` by default.
There are several ways to fix this:
- Add `%LocalAppData%\Programs\stack\x86_64-windows\msys2-<...>\mingw64\bin` to your PATH
- run `stack exec xrefcheck.exe -- <args>` instead of `xrefcheck.exe <args>`
- add DLLs from archive from releases page to a folder containing `xrefcheck.exe`

## FAQ [↑](#xrefcheck)

1. How do I ignore specific files?
Expand Down Expand Up @@ -138,7 +148,6 @@ If you wish to use `cabal`, you need to run [`stack2cabal`](https://hackage.hask

## Further work [↑](#xrefcheck)

- [ ] Support for non-Unix systems.
- [ ] Support link detection in different languages, not only Markdown.
- [ ] Haskell Haddock is first in turn.

Expand Down
3 changes: 2 additions & 1 deletion exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ module Main where
import Universum

import Main.Utf8 (withUtf8)
import System.IO.CodePage (withCP65001)

import Xrefcheck.CLI (Command (..), getCommand)
import Xrefcheck.Command (defaultAction)
import Xrefcheck.Config (defConfigText)

main :: IO ()
main = withUtf8 $ do
main = withUtf8 $ withCP65001 $ do
command <- getCommand
case command of
DefaultCommand options ->
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ executables:
- xrefcheck
- universum
- with-utf8
- code-page

tests:
xrefcheck-tests:
Expand Down
4 changes: 2 additions & 2 deletions src/Xrefcheck/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Data.List qualified as L
import Data.Reflection (Given)
import Data.Text qualified as T
import Fmt (Buildable (..))
import System.FilePath (isPathSeparator, pathSeparator)
import System.FilePath.Posix (isPathSeparator)
import Text.Interpolation.Nyan
import Time (Second, Time)

Expand Down Expand Up @@ -339,7 +339,7 @@ canonizeLocalRef :: Text -> Text
canonizeLocalRef ref =
maybe ref canonizeLocalRef (T.stripPrefix localPrefix ref)
where
localPrefix = toText ['.', pathSeparator]
localPrefix = "./"

-----------------------------------------------------------
-- Visualisation
Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/Scan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Data.Map qualified as M
import Data.Reflection (Given)
import Fmt (Buildable (..), fmt)
import System.Directory (doesDirectoryExist)
import System.FilePath
import System.FilePath.Posix
(dropTrailingPathSeparator, equalFilePath, splitDirectories, takeDirectory, takeExtension, (</>))
import System.Process (cwd, readCreateProcess, shell)
import Text.Interpolation.Nyan
Expand Down
5 changes: 2 additions & 3 deletions src/Xrefcheck/System.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import Data.Coerce (coerce)
import GHC.IO.Unsafe (unsafePerformIO)
import System.Directory (canonicalizePath)
import System.Environment (lookupEnv)
import System.FilePath (isRelative, (</>))
import System.FilePath.Glob (CompOptions (errorRecovery))
import System.FilePath.Glob qualified as Glob
import System.FilePath.Posix (isRelative, (</>))
import Text.Interpolation.Nyan

import Xrefcheck.Util (normaliseWithNoTrailing)
Expand Down Expand Up @@ -89,4 +88,4 @@ instance FromJSON RelGlobPattern where

-- | Glob compilation options we use.
globCompileOptions :: Glob.CompOptions
globCompileOptions = Glob.compDefault{errorRecovery = False}
globCompileOptions = Glob.compDefault{Glob.errorRecovery = False}
2 changes: 1 addition & 1 deletion src/Xrefcheck/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Data.Time (UTCTime)
import Data.Time.Clock (nominalDiffTimeToSeconds)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Fmt (Builder)
import System.FilePath (dropTrailingPathSeparator, normalise)
import System.FilePath.Posix (dropTrailingPathSeparator, normalise)
import Time (Second, Time (..), sec)

import Xrefcheck.Util.Colorize
Expand Down
2 changes: 1 addition & 1 deletion src/Xrefcheck/Verify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import Network.HTTP.Req
HttpMethod, NoReqBody (..), defaultHttpConfig, ignoreResponse, req, runReq, useURI)
import Network.HTTP.Types.Header (hRetryAfter)
import Network.HTTP.Types.Status (Status, statusCode, statusMessage)
import System.FilePath
import System.FilePath.Posix
(equalFilePath, joinPath, makeRelative, normalise, splitDirectories, takeDirectory, (</>))
import Text.Interpolation.Nyan
import Text.ParserCombinators.ReadPrec qualified as ReadPrec (lift)
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extra-deps:
- firefly-0.2.1.0@sha256:e9d73486464c3e223ec457e02b30ddd5b550fdbf6292b268c64581e2b07d888b,1519
- cmark-gfm-0.2.5
- git: https://github.com/serokell/nyan-interpolation
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
subdirs:
- full
- core
10 changes: 5 additions & 5 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ packages:
original:
hackage: cmark-gfm-0.2.5
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation
pantry-tree:
Expand All @@ -28,20 +28,20 @@ packages:
subdir: full
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: full
- completed:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
name: nyan-interpolation-core
pantry-tree:
sha256: 59d1c732629b06d0035229dccce484d6b4c3078d6bb3e493317afddc9be233df
sha256: 4802161ce5d38f895e3b5106c789bfbe20b8d12c2f6c5fcba3999bec105283bc
size: 1516
subdir: core
version: '0.9'
original:
commit: 5e158057b167275d2150454e2bb731cfe686ea7a
commit: 348355385466d6d0116251b463a2842ecce0360d
git: https://github.com/serokell/nyan-interpolation
subdir: core
snapshots:
Expand Down
8 changes: 3 additions & 5 deletions tests/golden/check-git/check-git.bats
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ load '../helpers'
assert_output --partial "All repository links are valid."

# this is printed to stderr
assert_output --partial - <<EOF
Those files are not added by Git, so we're not scanning them:
- git.md
Please run "git add" before running xrefcheck or enable --include-untracked CLI option to check these files.
EOF
assert_output --partial "Those files are not added by Git, so we're not scanning them:"
assert_output --partial "- git.md"
assert_output --partial "Please run \"git add\" before running xrefcheck or enable --include-untracked CLI option to check these files."
}

@test "Git: bad file not tracked, --include-untracked enabled, check failure" {
Expand Down
6 changes: 2 additions & 4 deletions tests/golden/check-ignore/check-ignore.bats
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ EOF
run xrefcheck\
--ignore "<to-ignore>"
assert_failure
assert_output --partial "option --ignore: Glob pattern compilation failed.
Error message is:
compile :: bad <>, expected number followed by - in to-ignore
"
assert_output --partial "option --ignore: Glob pattern compilation failed."
assert_output --partial "compile :: bad <>, expected number followed by - in to-ignore"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ load '../helpers'
-c config-check-enabled.yaml \
-r .

assert_diff expected.gold
assert_diff expected_linux.gold || assert_diff expected_windows.gold
}

@test "Ignore localhost, no config specified" {
Expand Down
35 changes: 35 additions & 0 deletions tests/golden/check-ignoreExternalRefsTo/expected_windows.gold
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
=== Invalid references found ===

➥ In file check-ignoreExternalRefsTo.md
bad reference (external) at src:7:10-53:
- text: "web-site"
- link: https://localhost:20000/web-site
- anchor: -

⛂ InternalException (HostCannotConnect "localhost" [Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED)),Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))])

➥ In file check-ignoreExternalRefsTo.md
bad reference (external) at src:9:10-45:
- text: "team"
- link: https://127.0.0.1:20000/team
- anchor: -

⛂ InternalException (HostCannotConnect "127.0.0.1" [Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))])

➥ In file check-ignoreExternalRefsTo.md
bad reference (external) at src:11:10-44:
- text: "blog"
- link: http://localhost:20000/blog
- anchor: -

⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))

➥ In file check-ignoreExternalRefsTo.md
bad reference (external) at src:13:10-44:
- text: "labs"
- link: http://127.0.0.1:20000/labs
- anchor: -

⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))

Invalid references dumped, 4 in total.
Martoon-00 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion tests/golden/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ assert_diff() {
: "{output_file?}"

diff $output_file $1 \
--ignore-tab-expansion
--ignore-tab-expansion \
--strip-trailing-cr
}