Skip to content

Commit 74361a3

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 bf8c751 commit 74361a3

File tree

7 files changed

+144
-5
lines changed

7 files changed

+144
-5
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
@@ -25,6 +25,10 @@ Unreleased
2525
as broken (with message `Link targets a local file outside repository`).
2626
Same for links that are using directories outside repository (e.g. `/../repo/a.md`),
2727
since such things are not supported by GitHub markdown renderer.
28+
* [#191](https://github.com/serokell/xrefcheck/pull/191)
29+
+ Now we consider slash `/` (and only it) as path separator in local links for all OS,
30+
so xrefcheck's report is OS-independent
31+
+ Use utf-8 compatible codepage on Windows
2832

2933
0.2.1
3034
==========

README.md

+11-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,17 @@ Currently supported options include:
164164
## Build instructions [↑](#xrefcheck)
165165

166166
Run `stack install` to build everything and install the executable.
167-
If you want to use cabal, you need to run (`stack2cabal`)[https://hackage.haskell.org/package/stack2cabal] first!
167+
If you want to use cabal, you need to run [`stack2cabal`](https://hackage.haskell.org/package/stack2cabal) first!
168+
169+
### Run on Windows [↑](#xrefcheck)
170+
On Windows, executable requires some dynamic libraries (DLLs).
171+
They are shipped together with executable in [releases page](https://github.com/serokell/xrefcheck/releases).
172+
If you have builded executable from source using `stack install`,
173+
those DLLs are downloaded by stack to location is not on `%PATH%` by default.
174+
There are several ways to fix this:
175+
- Add `%LocalAppData%\Programs\stack\x86_64-windows\msys2-<...>\mingw64\bin` to your PATH
176+
- run `stack exec xrefcheck.exe -- <args>` instead of `xrefcheck.exe <args>`
177+
- add DLLs from archive from releases page to a folder containing `xrefcheck.exe`
168178

169179
### CI and nix [↑](#xrefcheck)
170180

@@ -179,7 +189,6 @@ You can do that too if you wish.
179189

180190
## For further work [↑](#xrefcheck)
181191

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

tests/Test/Xrefcheck/ConfigSpec.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Universum
1010
import Control.Concurrent (forkIO, killThread)
1111
import Control.Exception qualified as E
1212

13-
import Data.ByteString qualified as BS
13+
import Data.ByteString.Char8 qualified as BS
1414
import Data.List (isInfixOf)
1515
import Data.Yaml (ParseException (..), decodeEither')
1616
import Network.HTTP.Types (Status (..))
@@ -37,7 +37,9 @@ test_config =
3737
-- stack exec xrefcheck -- dump-config -t GitHub -o tests/configs/github-config.yaml
3838
[ testCase "Config matches" $ do
3939
config <- BS.readFile "tests/configs/github-config.yaml"
40-
when (config /= defConfigText GitHub) $
40+
-- On Windows, git clone can replace \n with \r\n in some files
41+
let removeCR = BS.filter (/= '\r')
42+
when (removeCR config /= removeCR (defConfigText GitHub)) $
4143
assertFailure $ toString $ unwords
4244
[ "Config does not match the expected format."
4345
, "Run"

tests/golden/check-ignoreRefs/check-ignoreRefs.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,43 @@
1+
=== Invalid references found ===
2+
3+
➥ In file check-ignoreRefs.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+
12+
13+
➥ In file check-ignoreRefs.md
14+
bad reference (external) at src:9:10-45:
15+
- text: "team"
16+
- link: https://127.0.0.1:20000/team
17+
- anchor: -
18+
19+
⛂ InternalException (HostCannotConnect "127.0.0.1" [Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))])
20+
21+
22+
23+
➥ In file check-ignoreRefs.md
24+
bad reference (external) at src:11:10-44:
25+
- text: "blog"
26+
- link: http://localhost:20000/blog
27+
- anchor: -
28+
29+
⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))
30+
31+
32+
33+
➥ In file check-ignoreRefs.md
34+
bad reference (external) at src:13:10-44:
35+
- text: "labs"
36+
- link: http://127.0.0.1:20000/labs
37+
- anchor: -
38+
39+
⛂ ConnectionFailure Network.Socket.connect: <socket: N>: failed (Connection refused (WSAECONNREFUSED))
40+
41+
42+
43+
Invalid references dumped, 4 in total.

0 commit comments

Comments
 (0)