Bump pandoc to 2.9, switch to GitHub actions

This commit is contained in:
Jasper Van der Jeugt 2020-06-29 17:11:36 +02:00 committed by GitHub
parent 600587e636
commit 2135748f23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 203 additions and 167 deletions

View File

@ -1,57 +0,0 @@
version: 2
workflows:
version: 2
build-workflow:
jobs:
- build-macos:
filters:
tags:
only: /.*/
- build-linux:
filters:
tags:
only: /.*/
jobs:
build-macos:
macos:
xcode: '10.0.0'
steps:
- run:
name: 'Set up PATH'
command: echo "export PATH=$HOME/.local/bin:$PATH" >> $BASH_ENV
- checkout
- run:
name: 'Install stack'
command: 'curl -sSL https://get.haskellstack.org/ | sh'
- restore_cache:
key: 'v6-{{ arch }}'
- run:
command: 'make build test'
- save_cache:
key: 'v6-{{ arch }}'
paths:
- '~/.stack'
- run:
name: 'Upload release'
command: 'if [[ ! -z "$CIRCLE_TAG" ]]; then make release; fi'
build-linux:
# This image has most Haskell stuff preinstalled.
docker:
- image: 'haskell:8.6'
steps:
- checkout
- restore_cache:
key: 'v6-{{ arch }}'
- run:
command: 'make build test'
- save_cache:
key: 'v6-{{ arch }}'
paths:
- '~/.stack'
- run:
name: 'Upload release'
command: 'if [[ ! -z "$CIRCLE_TAG" ]]; then make release; fi'

100
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,100 @@
name: CI
on: ['push']
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest]
stack: ["2.1.3"]
ghc: ["8.8.3"]
steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'
- uses: actions/checkout@v2
- uses: actions/setup-haskell@v1.1
name: Setup Haskell Stack
with:
ghc-version: ${{ matrix.ghc }}
stack-version: ${{ matrix.stack }}
- uses: actions/cache@v2
name: Cache ~/.stack
with:
path: ~/.stack
key: ${{ runner.os }}-${{ matrix.ghc }}-v1
- name: Add ~/.local/bin to PATH
run: echo "::add-path::$HOME/.local/bin"
- name: Build
run: make build
id: build
- name: Test
run: make test
- name: Build artifact
if: startsWith(github.ref, 'refs/tags')
run: make artifact
env:
PATAT_TAG: ${{ steps.get_version.outputs.version }}
- uses: actions/upload-artifact@v2
if: startsWith(github.ref, 'refs/tags')
with:
path: artifacts/*
name: artifacts
release:
name: Release
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
steps:
- name: Get the version
id: get_version
run: 'echo ::set-output name=version::${GITHUB_REF#refs/tags/}'
- uses: actions/download-artifact@v2
with:
name: artifacts
- name: Display structure of downloaded files
run: ls -R
- uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.version }}
release_name: ${{ steps.get_version.outputs.version }}
- name: Upload Linux Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./patat-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_name: patat-${{ steps.get_version.outputs.version }}-linux-x86_64.tar.gz
asset_content_type: application/gzip
- name: Upload MacOS Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./patat-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_name: patat-${{ steps.get_version.outputs.version }}-darwin-x86_64.zip
asset_content_type: application/zip

View File

@ -2,12 +2,8 @@ ARCH=$(shell uname -m)
UNAME=$(shell uname | tr 'A-Z' 'a-z')
PATAT_BINARY=$(HOME)/.local/bin/patat
PATAT_VERSION=$(shell sed -n 's/^Version: *//p' *.cabal)
PATAT_PACKAGE=patat-v$(PATAT_VERSION)-$(UNAME)-$(ARCH)
GHR_VERSION=0.13.0
GHR_NAME=ghr_v$(GHR_VERSION)_$(UNAME)_amd64
GHR_BINARY=$(HOME)/.local/bin/ghr
PATAT_TAG?=v$(shell sed -n 's/^Version: *//p' *.cabal)
PATAT_PACKAGE=patat-$(PATAT_TAG)-$(UNAME)-$(ARCH)
UPX_VERSION=3.94
UPX_NAME=upx-$(UPX_VERSION)-amd64_$(UNAME)
@ -42,14 +38,17 @@ COMPRESS_BIN=upx
endif
# Default target.
.PHONY: build
build: $(PATAT_BINARY)
# Upload a release.
release: $(PATAT_PACKAGE).$(ARCHIVE) $(GHR_BINARY)
ghr -u jaspervdj -r patat v$(PATAT_VERSION) $(PATAT_PACKAGE).$(ARCHIVE)
# When we want to do a release.
.PHONY: artifact
artifact: $(PATAT_PACKAGE).$(ARCHIVE)
mkdir -p artifacts
cp $(PATAT_PACKAGE).$(ARCHIVE) artifacts/
$(PATAT_PACKAGE).$(ARCHIVE): $(PATAT_BINARY) extra/patat.1 $(COMPRESS_BIN_DEPS)
mkdir $(PATAT_PACKAGE)
mkdir -p $(PATAT_PACKAGE)
cp $(PATAT_BINARY) $(PATAT_PACKAGE)/
$(COMPRESS_BIN) $(PATAT_PACKAGE)/patat
cp README.md $(PATAT_PACKAGE)/
@ -59,15 +58,7 @@ $(PATAT_PACKAGE).$(ARCHIVE): $(PATAT_BINARY) extra/patat.1 $(COMPRESS_BIN_DEPS)
$(ARCHIVE_CREATE) $(PATAT_PACKAGE).$(ARCHIVE) $(PATAT_PACKAGE)
$(PATAT_BINARY):
stack build -j1 --copy-bins --pedantic
# GHR is used to upload releases to GitHub.
$(GHR_BINARY):
curl -Lo /tmp/$(GHR_NAME).$(ARCHIVE) \
https://github.com/tcnksm/ghr/releases/download/v$(GHR_VERSION)/$(GHR_NAME).$(ARCHIVE)
cd /tmp && $(ARCHIVE_EXTRACT) $(GHR_NAME).$(ARCHIVE)
mv /tmp/$(GHR_NAME)/ghr $(GHR_BINARY)
ghr --version
stack build --system-ghc --copy-bins --pedantic
# UPX is used to compress the resulting binary. We currently don't use this on
# Mac OS.

