Skip to content

Commit 3664674

Browse files
Skip kdl-test tests if dotslash is not installed (#24)
* Skip kdl-test tests if dotslash not installed * Move kdl-test to tools/ * Add GHC 9.14 to CI * Update CI/release workflows
1 parent fca8dc3 commit 3664674

7 files changed

Lines changed: 141 additions & 31 deletions

File tree

.github/workflows/ci.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- '9.8'
1919
- '9.10'
2020
- '9.12'
21-
# - '9.14'
21+
- '9.14'
2222
include:
2323
- ghc_version: '9.8.1'
2424
oldest: true
@@ -41,6 +41,23 @@ jobs:
4141
cabal configure
4242
--enable-test
4343
--test-show-details=streaming
44+
-
45+
# TODO: Remove these exclusions as packages are updated with 9.14
46+
if: ${{ matrix.ghc_version == '9.14' }}
47+
name: Add 9.14 flags
48+
run: >
49+
cabal configure
50+
--enable-append
51+
--allow-newer='aeson:*'
52+
--allow-newer='boring:*'
53+
--allow-newer='indexed-traversable:*'
54+
--allow-newer='indexed-traversable-instances:*'
55+
--allow-newer='ordered-containers:*'
56+
--allow-newer='semialign:*'
57+
--allow-newer='text-iso8601:*'
58+
--allow-newer='these:*'
59+
--allow-newer='time-compat:*'
60+
--allow-newer='uuid-types:*'
4461
-
4562
if: ${{ matrix.oldest }}
4663
name: Use oldest dependencies
@@ -79,7 +96,7 @@ jobs:
7996
name: Install hooky
8097
run: |
8198
curl -fsSL \
82-
https://github.com/brandonchinn178/hooky/releases/download/v1.0.0/hooky-1.0.0-linux-x86_64 \
99+
https://github.com/brandonchinn178/hooky/releases/download/v1.0.2/hooky-1.0.2-linux-x86_64 \
83100
-o /usr/local/bin/hooky
84101
chmod +x /usr/local/bin/hooky
85102
-
@@ -102,9 +119,6 @@ jobs:
102119
id: setup
103120
name: Set up GHC
104121
uses: haskell-actions/setup@v2
105-
-
106-
name: Strip unreleased section from CHANGELOG
107-
run: sed -i -n '/^## Unreleased/d; /^## /,$p' CHANGELOG.md
108122
-
109123
name: Create sdist bundle
110124
run: cabal sdist --output-directory=.

.github/workflows/release.yml

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,81 @@
11
name: Release
22
on: workflow_dispatch
33

4+
defaults:
5+
run:
6+
shell: bash -eu -o pipefail {0}
7+
48
jobs:
9+
cabal_file:
10+
runs-on: ubuntu-latest
11+
steps:
12+
-
13+
uses: actions/checkout@v6
14+
-
15+
uses: haskell-actions/parse-cabal-file@v1
16+
id: cabal_file
17+
with:
18+
cabal_file: kdl-hs.cabal
19+
outputs:
20+
version: ${{ steps.cabal_file.outputs.version }}
21+
522
ci:
623
uses: ./.github/workflows/ci.yml
724

25+
check_changelog:
26+
needs:
27+
- cabal_file
28+
runs-on: ubuntu-latest
29+
env:
30+
version: ${{ needs.cabal_file.outputs.version }}
31+
steps:
32+
-
33+
uses: actions/checkout@v6
34+
-
35+
name: Validate CHANGELOG
36+
run:
37+
scripts/release_notes.py validate-changelog
38+
--release-version "${version}"
39+
840
release:
941
runs-on: ubuntu-latest
1042
needs:
43+
- cabal_file
1144
- ci
45+
- check_changelog
46+
47+
env:
48+
version: ${{ needs.cabal_file.outputs.version }}
1249

1350
steps:
1451
-
15-
uses: actions/checkout@v3
52+
uses: actions/checkout@v6
1653
-
1754
uses: actions/download-artifact@v4
1855
with:
1956
name: kdl-sdist
20-
path: ./sdist/
21-
-
22-
id: cabal_file
23-
uses: haskell-actions/parse-cabal-file@v1
24-
with:
25-
cabal_file: kdl-hs.cabal
26-
-
27-
name: Set version label
28-
run: echo 'VERSION=v${{ steps.cabal_file.outputs.version }}' >> "${GITHUB_ENV}"
57+
path: ./.release/sdist/
2958
-
3059
id: hackage_token_secret
3160
name: Load Hackage token secret name
3261
run: |
3362
USERNAME="$(echo "${GITHUB_ACTOR}" | tr '[:lower:]' '[:upper:]' | tr '-' '_')"
3463
echo "name=HACKAGE_TOKEN_${USERNAME}" >> "${GITHUB_OUTPUT}"
3564
-
36-
name: Get CHANGELOG section
37-
run: |
38-
sed '/^## Unreleased/,/^$/d' CHANGELOG.md > /tmp/changelog-without-unreleased
39-
if [[ "$(head -n 1 /tmp/changelog-without-unreleased)" != "## ${VERSION}" ]]; then
40-
echo "CHANGELOG doesn't look updated" >&2
41-
exit 1
42-
fi
43-
sed '1 d; /^## v/,$ d' /tmp/changelog-without-unreleased > /tmp/changelog-body
65+
name: Generate release notes
66+
run:
67+
scripts/release_notes.py generate
68+
--release-version "${version}"
69+
| tee .release/release-notes.md
4470
-
4571
uses: haskell-actions/hackage-publish@v1
4672
with:
4773
hackageToken: ${{ secrets[steps.hackage_token_secret.outputs.name] }}
48-
packagesPath: ./sdist/
74+
packagesPath: ./.release/sdist/
4975
-
5076
uses: softprops/action-gh-release@v1
5177
with:
52-
tag_name: ${{ env.VERSION }}
53-
body_path: /tmp/changelog-body
78+
tag_name: v${{ env.version }}
79+
body_path: .release/release-notes.md
5480
draft: true
5581
target_commitish: ${{ github.sha }}

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
## Unreleased
2-
31
## v1.0.0
42

53
* Implement KDL v2 parser

kdl-hs.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extra-source-files:
1818
test/KDL/__snapshots__/DecoderSpec.snap.md
1919
test/KDL/__snapshots__/ParserSpec.snap.md
2020
test/KDL/__snapshots__/RenderSpec.snap.md
21+
tools/kdl-test
2122

2223
source-repository head
2324
type: git

scripts/release_notes.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import itertools
5+
from pathlib import Path
6+
7+
TOP = Path(__file__).resolve().parent.parent
8+
9+
10+
def main() -> None:
11+
parser = argparse.ArgumentParser()
12+
subparsers = parser.add_subparsers(required=True)
13+
14+
parser_validate_changelog = subparsers.add_parser("validate-changelog")
15+
parser_validate_changelog.add_argument("--release-version", required=True)
16+
parser_validate_changelog.set_defaults(
17+
run=lambda args: validate_changelog(
18+
version=args.release_version,
19+
)
20+
)
21+
22+
parser_generate = subparsers.add_parser("generate")
23+
parser_generate.add_argument("--release-version", required=True)
24+
parser_generate.set_defaults(
25+
run=lambda args: generate(
26+
version=args.release_version,
27+
)
28+
)
29+
30+
args = parser.parse_args()
31+
args.run(args)
32+
33+
34+
def validate_changelog(version: str) -> None:
35+
_ = get_changelog_for(version)
36+
37+
38+
def get_changelog_for(version: str) -> str:
39+
changelog = (TOP / "CHANGELOG.md").read_text().splitlines()
40+
41+
if changelog[0] != f"## v{version}":
42+
raise Exception(
43+
f"""
44+
CHANGELOG doesn't look updated.
45+
Expected version: {version!r}
46+
Got header: {changelog[0]!r}
47+
"""
48+
)
49+
50+
return "\n".join(
51+
itertools.takewhile(
52+
lambda line: not line.startswith("#"),
53+
changelog[1:],
54+
)
55+
)
56+
57+
58+
def generate(version: str) -> None:
59+
release_notes = [
60+
get_changelog_for(version),
61+
]
62+
print("\n".join(release_notes))
63+
64+
65+
if __name__ == "__main__":
66+
main()

test/KDL/ParserSpec.hs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
module KDL.ParserSpec (spec) where
55

66
import Control.Monad (forM_)
7+
import Data.Maybe (isJust)
78
import Data.Text.IO qualified as Text
89
import KDL qualified
910
import Skeletest
1011
import Skeletest.Predicate qualified as P
1112
import System.Directory (findExecutable, listDirectory)
1213
import System.FilePath (takeExtension, (</>))
1314
import System.IO.Temp (withSystemTempDirectory)
15+
import System.IO.Unsafe (unsafePerformIO)
1416
import System.Process (callProcess)
1517

1618
spec :: Spec
@@ -44,17 +46,20 @@ spec = do
4446
-- tested in `parse`
4547
actual `shouldBe` expected
4648

47-
describe "kdl-test examples" $ do
49+
(if dotSlashInstalled then id else skip "dotslash not installed") . describe "kdl-test examples" $ do
4850
it "decodes correctly" $ do
4951
decoder <- findExecutable "kdl-hs-test-decoder" >>= maybe (error "Could not find kdl-hs-test-decoder") pure
50-
callProcess "scripts/kdl-test" ["run", "--decoder", decoder]
52+
callProcess "tools/kdl-test" ["run", "--decoder", decoder]
5153

5254
it "roundtrips successfully" $ do
5355
FixtureTmpDir tmpdir <- getFixture
5456
let dir = tmpdir </> "kdl-examples"
55-
callProcess "scripts/kdl-test" ["extract", "--dir", dir]
57+
callProcess "tools/kdl-test" ["extract", "--dir", dir]
5658
files <- filter ((== ".kdl") . takeExtension) <$> listDirectory (dir </> "valid")
5759
forM_ files $ \file -> do
5860
context file $ do
5961
content <- Text.readFile (dir </> "valid" </> file)
6062
(fmap KDL.render . KDL.parse) content `shouldBe` Right content
63+
64+
dotSlashInstalled :: Bool
65+
dotSlashInstalled = unsafePerformIO $ isJust <$> findExecutable "dotslash"
File renamed without changes.

0 commit comments

Comments
 (0)