Skip to content

Commit 1d72e7d

Browse files
committed
Initial project
1 parent 61fc90f commit 1d72e7d

File tree

20 files changed

+859
-43
lines changed

20 files changed

+859
-43
lines changed

.github/workflows/haskell.yml

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
name: Binaries
2+
3+
defaults:
4+
run:
5+
shell: bash
6+
7+
on:
8+
push:
9+
branches:
10+
- main
11+
pull_request:
12+
13+
jobs:
14+
build:
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
ghc: ["9.6.5", "9.8.2"]
21+
os:
22+
- ubuntu-latest
23+
- windows-latest
24+
25+
env:
26+
# Modify this value to "invalidate" the cabal cache.
27+
CABAL_CACHE_VERSION: "hw-prelude/2024-10-21"
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
32+
- uses: haskell-actions/setup@v2
33+
id: setup-haskell
34+
with:
35+
ghc-version: ${{ matrix.ghc }}
36+
cabal-version: '3.10.3.0'
37+
38+
- name: Set some window specific things
39+
if: matrix.os == 'windows-latest'
40+
run: echo 'EXE_EXT=.exe' >> $GITHUB_ENV
41+
42+
- name: Configure project
43+
run: |
44+
cabal configure --enable-tests --enable-benchmarks --write-ghc-environment-files=ghc8.4.4+
45+
cabal build all --enable-tests --enable-benchmarks --dry-run
46+
47+
- name: Cabal cache over S3
48+
uses: action-works/cabal-cache-s3@v1
49+
env:
50+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
51+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52+
with:
53+
region: us-west-2
54+
dist-dir: dist-newstyle
55+
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
56+
threads: 16
57+
archive-uri: ${{ secrets.BINARY_CACHE_URI }}/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
58+
skip: "${{ secrets.BINARY_CACHE_URI == '' }}"
59+
60+
- name: Cabal cache over HTTPS
61+
uses: action-works/cabal-cache-s3@v1
62+
with:
63+
dist-dir: dist-newstyle
64+
store-path: ${{ steps.setup-haskell.outputs.cabal-store }}
65+
threads: 16
66+
archive-uri: https://cache.haskellworks.io/${{ env.CABAL_CACHE_VERSION }}/${{ runner.os }}/${{ matrix.cabal }}/${{ matrix.ghc }}
67+
skip: "${{ secrets.BINARY_CACHE_URI != '' }}"
68+
69+
- name: Build
70+
run: cabal build all --enable-tests --enable-benchmarks
71+
72+
- name: Test
73+
env:
74+
LOCALSTACK_AUTH_TOKEN: ${{ secrets.LOCALSTACK_AUTH_TOKEN }}
75+
run: cabal test all --enable-tests --enable-benchmarks
76+
77+
check:
78+
needs: build
79+
runs-on: ubuntu-latest
80+
outputs:
81+
tag: ${{ steps.tag.outputs.tag }}
82+
83+
steps:
84+
- uses: actions/checkout@v2
85+
86+
- name: Check if cabal project is sane
87+
run: |
88+
PROJECT_DIR=$PWD
89+
mkdir -p $PROJECT_DIR/build/sdist
90+
for i in $(git ls-files | grep '\.cabal'); do
91+
cd $PROJECT_DIR && cd `dirname $i`
92+
cabal check
93+
done
94+
95+
- name: Tag new version
96+
id: tag
97+
if: ${{ github.ref == 'refs/heads/main' }}
98+
env:
99+
server: http://hackage.haskell.org
100+
username: ${{ secrets.HACKAGE_USER }}
101+
password: ${{ secrets.HACKAGE_PASS }}
102+
run: |
103+
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)"
104+
105+
echo "Package version is v$package_version"
106+
107+
git fetch --unshallow origin
108+
109+
if git tag "v$package_version"; then
110+
echo "Tagging with new version "v$package_version""
111+
112+
if git push origin "v$package_version"; then
113+
echo "Tagged with new version "v$package_version""
114+
115+
echo "::set-output name=tag::v$package_version"
116+
fi
117+
fi
118+
119+
release:
120+
needs: [build, check]
121+
runs-on: ubuntu-latest
122+
if: ${{ needs.check.outputs.tag != '' }}
123+
outputs:
124+
upload_url: ${{ steps.create_release.outputs.upload_url }}
125+
126+
steps:
127+
- uses: actions/checkout@v2
128+
129+
- name: Create source distribution
130+
run: |
131+
PROJECT_DIR=$PWD
132+
mkdir -p $PROJECT_DIR/build/sdist
133+
for i in $(git ls-files | grep '\.cabal'); do
134+
cd $PROJECT_DIR && cd `dirname $i`
135+
cabal v2-sdist -o $PROJECT_DIR/build/sdist
136+
done;
137+
138+
- name: Publish to hackage
139+
env:
140+
server: http://hackage.haskell.org
141+
username: ${{ secrets.HACKAGE_USER }}
142+
password: ${{ secrets.HACKAGE_PASS }}
143+
candidate: false
144+
run: |
145+
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)"
146+
147+
for PACKAGE_TARBALL in $(find ./build/sdist/ -name "*.tar.gz"); do
148+
PACKAGE_NAME=$(basename ${PACKAGE_TARBALL%.*.*})
149+
150+
if ${{ env.candidate }}; then
151+
TARGET_URL="${{ env.server }}/packages/candidates";
152+
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/candidate/docs"
153+
else
154+
TARGET_URL="${{ env.server }}/packages/upload";
155+
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/docs"
156+
fi
157+
158+
HACKAGE_STATUS=$(curl --silent --head -w %{http_code} -XGET --anyauth --user "${{ env.username }}:${{ env.password }}" ${{ env.server }}/package/$PACKAGE_NAME -o /dev/null)
159+
160+
if [ "$HACKAGE_STATUS" = "404" ]; then
161+
echo "Uploading $PACKAGE_NAME to $TARGET_URL"
162+
163+
curl -X POST -f --user "${{ env.username }}:${{ env.password }}" $TARGET_URL -F "package=@$PACKAGE_TARBALL"
164+
echo "Uploaded $PACKAGE_NAME"
165+
else
166+
echo "Package $PACKAGE_NAME" already exists on Hackage.
167+
fi
168+
done
169+
170+
- name: Create Release
171+
id: create_release
172+
uses: actions/create-release@v1
173+
env:
174+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
175+
with:
176+
tag_name: ${{ github.ref }}
177+
release_name: Release ${{ github.ref }}
178+
body: Undocumented
179+
draft: true
180+
prerelease: false

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Revision history for hw-polysemy
1+
# Revision history for hw-prelude
22