View File

@ -1,19 +1,20 @@
-- | This script generates a man page for patat.
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative ((<$>))
import Control.Exception (throw)
import Control.Monad (guard)
import Control.Monad.Trans (liftIO)
import Data.Char (isSpace, toLower)
import Data.List (isPrefixOf)
import qualified Data.Map as M
import Data.Maybe (isJust)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Time as Time
import qualified GHC.IO.Encoding as Encoding
import Prelude
import System.Environment (getEnv)
import qualified System.IO as IO
import qualified Data.Time as Time
import Text.DocTemplates as DT
import qualified Text.Pandoc as Pandoc
getVersion :: IO String
@ -54,7 +55,7 @@ toSections level = go
fromSections :: Sections -> [Pandoc.Block]
fromSections = concatMap $ \(level, title, blocks) ->
Pandoc.Header level ("", [], []) [Pandoc.Str $ T.unpack title] : blocks
Pandoc.Header level ("", [], []) [Pandoc.Str title] : blocks
reorganizeSections :: Pandoc.Pandoc -> Pandoc.Pandoc
reorganizeSections (Pandoc.Pandoc meta0 blocks0) =
@ -89,6 +90,9 @@ reorganizeSections (Pandoc.Pandoc meta0 blocks0) =
lookupSection name sections =
[section | section@(_, n, _) <- sections, name == n]
simpleContext :: [(T.Text, T.Text)] -> DT.Context T.Text
simpleContext = DT.toContext . M.fromList
main :: IO ()
main = Pandoc.runIOorExplode $ do
liftIO $ Encoding.setLocaleEncoding Encoding.utf8
@ -99,18 +103,18 @@ main = Pandoc.runIOorExplode $ do
source <- liftIO $ T.readFile "README.md"
pandoc0 <- Pandoc.readMarkdown readerOptions source
template <- Pandoc.getDefaultTemplate "man"
template <- Pandoc.compileDefaultTemplate "man"
version <- liftIO getVersion
date <- liftIO getPrettySourceDate
version <- T.pack <$> liftIO getVersion
date <- T.pack <$> liftIO getPrettySourceDate
let writerOptions = Pandoc.def
{ Pandoc.writerTemplate = Just template
, Pandoc.writerVariables =
, Pandoc.writerVariables = simpleContext
[ ("author", "Jasper Van der Jeugt")
, ("title", "patat manual")
, ("date", date)
, ("footer", "patat v" ++ version)
, ("footer", "patat v" <> version)
, ("section", "1")
]
}

