Skip to content

Commit

Permalink
Merge branch 'main' into gabriella/upgrade_nixpkgs_2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 authored Oct 6, 2024
2 parents cb273d0 + dc48911 commit 361019c
Show file tree
Hide file tree
Showing 117 changed files with 981 additions and 426 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
dhall-csv/tasty/data/* binary
dhall-docs/tasty/data/golden/**/*.html binary
dhall-docs/tasty/data/package/StandaloneTextFile.txt binary
dhall-docs/tasty/data/package/MarkdownFile.md binary
dhall-docs/tasty/data/package/InvalidMarkdownFile.md binary
dhall-yaml/tasty/data/* binary
35 changes: 23 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env:
cache_generation: 2021-06-22
cache_generation: 2024-06-13

# NOTE: Please keep .mergify.yml in sync when adding or removing any jobs.
name: main
Expand All @@ -13,6 +13,10 @@ jobs:
archive-command: 'tar --create --bzip2 --file'
file-extension: 'tar.bz2'
executable-extension: ''
- runner: 'macos-13'
archive-command: 'tar --create --bzip2 --file'
file-extension: 'tar.bz2'
executable-extension: ''
- runner: 'ubuntu-latest'
archive-command: 'tar --create --bzip2 --file'
file-extension: 'tar.bz2'
Expand All @@ -27,6 +31,12 @@ jobs:
- os:
runner: "ubuntu-latest"
stack-yaml: "stack.ghc-8.10.yaml"
- os:
runner: "ubuntu-latest"
stack-yaml: "stack.ghc-9.2.yaml"
- os:
runner: "ubuntu-latest"
stack-yaml: "stack.ghc-9.4.yaml"
fail-fast: false
name: ${{ matrix.os.runner }} - ${{ matrix.stack-yaml }}
runs-on: ${{ matrix.os.runner }}
Expand All @@ -37,24 +47,27 @@ jobs:
submodules: true
- id: setup-haskell-cabal
name: "Setup Haskell environment"
uses: haskell-actions/setup@v2.5
uses: haskell-actions/setup@v2.7
with:
enable-stack: true
stack-version: "latest"
stack-no-global: true
- name: "Cache"
uses: actions/cache@v3
uses: actions/cache@v4
with:
key: ${{ matrix.os.runner }}-${{ hashFiles(matrix.stack-yaml) }}-${{ env.cache_generation }}
key: ${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-${{ hashFiles(matrix.stack-yaml) }}
restore-keys: |
${{ matrix.os.runner }}-
${{ matrix.os.runner }}-${{ runner.arch }}-${{ env.cache_generation }}-
path: |
${{ steps.setup-haskell-cabal.outputs.stack-root }}
- name: Install libsodium
- name: "Install libsodium"
shell: bash
run: |
if [ '${{matrix.os.runner}}' == 'ubuntu-latest' ]; then
sudo apt-get install -y libsodium-dev
fi
echo "::debug::'pkg-config libsodium' output:"
pkg-config --print-errors --libs libsodium || true
- name: "Build"
shell: bash
run: |
Expand Down Expand Up @@ -127,14 +140,12 @@ jobs:
dhall-yaml
)
architecture="$(uname -m)"
function package() (
local package="${1}"
local version="$(stack query locals "${package}" version)"
shift
local assets=("${@}")
local package_file="${package}-${version}-${architecture}-${{runner.os}}.${{ matrix.os.file-extension }}"
local package_file="${package}-${version}-${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}"
${{matrix.os.archive-command}} "${package_file}" "${assets[@]}"
)
Expand All @@ -153,7 +164,7 @@ jobs:
package 'dhall-yaml' "bin/dhall-to-yaml-ng${exe}" "bin/yaml-to-dhall${exe}"
- name: "Upload package"
if: ${{ matrix.stack-yaml == 'stack.yaml' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: 'dhall-${{runner.os}}.${{matrix.os.file-extension}}'
path: 'dhall-*${{runner.os}}.${{matrix.os.file-extension}}'
name: 'dhall-${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'
path: 'dhall-*${{ runner.os }}-${{ runner.arch }}.${{ matrix.os.file-extension }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cabal.sandbox.config
cabal.project.local
cabal.project.local~
.HTF/
.envrc
.ghc.environment.*
.cache
.history
Expand Down
2 changes: 1 addition & 1 deletion dhall-bash/dhall-bash.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Library
Build-Depends:
base >= 4.11.0.0 && < 5 ,
bytestring < 0.13,
containers < 0.7 ,
containers < 0.8 ,
dhall >= 1.42.0 && < 1.43,
neat-interpolation < 0.6 ,
shell-escape < 0.3 ,
Expand Down
10 changes: 5 additions & 5 deletions dhall-csv/dhall-csv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ Library
Hs-Source-Dirs: src
Build-Depends:
base >= 4.12.0.0 && < 5 ,
bytestring < 0.12,
bytestring < 0.13,
cassava >= 0.5.0.0 && < 0.6 ,
containers >= 0.5.9 && < 0.7 ,
containers >= 0.5.9 && < 0.8 ,
either ,
exceptions >= 0.8.3 && < 0.11,
dhall >= 1.39.0 && < 1.43,
filepath < 1.5 ,
filepath < 1.6 ,
optparse-applicative ,
prettyprinter >= 1.7.0 && < 1.8 ,
text >= 0.11.1.0 && < 2.1 ,
text >= 0.11.1.0 && < 2.2 ,
unordered-containers < 0.3 ,
vector >= 0.12 && < 0.14
Exposed-Modules:
Expand Down Expand Up @@ -108,7 +108,7 @@ Test-Suite tasty
dhall ,
dhall-csv ,
filepath ,
tasty < 1.5 ,
tasty < 1.6 ,
tasty-silver < 3.4 ,
tasty-hunit >= 0.2 ,
unordered-containers ,
Expand Down
10 changes: 6 additions & 4 deletions dhall-docs/dhall-docs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ Category: Compiler
Extra-Source-Files:
CHANGELOG.md
README.md
tasty/data/package/*.md
tasty/data/package/*.txt
tasty/data/package/*.dhall
tasty/data/package/a/*.dhall
tasty/data/package/a/b/*.dhall
tasty/data/package/a/b/c/*.dhall
tasty/data/package/deep/nested/folder/*.dhall
tasty/data/golden/*.md.html
tasty/data/golden/*.txt.html
tasty/data/golden/*.dhall.html
tasty/data/golden/a/*.dhall.html
Expand Down Expand Up @@ -71,7 +73,7 @@ Library
directory >= 1.3.0.0 && < 1.4 ,
dhall >= 1.38.0 && < 1.43,
file-embed >= 0.0.10.0 ,
filepath >= 1.4 && < 1.5 ,
filepath >= 1.4 && < 1.6 ,
lens-family-core >= 1.0.0 && < 2.2 ,
lucid >= 2.9.12 && < 2.12,
mmark >= 0.0.7.0 && < 0.8 ,
Expand Down Expand Up @@ -124,7 +126,7 @@ Test-Suite doctest
Build-Depends:
base ,
directory,
filepath < 1.5 ,
filepath < 1.6 ,
doctest >= 0.7.0
Other-Extensions: OverloadedStrings RecordWildCards
Default-Language: Haskell2010
Expand All @@ -147,10 +149,10 @@ Test-Suite tasty
path ,
path-io ,
pretty >= 1.1.1.1 ,
tasty < 1.5 ,
tasty < 1.6 ,
tasty-silver < 3.4 ,
tasty-hunit >= 0.10 && < 0.11,
turtle < 1.7 ,
turtle >= 1.6 && < 1.7 ,
text
GHC-Options: -Wall
Default-Language: Haskell2010
67 changes: 54 additions & 13 deletions dhall-docs/src/Dhall/Docs/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ instance MonadWriter [DocsGenWarning] GeneratedDocs where

data DocsGenWarning
= InvalidDhall (Text.Megaparsec.ParseErrorBundle Text Void)
| InvalidMarkdown MarkdownParseError
| InvalidMarkdownHeader MarkdownParseError
| InvalidMarkdownFile MarkdownParseError
| DhallDocsCommentError (Path Rel File) CommentParseError

warn :: String
Expand All @@ -117,11 +118,16 @@ instance Show DocsGenWarning where
Text.Megaparsec.errorBundlePretty err <>
"... documentation won't be generated for this file"

show (InvalidMarkdown MarkdownParseError{..}) =
show (InvalidMarkdownHeader MarkdownParseError{..}) =
warn <>"Header comment is not markdown\n\n" <>
Text.Megaparsec.errorBundlePretty unwrap <>
"The original non-markdown text will be pasted in the documentation"

show (InvalidMarkdownFile MarkdownParseError{..}) =
warn <>"Failed to parse file as markdown\n\n" <>
Text.Megaparsec.errorBundlePretty unwrap <>
"The original file contents will be pasted in the documentation"

show (DhallDocsCommentError path err) =
warn <> Path.fromRelFile path <> specificError
where
Expand Down Expand Up @@ -167,9 +173,15 @@ data FileType
-- ^ Examples extracted from assertions in the file
, fileComments :: FileComments
}
| MarkdownFile
{ mmark :: MMark
-- ^ Parsed Markdown from 'contents'
}
| TextFile
deriving (Show)

data FileExtension = DhallExtension | MarkdownExtension | OtherExtension deriving (Show)

{-| Takes a list of files paths with their contents and returns the list of
valid `RenderedFile`s.
Expand All @@ -182,10 +194,12 @@ getAllRenderedFiles :: [(Path Rel File, ByteString)] -> GeneratedDocs [RenderedF
getAllRenderedFiles =
fmap Maybe.catMaybes . mapM toRenderedFile . foldr validFiles []
where
hasDhallExtension :: Path Rel File -> Bool
hasDhallExtension absFile = case Path.splitExtension absFile of
Nothing -> False
Just (_, ext) -> ext == ".dhall"
getFileExtension :: Path Rel File -> FileExtension
getFileExtension absFile =
case snd <$> Path.splitExtension absFile of
Just ".dhall" -> DhallExtension
Just ".md" -> MarkdownExtension
_ -> OtherExtension

validFiles :: (Path Rel File, ByteString) -> [(Path Rel File, Text)] -> [(Path Rel File, Text)]
validFiles (relFile, content) xs = case Data.Text.Encoding.decodeUtf8' content of
Expand All @@ -195,8 +209,8 @@ getAllRenderedFiles =
toRenderedFile
:: (Path Rel File, Text) -> GeneratedDocs (Maybe RenderedFile)
toRenderedFile (relFile, contents) =
case exprAndHeaderFromText (Path.fromRelFile relFile) contents of
Right (Header header, expr) -> do
case (exprAndHeaderFromText (Path.fromRelFile relFile) contents, getFileExtension relFile) of
(Right (Header header, expr), _) -> do
let denoted = denote expr :: Expr Void Import

headerContents <-
Expand All @@ -217,11 +231,27 @@ getAllRenderedFiles =
, fileComments = FileComments headerContents
}
}
Left ParseError{..} | hasDhallExtension relFile -> do
(Left ParseError{..}, DhallExtension) -> do
Writer.tell [InvalidDhall unwrap]
return Nothing

Left _ -> do
(Left ParseError{}, MarkdownExtension) ->
case parseMarkdown relFile contents of
Right mmark ->
return $ Just $ RenderedFile
{ contents
, path = relFile
, fileType = MarkdownFile mmark
}
Left err -> do
Writer.tell [InvalidMarkdownFile err]
return $ Just $ RenderedFile
{ contents
, path = relFile
, fileType = TextFile
}

_ -> do
return $ Just $ RenderedFile
{ contents
, path = relFile
Expand Down Expand Up @@ -330,7 +360,7 @@ makeHtml baseImportUrl packageName characterSet RenderedFile{..} = do
headerAsHtml <-
case markdownToHtml path strippedHeader of
Left err -> do
Writer.tell [InvalidMarkdown err]
Writer.tell [InvalidMarkdownHeader err]
return $ Lucid.toHtml strippedHeader
Right html -> return html

Expand All @@ -344,6 +374,16 @@ makeHtml baseImportUrl packageName characterSet RenderedFile{..} = do
DocParams{ relativeResourcesPath, packageName, characterSet, baseImportUrl }

return htmlAsText

MarkdownFile mmark -> do
let htmlAsText =
Text.Lazy.toStrict $ Lucid.renderText $ markdownFileToHtml
path
contents
(render mmark)
DocParams{ relativeResourcesPath, packageName, characterSet, baseImportUrl }
return htmlAsText

TextFile -> do
let htmlAsText =
Text.Lazy.toStrict $ Lucid.renderText $ textFileToHtml
Expand Down Expand Up @@ -420,8 +460,9 @@ createIndexes baseImportUrl packageName characterSet renderedFiles = map toIndex
adapt RenderedFile{..} = (stripPrefix (addHtmlExt path), m)
where
m = case fileType of
DhallFile{..} -> mType
TextFile -> Nothing
DhallFile{..} -> mType
MarkdownFile _ -> Nothing
TextFile -> Nothing

html = indexToHtml
indexDir
Expand Down
Loading

0 comments on commit 361019c

Please sign in to comment.