Skip to content

Commit fb77575

Browse files
committed
[#164] Add workflow for running Windows tests on CI
Problem: we are not testing behavior of xrefcheck on Windows Solution: and add workflow to run golden and tasty tests on CI via github-actions windows runner Some subproblems appear: 1. Problem: CI build fails beacuse it needs `pcre` package Solution: add it (somehow), see `install pacman dependencies` in ci.yml 2. Problem: Network errors displayed different on different platforms Solution: collect output from both and use `assert_diff expected_linux.gold || assert_diff expected_windows.gold` 3: Problem: "Config matches" test is failing because checkout action clone files with CRLF, and test assert equality of two ByteStrings Solution: manually remove CR
1 parent aba295b commit fb77575

File tree

13 files changed

+143
-17
lines changed

13 files changed

+143
-17
lines changed

.github/workflows/ci.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# SPDX-FileCopyrightText: 2020 Kowainik
2+
# SPDX-FileCopyrightText: 2022 Serokell <https://serokell.io/>
3+
#
4+
# SPDX-License-Identifier: MPL-2.0
5+
6+
# Sources:
7+
# • https://github.com/kowainik/validation-selective/blob/5b46cd4810bbaa09b704062ebbfa2bb47137425d/.github/workflows/ci.yml
8+
# • https://kodimensional.dev/github-actions
9+
# • https://github.com/serokell/tztime/blob/336f585c2c7125a8ba58ffbf3dbea4f36a7c40e7/.github/workflows/ci.yml
10+
11+
name: CI
12+
13+
on: [push]
14+
15+
jobs:
16+
xrefcheck-build-and-test:
17+
runs-on: windows-latest
18+
strategy:
19+
matrix:
20+
stack: ["2.7.5"]
21+
ghc: ["9.0.2"]
22+
include:
23+
- ghc: "9.0.2"
24+
stackyaml: stack.yaml
25+
steps:
26+
- uses: actions/checkout@v3
27+
with:
28+
submodules: 'true'
29+
30+
- uses: haskell/actions/[email protected]
31+
id: setup-haskell-stack
32+
name: Setup Haskell Stack
33+
with:
34+
ghc-version: ${{ matrix.ghc }}
35+
stack-version: ${{ matrix.stack }}
36+
37+
- uses: actions/cache@v3
38+
name: Cache stack root
39+
with:
40+
path: ~/AppData/Roaming/stack
41+
key: ${{ runner.os }}-${{ matrix.ghc }}-stack
42+
43+
- uses: actions/cache@v3
44+
name: Cache AppData/Local/Programs/stack
45+
with:
46+
path: ~/AppData/Local/Programs/stack
47+
key: ${{ runner.os }}-${{ matrix.ghc }}-appdata-stack
48+
49+
50+
# When editing this action, make sure it can run without using cached folders.
51+
# Yes, it tries to install mingw-w64-x86_64-pcre twice
52+
- name: install pacman dependencies
53+
run: |
54+
stack --system-ghc exec -- pacman -S --needed --noconfirm pkgconf;
55+
stack --system-ghc exec -- pacman -S --needed --noconfirm msys2-keyring;
56+
stack --system-ghc exec -- pacman --noconfirm -Syuu;
57+
stack --system-ghc exec -- pacman -S --needed --noconfirm mingw-w64-x86_64-pcre;
58+
stack --system-ghc exec -- pacman --noconfirm -Syuu;
59+
stack --system-ghc exec -- pacman -S --needed --noconfirm mingw-w64-x86_64-pcre;
60+
stack --system-ghc exec -- pacman -S --needed --noconfirm pcre-devel;
61+
62+
- name: Build
63+
run: |
64+
stack build --system-ghc --stack-yaml ${{ matrix.stackyaml }} --test --bench --no-run-tests --no-run-benchmarks --ghc-options '-Werror'
65+
66+
- name: stack test xrefcheck:xrefcheck-tests
67+
run: |
68+
stack test --system-ghc --stack-yaml ${{ matrix.stackyaml }} xrefcheck:xrefcheck-tests
69+
70+
- name: install xrefcheck to use with golden tests
71+
run: |
72+
stack --system-ghc --stack-yaml ${{ matrix.stackyaml }} install;
73+
74+
- uses: mig4/setup-bats@v1
75+
name: Setup bats
76+
77+
- name: Golden tests
78+
run: |
79+
export PATH=$PATH:/c/Users/runneradmin/AppData/Roaming/local/bin;
80+
bats ./tests/golden/**
81+
shell: bash

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Unreleased
2626
+ Now we notify user when there are scannable files that were not added to Git
2727
yet. Also added CLI option `--include-untracked` to scan such files and treat
2828
as existing.
29+
* [#191](https://github.com/serokell/xrefcheck/pull/191)
30+
+ Now we consider slash `/` (and only it) as path separator in local links for all OS,
31+
so xrefcheck's report is OS-independent
32+
+ Use utf-8 compatible codepage on Windows
2933

3034
0.2.2
3135
==========

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ This file should be committed to your repository.
9898
Run `stack install` to build everything and install the executable.
9999
If you wish to use `cabal`, you need to run [`stack2cabal`](https://hackage.haskell.org/package/stack2cabal) first!
100100

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

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

139149
## Further work [↑](#xrefcheck)
140150

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

exec/Main.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ module Main where
88
import Universum
99

1010
import Main.Utf8 (withUtf8)
11+
import System.IO.CodePage (withCP65001)
1112

1213
import Xrefcheck.CLI (Command (..), getCommand)
1314
import Xrefcheck.Command (defaultAction)
1415
import Xrefcheck.Config (defConfigText)
1516

1617
main :: IO ()
17-
main = withUtf8 $ do
18+
main = withUtf8 $ withCP65001 $ do
1819
command <- getCommand
1920
case command of
2021
DefaultCommand options ->

package.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ library:
111111
- reflection
112112
- nyan-interpolation
113113
- safe-exceptions
114-
- code-page
115114

116115
executables:
117116
xrefcheck:
@@ -128,6 +127,7 @@ executables:
128127
- xrefcheck
129128
- universum
130129
- with-utf8
130+
- code-page
131131

132132
tests:
133133
xrefcheck-tests:

src/Xrefcheck/Command.hs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import Fmt (build, fmt, fmtLn)
1515
import System.Console.Pretty (supportsPretty)
1616
import System.Directory (doesFileExist)
1717
import Text.Interpolation.Nyan
18-
import System.IO.CodePage (withCP65001)
1918

2019
import Xrefcheck.CLI (Options (..), addExclusionOptions, addNetworkingOptions, defaultConfigPaths)
2120
import Xrefcheck.Config
@@ -49,7 +48,7 @@ findFirstExistingFile = \case
4948
if exists then pure (Just file) else findFirstExistingFile files
5049

5150
defaultAction :: Options -> IO ()
52-
defaultAction Options{..} = withCP65001 $ do
51+
defaultAction Options{..} = do
5352
coloringSupported <- supportsPretty
5453
give (if coloringSupported then oColorMode else WithoutColors) $ do
5554
config <- case oConfigPath of

src/Xrefcheck/System.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import GHC.IO.Unsafe (unsafePerformIO)
2222
import System.Directory (canonicalizePath)
2323
import System.Environment (lookupEnv)
2424
import System.FilePath.Glob qualified as Glob
25-
import Text.Interpolation.Nyan
2625
import System.FilePath.Posix (isRelative, (</>))
26+
import Text.Interpolation.Nyan
2727

2828
import Xrefcheck.Util (normaliseWithNoTrailing)
2929

tests/golden/check-git/check-git.bats

+3-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ load '../helpers'
3131
assert_output --partial "All repository links are valid."
3232

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

4139
@test "Git: bad file not tracked, --include-untracked enabled, check failure" {

tests/golden/check-ignore/check-ignore.bats

+2-4
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ EOF
102102
run xrefcheck\
103103
--ignore "<to-ignore>"
104104
assert_failure
105-
assert_output --partial "option --ignore: Glob pattern compilation failed.
106-
Error message is:
107-
compile :: bad <>, expected number followed by - in to-ignore
108-
"
105+
assert_output --partial "option --ignore: Glob pattern compilation failed."
106+
assert_output --partial "compile :: bad <>, expected number followed by - in to-ignore"
109107
}

tests/golden/check-ignoreExternalRefsTo/check-ignoreExternalRefsTo.bats

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ load '../helpers'
2222
-c config-check-enabled.yaml \
2323
-r .
2424

25-
assert_diff expected.gold
25+
assert_diff expected_linux.gold || assert_diff expected_windows.gold
2626
}
2727

2828
@test "Ignore localhost, no config specified" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== Invalid references found ===
2+
3+
➥ In file check-ignoreExternalRefsTo.md
4+
bad reference (external) at src:7:10-53:
5+
- text: "web-site"
6+
- link: https://localhost:20000/web-site
7+
- anchor: -
8+
9+
⛂ InternalException (HostCannotConnect "localhost" [Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED)),Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))])
10+
11+
➥ In file check-ignoreExternalRefsTo.md
12+
bad reference (external) at src:9:10-45:
13+
- text: "team"
14+
- link: https://127.0.0.1:20000/team
15+
- anchor: -
16+
17+
⛂ InternalException (HostCannotConnect "127.0.0.1" [Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))])
18+
19+
➥ In file check-ignoreExternalRefsTo.md
20+
bad reference (external) at src:11:10-44:
21+
- text: "blog"
22+
- link: http://localhost:20000/blog
23+
- anchor: -
24+
25+
⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))
26+
27+
➥ In file check-ignoreExternalRefsTo.md
28+
bad reference (external) at src:13:10-44:
29+
- text: "labs"
30+
- link: http://127.0.0.1:20000/labs
31+
- anchor: -
32+
33+
⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))
34+
35+
Invalid references dumped, 4 in total.

tests/golden/helpers.bash

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ assert_diff() {
6767
: "{output_file?}"
6868

6969
diff $output_file $1 \
70-
--ignore-tab-expansion
70+
--ignore-tab-expansion \
71+
--strip-trailing-cr
7172
}

0 commit comments

Comments
 (0)