View File

@ -5,11 +5,10 @@ module Data.Aeson.Extended
, FlexibleNum (..)
) where
import Control.Applicative ((<$>))
import Data.Aeson
import qualified Data.Text as T
import Text.Read (readMaybe)
import Prelude
import Text.Read (readMaybe)
-- | This can be parsed from a JSON string in addition to a JSON number.
newtype FlexibleNum a = FlexibleNum {unFlexibleNum :: a}

View File

@ -8,14 +8,13 @@ module Patat.Main
--------------------------------------------------------------------------------
import Control.Applicative ((<$>), (<*>))
import Control.Concurrent (forkIO, killThread, threadDelay)
import Control.Concurrent.Chan (Chan)
import qualified Control.Concurrent.Chan as Chan
import Control.Exception (bracket)
import Control.Monad (forever, unless, when)
import qualified Data.Aeson.Extended as A
import Data.Monoid (mempty, (<>))
import qualified Data.Text as T
import Data.Time (UTCTime)
import Data.Version (showVersion)
import qualified Options.Applicative as OA
@ -121,7 +120,7 @@ main = do
when (oVersion options) $ do
putStrLn (showVersion Paths_patat.version)
putStrLn $ "Using pandoc: " ++ Pandoc.pandocVersion
putStrLn $ "Using pandoc: " ++ T.unpack Pandoc.pandocVersion
exitSuccess
filePath <- case oFilePath options of

View File

@ -11,13 +11,11 @@ module Patat.Presentation.Display
--------------------------------------------------------------------------------
import Control.Applicative ((<$>))
import Control.Monad (mplus, unless)
import qualified Data.Aeson.Extended as A
import Data.Data.Extended (grecQ)
import qualified Data.List as L
import Data.Maybe (fromMaybe)
import Data.Monoid (mconcat, mempty, (<>))
import qualified Data.Text as T
import Patat.Cleanup
import qualified Patat.Images as Images
@ -107,7 +105,7 @@ displayPresentation mbImages pres@Presentation {..} =
Just (ActiveContent fragment)
| Just images <- mbImages
, Just image <- onlyImage fragment ->
displayImage images image
displayImage images $ T.unpack image
Just (ActiveContent fragment) ->
displayWithBorders pres $ \_canvasSize theme ->
prettyFragment theme fragment
@ -229,7 +227,7 @@ prettyBlock theme@Theme {..} (Pandoc.OrderedList _ bss) = PP.vcat
| i <- [1 .. length bss]
]
prettyBlock _theme (Pandoc.RawBlock _ t) = PP.string t <> PP.hardline
prettyBlock _theme (Pandoc.RawBlock _ t) = PP.text t <> PP.hardline
prettyBlock _theme Pandoc.HorizontalRule = "---"
@ -289,7 +287,7 @@ prettyInline :: Theme -> Pandoc.Inline -> PP.Doc
prettyInline _theme Pandoc.Space = PP.space
prettyInline _theme (Pandoc.Str str) = PP.string str
prettyInline _theme (Pandoc.Str str) = PP.text str
prettyInline theme@Theme {..} (Pandoc.Emph inlines) =
themed themeEmph $
@ -301,13 +299,13 @@ prettyInline theme@Theme {..} (Pandoc.Strong inlines) =
prettyInline Theme {..} (Pandoc.Code _ txt) =
themed themeCode $
PP.string (" " <> txt <> " ")
PP.text (" " <> txt <> " ")
prettyInline theme@Theme {..} link@(Pandoc.Link _attrs text (target, _title))
| isReferenceLink link =
"[" <> themed themeLinkText (prettyInlines theme text) <> "]"
| otherwise =
"<" <> themed themeLinkTarget (PP.string target) <> ">"
"<" <> themed themeLinkTarget (PP.text target) <> ">"
prettyInline _theme Pandoc.SoftBreak = PP.softline
@ -322,16 +320,16 @@ prettyInline theme@Theme {..} (Pandoc.Quoted Pandoc.DoubleQuote t) =
"'" <> themed themeQuoted (prettyInlines theme t) <> "'"
prettyInline Theme {..} (Pandoc.Math _ t) =
themed themeMath (PP.string t)
themed themeMath (PP.text t)
prettyInline theme@Theme {..} (Pandoc.Image _attrs text (target, _title)) =
"![" <> themed themeImageText (prettyInlines theme text) <> "](" <>
themed themeImageTarget (PP.string target) <> ")"
themed themeImageTarget (PP.text target) <> ")"
-- These elements aren't really supported.
prettyInline theme (Pandoc.Cite _ t) = prettyInlines theme t
prettyInline theme (Pandoc.Span _ t) = prettyInlines theme t
prettyInline _theme (Pandoc.RawInline _ t) = PP.string t
prettyInline _theme (Pandoc.RawInline _ t) = PP.text t
prettyInline theme (Pandoc.Note t) = prettyBlocks theme t
prettyInline theme (Pandoc.Superscript t) = prettyInlines theme t
prettyInline theme (Pandoc.Subscript t) = prettyInlines theme t
@ -357,10 +355,10 @@ prettyReferences theme@Theme {..} =
"[" <>
themed themeLinkText (prettyInlines theme $ Pandoc.newlineToSpace text) <>
"](" <>
themed themeLinkTarget (PP.string target) <>
(if null title
themed themeLinkTarget (PP.text target) <>
(if T.null title
then mempty
else PP.space <> "\"" <> PP.string title <> "\"")
else PP.space <> "\"" <> PP.text title <> "\"")
<> ")"
prettyReference _ = mempty
@ -376,5 +374,5 @@ isReferenceLink _ = False
isVisibleBlock :: Pandoc.Block -> Bool
isVisibleBlock Pandoc.Null = False
isVisibleBlock (Pandoc.RawBlock (Pandoc.Format "html") t) =
not ("<!--" `L.isPrefixOf` t && "-->" `L.isSuffixOf` t)
not ("<!--" `T.isPrefixOf` t && "-->" `T.isSuffixOf` t)
isVisibleBlock _ = True