33
## 0.1.0.0 -- YYYY-mm-dd
44

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Opinionated prelude library

cabal.project

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
packages: .
2+
3+
allow-newer:
4+
base,
5+
bytestring,
6+
7+
package testcontainers
8+
ghc-options: -XDuplicateRecordFields
9+
10+
package amazonka
11+
ghc-options: -XDuplicateRecordFields
12+
13+
package amazonka-s3
14+
ghc-options: -XDuplicateRecordFields
15+
16+
package amazonka-sso
17+
ghc-options: -XDuplicateRecordFields
18+
19+
package amazonka-sts
20+
ghc-options: -XDuplicateRecordFields

hw-polysemy.cabal

Lines changed: 0 additions & 37 deletions
This file was deleted.

hw-prelude.cabal

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
cabal-version: 3.4
2+
name: hw-prelude
3+
version: 0.0.0.1
4+
synopsis: Opinionated prelude library
5+
description: Opinionated prelude library.
6+
license: Apache-2.0
7+
license-file: LICENSE
8+
author: John Ky
9+
maintainer: [email protected]
10+
copyright: 2024 John Ky
11+
category: Development
12+
build-type: Simple
13+
extra-doc-files: CHANGELOG.md
14+
extra-source-files: README.md
15+
16+
source-repository head
17+
type: git
18+
location: https://github.com/haskell-works/hw-prelude
19+
20+
common base { build-depends: base >= 4.13 && < 5 }
21+
22+
common async { build-depends: async < 2.3 }
23+
common bytestring { build-depends: bytestring < 0.13 }
24+
common contravariant { build-depends: contravariant < 1.6 }
25+
common directory { build-depends: directory < 1.4 }
26+
common filepath { build-depends: filepath < 1.6 }
27+
common network { build-depends: network < 3.3 }
28+
common process { build-depends: process < 1.7 }
29+
common resourcet { build-depends: resourcet < 1.4 }
30+
common text { build-depends: text < 3 }
31+
common unliftio { build-depends: unliftio < 0.3 }
32+
33+
common hw-prelude { build-depends: hw-prelude }
34+
35+
common Win32
36+
if os(windows)
37+
build-depends: Win32 >= 2.5.4.1
38+
39+
flag werror
40+
description: Enable -Werror
41+
manual: True
42+
default: False
43+
44+
common project-config
45+
default-language: Haskell2010
46+
default-extensions: BlockArguments
47+
DataKinds
48+
DeriveGeneric
49+
DuplicateRecordFields
50+
FlexibleContexts
51+
FlexibleInstances
52+
LambdaCase
53+
NoImplicitPrelude
54+
OverloadedStrings
55+
RankNTypes
56+
ScopedTypeVariables
57+
TypeApplications
58+
TypeOperators
59+
ghc-options: -Wall
60+
61+
if flag(werror)
62+
ghc-options: -Werror
63+
64+
library
65+
import: base, project-config,
66+
async,
67+
bytestring,
68+
contravariant,
69+
directory,
70+
filepath,
71+
network,
72+
process,
73+
resourcet,
74+
text,
75+
unliftio,
76+
Win32,
77+
visibility: public
78+
79+
if os(windows)
80+
exposed-modules: HaskellWorks.IO.Win32.NamedPipe
81+
82+
exposed-modules: HaskellWorks.Control.Monad
83+
HaskellWorks.Data.String
84+
HaskellWorks.Error
85+
HaskellWorks.Error.Types
86+
HaskellWorks.IO.Network.NamedPipe
87+
HaskellWorks.IO.Network.Port
88+
HaskellWorks.IO.Network.Socket
89+
HaskellWorks.IO.Process
90+
HaskellWorks.Prelude
91+
HaskellWorks.Unsafe
92+
hs-source-dirs: src

