Skip to content

Commit

Permalink
Add CI
Browse files Browse the repository at this point in the history
Shamelessly stolen from https://github.com/DigitalBrains1/prettyprinter-interp

Co-authored-by: Peter Lebbing <[email protected]>
  • Loading branch information
martijnbastiaan and DigitalBrains1 committed Feb 24, 2024
1 parent 2b80994 commit b62850c
Show file tree
Hide file tree
Showing 18 changed files with 368 additions and 54 deletions.
32 changes: 32 additions & 0 deletions .ci/all_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Makes sure:
* All jobs are listed in the 'all' job
* Only existing tests are listed
"""

import sys
import yaml

CI_PATH = '.github/workflows/ci.yaml'
ALL_TEST = 'all'


def main():
ci_yaml_fp = open(CI_PATH, 'r')
ci_yaml_parsed = yaml.load(ci_yaml_fp, Loader=yaml.FullLoader)

all_jobs = set(ci_yaml_parsed['jobs'].keys()) - {ALL_TEST}
all_needs = set(ci_yaml_parsed['jobs'][ALL_TEST]['needs'])

if all_jobs - all_needs:
sys.exit(f'Not all jobs mentioned in {ALL_TEST}.needs: '
f'{all_jobs - all_needs}')

if all_needs - all_jobs:
sys.exit(f'Non-existing jobs found in {ALL_TEST}.needs: '
f'{all_needs - all_jobs}')


if __name__ == '__main__':
main()
2 changes: 2 additions & 0 deletions .ci/cabal.project.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package docopt
ghc-options: -Werror
8 changes: 8 additions & 0 deletions .ci/cabal.project.local-lower
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package docopt
ghc-options: -Werror

prefer-oldest: True

constraints:
aeson >= 1.4.4.0,
contravariant >= 1.5.2
37 changes: 37 additions & 0 deletions .ci/cabal.project.local-upper
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package docopt
ghc-options: -Werror

repository head.hackage.ghc.haskell.org
url: https://ghc.gitlab.haskell.org/head.hackage/
secure: True
key-threshold: 3
root-keys:
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89

active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org

-- HEAD.hackage standard allow-newer packages
allow-newer:
Cabal,
base,
binary,
bytestring,
deepseq,
ghc,
ghc-bignum,
ghc-prim,
integer-gmp,
template-haskell,
text,
time

-- Boot packages
constraints:
base installed,
ghc installed,
ghc-bignum installed,
ghc-prim installed,
integer-gmp installed,
template-haskell installed
3 changes: 3 additions & 0 deletions .ci/stack-8.10.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-18.28
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-8.8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-16.31
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-9.0.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-19.33
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-9.2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-20.26
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-9.4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-21.14
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-9.6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: lts-22.11
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
3 changes: 3 additions & 0 deletions .ci/stack-9.8.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resolver: nightly-2024-02-24
ghc-options:
"$locals": -Werror -Wall -Wcompat -Wno-name-shadowing
208 changes: 208 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: CI
on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
# Stack
stack:
name: Stack / GHC ${{ matrix.ghc }}
runs-on: ubuntu-latest
strategy:
matrix:
# TODO: "8.0", "8.2", "8.4", "8.6"
ghc: ["8.8", "8.10", "9.0", "9.2", "9.4", "9.6", "9.8"]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Haskell
uses: haskell-actions/setup@v2
id: setup-haskell
with:
enable-stack: true
stack-no-global: true

- name: General Setup
run: |
cp .ci/stack-${{ matrix.ghc }}.yaml stack.yaml
# Print out some information for debugging purposes
ghc --version
stack --version
cat stack.yaml
- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
with:
path: ${{ steps.setup-haskell.outputs.stack-root }}/snapshots
key:
${{ runner.os }}-stack-${{ matrix.ghc }}-${{
hashFiles('prettyprinter-interp.cabal', 'stack.yaml') }}
restore-keys: ${{ runner.os }}-stack-${{ matrix.ghc }}-

- name: Install dependencies
run: stack build --test --only-dependencies

# Cache dependencies already at this point, so that we do not have to
# rebuild them should the subsequent steps fail
- name: Save cached dependencies
uses: actions/cache/save@v4
# Trying to save over an existing cache gives distracting
# "Warning: Cache save failed." since they are immutable
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup-haskell.outputs.stack-root }}/snapshots
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run : stack build

- name: Test
run : stack test

# Cabal
cabal:
name: Cabal / GHC ${{ matrix.ghc }} ${{ matrix.project-variant }}
runs-on: ubuntu-latest
strategy:
matrix:
ghc:
- "8.0.2"
- "8.2.2"
- "8.4.4"
- "8.6.5"
- "8.8.4"
- "8.10.7"
- "9.0.2"
- "9.0.2"
- "9.2.8"
- "9.4.7"
- "9.6.3"
- "9.8.1"
project-variant: [""]
include:
- ghc: 8.0.2
project-variant: -lower
- ghc: 9.8.1
project-variant: -upper

fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false

- name: Setup Haskell
uses: haskell-actions/setup@v2
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-update: false

- name: General Setup
run: |
cp .ci/cabal.project.local${{ matrix.project-variant}} \
cabal.project.local
# Print out some information for debugging purposes
ghc --version
cabal --version
cat cabal.project.local
- name: Setup CI
# This generates dist-newstyle/cache/plan.json with hashes for all
# dependencies, for cache invalidation.
run: |
cabal v2-update
cabal v2-build all --enable-tests --dry-run
- name: Restore cached dependencies
uses: actions/cache/restore@v4
id: cache
env:
key:
${{ runner.os }}-ghc-${{ matrix.ghc }}-cabal-${{
steps.setup-haskell.outputs.cabal-version }}${{
matrix.project-variant }}
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key:
${{ env.key }}-${{ hashFiles('cabal.project.local',
'dist-newstyle/cache/plan.json') }}
restore-keys: ${{ env.key }}-

- name: Install dependencies
run: cabal v2-build all --enable-tests --only-dependencies

# Cache dependencies already at this point, so that we do not have to
# rebuild them should the subsequent steps fail
- name: Save cached dependencies
uses: actions/cache/save@v4
# Trying to save over an existing cache gives distracting
# "Warning: Cache save failed." since they are immutable
if: steps.cache.outputs.cache-hit != 'true'
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: ${{ steps.cache.outputs.cache-primary-key }}

- name: Build
run: cabal v2-build all --enable-tests

- name: Test
run: cabal v2-test --enable-tests --test-show-details=direct

# Mechanism copied from https://github.com/clash-lang/clash-compiler/
all:
name: All jobs finished
if: ${{ !cancelled() }}
needs:
- stack
- cabal
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
show-progress: false

- name: Check dependencies for failures
run: |
# Test all dependencies for success/failure
set -x
# True if at least one dependency succeeded
success="${{ contains(needs.*.result, 'success') }}"
# True if at least one dependency failed
fail="${{ contains(needs.*.result, 'failure') }}"
set +x
# Test whether success/fail variables contain sane values
if [[ "${success}" != "true" && "${success}" != "false" ]]; then exit 1; fi
if [[ "${fail}" != "true" && "${fail}" != "false" ]]; then exit 1; fi
# We want to fail if one or more dependencies fail. For safety, we introduce
# a second check: if no dependencies succeeded something weird is going on.
if [[ "${fail}" == "true" || "${success}" == "false" ]]; then
echo "One or more dependency failed, or no dependency succeeded."
exit 1
fi
# Currently, ubuntu-latest already has it installed, but keep it around in
# case they ever change that
#
# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get -y install python3-yaml

- name: Check that the 'all' job depends on all other jobs
run: .ci/all_check.py
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
dist
.cabal-sandbox
cabal.sandbox.config
dist-newstyle/
/cabal.project.local

# GHC config
.ghc.environment.*

# Haskell compiled files
*.hi
Expand Down
24 changes: 13 additions & 11 deletions System/Console/Docopt/OptParse.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{-# OPTIONS_GHC -Wno-unused-do-bind #-}

module System.Console.Docopt.OptParse
where

Expand All @@ -15,7 +17,7 @@ import System.Console.Docopt.Types
-- @fmt@ is the OptPattern together with metadata to tell the parser how to parse args.
-- Together, these let @buildOptParser@ build a parsec parser that can be applied to an argv.
buildOptParser :: String -> OptFormat -> CharParser OptParserState ()
buildOptParser delim fmt@(pattern, infomap) =
buildOptParser delim (pattern, infomap) =

let -- Helpers
argDelim = (try $ string delim) <?> "space between arguments"
Expand Down Expand Up @@ -124,7 +126,7 @@ buildOptParser delim fmt@(pattern, infomap) =
unorderedSynParser = buildOptParser delim (Unordered oneOfSyns, infomap)
in unorderedSynParser
<?> humanize o
o@(Argument name) ->
o@(Argument _name) ->
do val <- try $ many1 (notFollowedBy argDelim >> anyChar)
updateSt_saveOccurrence o val
updateSt_inShortOptStack False
Expand Down Expand Up @@ -157,7 +159,7 @@ saveOccurrence opt info newval argmap = M.alter updateCurrentVal opt argmap
Just oldval -> newval `updateFrom` oldval
updateFrom newval oldval = Just $ case oldval of
MultiValue vs -> MultiValue $ newval : vs
Value v -> Value newval
Value _v -> Value newval
NoValue -> Value newval
Counted n -> Counted (n+1)
Present -> Present
Expand Down Expand Up @@ -185,21 +187,21 @@ optInitialValue :: OptionInfo -> Option -> Maybe ArgValue
optInitialValue info opt =
let repeatable = isRepeated info
in case opt of
Command name -> Just $ if repeatable then Counted 0 else NotPresent
Argument name -> Just $ if repeatable then MultiValue [] else NoValue
AnyOption -> Nothing -- no storable value for [options] shortcut
_ -> case expectsVal info of
Command _name -> Just $ if repeatable then Counted 0 else NotPresent
Argument _name -> Just $ if repeatable then MultiValue [] else NoValue
AnyOption -> Nothing -- no storable value for [options] shortcut
_ -> case expectsVal info of
True -> Just $ if repeatable then MultiValue [] else NoValue
False -> Just $ if repeatable then Counted 0 else NotPresent

optDefaultValue :: OptionInfo -> Option -> Maybe ArgValue
optDefaultValue info opt =
let repeatable = isRepeated info
in case opt of
Command name -> Just $ if repeatable then Counted 0 else NotPresent
Argument name -> Just $ if repeatable then MultiValue [] else NoValue
AnyOption -> Nothing -- no storable value for [options] shortcut
_ -> case expectsVal info of
Command _name -> Just $ if repeatable then Counted 0 else NotPresent
Argument _name -> Just $ if repeatable then MultiValue [] else NoValue
AnyOption -> Nothing -- no storable value for [options] shortcut
_ -> case expectsVal info of
True -> case defaultVal info of
Just dval -> Just $ if repeatable
then MultiValue $ reverse $ words dval
Expand Down
Loading

0 comments on commit b62850c

Please sign in to comment.