View File

@ -9,7 +9,6 @@ module Patat.Presentation.Display.CodeBlock
--------------------------------------------------------------------------------
import Data.Maybe (mapMaybe)
import Data.Monoid (mconcat, (<>))
import qualified Data.Text as T
import Patat.Presentation.Display.Table (themed)
import qualified Patat.PrettyPrint as PP
@ -19,16 +18,16 @@ import qualified Skylighting as Skylighting
--------------------------------------------------------------------------------
highlight :: [String] -> String -> [Skylighting.SourceLine]
highlight :: [T.Text] -> T.Text -> [Skylighting.SourceLine]
highlight classes rawCodeBlock = case mapMaybe getSyntax classes of
[] -> zeroHighlight rawCodeBlock
(syn : _) ->
case Skylighting.tokenize config syn (T.pack rawCodeBlock) of
case Skylighting.tokenize config syn rawCodeBlock of
Left _ -> zeroHighlight rawCodeBlock
Right sl -> sl
where
getSyntax :: String -> Maybe Skylighting.Syntax
getSyntax c = Skylighting.lookupSyntax (T.pack c) syntaxMap
getSyntax :: T.Text -> Maybe Skylighting.Syntax
getSyntax c = Skylighting.lookupSyntax c syntaxMap
config :: Skylighting.TokenizerConfig
config = Skylighting.TokenizerConfig
@ -44,13 +43,13 @@ highlight classes rawCodeBlock = case mapMaybe getSyntax classes of
-- | This does fake highlighting, everything becomes a normal token. That makes
-- things a bit easier, since we only need to deal with one cases in the
-- renderer.
zeroHighlight :: String -> [Skylighting.SourceLine]
zeroHighlight str =
[[(Skylighting.NormalTok, T.pack line)] | line <- lines str]
zeroHighlight :: T.Text -> [Skylighting.SourceLine]
zeroHighlight txt =
[[(Skylighting.NormalTok, line)] | line <- T.lines txt]
--------------------------------------------------------------------------------
prettyCodeBlock :: Theme -> [String] -> String -> PP.Doc
prettyCodeBlock :: Theme -> [T.Text] -> T.Text -> PP.Doc
prettyCodeBlock theme@Theme {..} classes rawCodeBlock =
PP.vcat (map blockified sourceLines) <>
PP.hardline

View File

@ -11,7 +11,6 @@ module Patat.Presentation.Display.Table
--------------------------------------------------------------------------------
import Data.List (intersperse, transpose)
import Data.Monoid (mconcat, mempty, (<>))
import Patat.PrettyPrint ((<$$>))
import qualified Patat.PrettyPrint as PP
import Patat.Theme (Theme (..))