src/HaskellWorks/Control/Monad.hs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
module HaskellWorks.Control.Monad
2+
( repeatNUntilM_,
3+
repeatNWhileM_,
4+
) where
5+
6+
import HaskellWorks.Prelude
7+
8+
-- | Repeat an action n times until the action returns True.
9+
repeatNUntilM_ :: ()
10+
=> Monad m
11+
=> Int
12+
-> (Int -> m Bool)
13+
-> m ()
14+
repeatNUntilM_ n action = go 0
15+
where
16+
go i =
17+
when (i < n) $ do
18+
shouldTerminate <- action i
19+
unless shouldTerminate $ go (i + 1)
20+
21+
-- | Repeat an action n times while the action returns True.
22+
repeatNWhileM_ :: ()
23+
=> Monad m
24+
=> Int
25+
-> (Int -> m Bool)
26+
-> m ()
27+
repeatNWhileM_ n action = go 0
28+
where
29+
go i =
30+
when (i < n) $ do
31+
shouldContinue <- action i
32+
when shouldContinue $ go (i + 1)

src/HaskellWorks/Data/String.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module HaskellWorks.Data.String
2+
( unlines
3+
, unwords
4+
, words
5+
, lines
6+
) where
7+
8+
import Data.String

0 commit comments

Comments
 (0)