View File

@ -4,16 +4,15 @@
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE OverloadedStrings #-}
module Patat.Presentation.Fragment
( FragmentSettings (..)
, fragmentBlocks
, fragmentBlock
) where
import Data.Foldable (Foldable)
import Data.List (foldl', intersperse)
import Data.Maybe (fromMaybe)
import Data.Traversable (Traversable)
import Prelude
import qualified Text.Pandoc as Pandoc

View File

@ -34,8 +34,6 @@ import qualified Data.Aeson.TH.Extended as A
import qualified Data.Foldable as Foldable
import Data.List (intercalate)
import Data.Maybe (fromMaybe, listToMaybe)
import Data.Monoid (Monoid (..))
import Data.Semigroup (Semigroup (..))
import qualified Data.Text as T
import qualified Patat.Theme as Theme
import Prelude

View File

@ -14,7 +14,6 @@ import Control.Monad.Trans (liftIO)
import qualified Data.Aeson as A
import qualified Data.HashMap.Strict as HMS
import Data.Maybe (fromMaybe)
import Data.Monoid (mempty, (<>))
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T

View File

@ -44,13 +44,9 @@ import Control.Monad.Reader (asks, local)
import Control.Monad.RWS (RWS, runRWS)
import Control.Monad.State (get, gets, modify)
import Control.Monad.Writer (tell)
import Data.Foldable (Foldable)
import qualified Data.List as L
import Data.Monoid (Monoid, mconcat, mempty)
import Data.Semigroup (Semigroup (..))
import Data.String (IsString (..))
import qualified Data.Text as T
import Data.Traversable (Traversable, traverse)
import Prelude hiding (null)
import qualified System.Console.ANSI as Ansi
import qualified System.IO as IO

View File

@ -23,8 +23,6 @@ import Data.Colour.SRGB (RGB(..), sRGB24reads, toSRGB24)
import Data.List (intercalate, isPrefixOf, isSuffixOf)
import qualified Data.Map as M
import Data.Maybe (mapMaybe, maybeToList)
import Data.Monoid (Monoid (..))
import Data.Semigroup (Semigroup (..))
import qualified Data.Text as T
import Numeric (showHex)
import Prelude

View File

@ -32,9 +32,9 @@ Library
Build-depends:
aeson >= 0.9 && < 1.5,
ansi-terminal >= 0.6 && < 0.10,
ansi-terminal >= 0.6 && < 0.11,
ansi-wl-pprint >= 0.6 && < 0.7,
base >= 4.8 && < 5,
base >= 4.9 && < 5,
base64-bytestring >= 1.0 && < 1.1,
bytestring >= 0.10 && < 0.11,
colour >= 2.3 && < 2.4,
@ -43,7 +43,7 @@ Library
filepath >= 1.4 && < 1.5,
mtl >= 2.2 && < 2.3,
optparse-applicative >= 0.12 && < 0.16,
pandoc >= 2.0.4 && < 2.8,
pandoc >= 2.9 && < 2.10,
process >= 1.6 && < 1.7,
skylighting >= 0.1 && < 0.9,
terminal-size >= 0.3 && < 0.4,
@ -105,9 +105,11 @@ Executable patat-make-man
Buildable: False
Build-depends:
base >= 4.8 && < 5,
base >= 4.9 && < 5,
containers >= 0.6 && < 0.7,
doctemplates >= 0.8 && < 0.9,
mtl >= 2.2 && < 2.3,
pandoc >= 2.0 && < 2.8,
pandoc >= 2.9 && < 2.10,
text >= 1.2 && < 1.3,
time >= 1.6 && < 1.10

View File

@ -1,4 +1,4 @@
resolver: 'lts-14.6'
resolver: 'lts-15.6'
save-hackage-creds: false
packages:

12
stack.yaml.lock Normal file
View File

@ -0,0 +1,12 @@
# This file was autogenerated by Stack.
# You should not edit this file by hand.
# For more information, please see the documentation at:
# https://docs.haskellstack.org/en/stable/lock_files
packages: []
snapshots:
- completed:
size: 491387
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/15/6.yaml
sha256: 8d81505a6de861e167a58534ab62330afb75bfa108735c7db1204f7ef2a39d79
original: lts-15.6