-
-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (168 loc) · 6.52 KB
/
haskell.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Haskell CI
defaults:
run:
shell: bash
on:
push:
branches:
- main
pull_request:
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
cabal: ["3.12"]
ghc: ["9.8.1", "9.6.3", "9.4.8"]
os: [ubuntu-latest, windows-latest]
include:
# Using include, to make sure there will only be one macOS job, even if the matrix gets expanded later on.
# We want a single job, because macOS runners are scarce.
- ghc: "9.6.3"
cabal: "3.12"
os: macos-latest
env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2024-08-05"
steps:
- name: Install Haskell
uses: input-output-hk/actions/haskell@latest
id: setup-haskell
with:
ghc-version: ${{ matrix.ghc }}
cabal-version: ${{ matrix.cabal }}
# - name: Install system dependencies
# uses: input-output-hk/actions/base@latest
# with:
# use-sodium-vrf: true # default is true
- uses: actions/checkout@v4
- name: Cabal update
run: cabal update
- name: Configure build
run: |
cabal configure --enable-tests --enable-benchmarks
cabal build all --enable-tests --enable-benchmarks --dry-run
- name: Record dependencies
run: |
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[].id' | sort | uniq > dependencies.txt
date +"%Y-%m-%d" > date.txt
- name: View dependencies
run: |
echo "date = $(cat date.txt)"
echo "md5(dependencies.txt) = $(md5sum dependencies.txt)"
echo "md5(date.txt) = $(md5sum date.txt)"
- name: Upload dependencies.txt
uses: actions/upload-artifact@v2
with:
name: dependencies
path: dependencies.txt
- uses: actions/cache@v4
name: Cache cabal store
with:
path: ${{ steps.setup-haskell.outputs.cabal-store }}
key: cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}-${{ hashFiles('date.txt') }}
restore-keys: |
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}-${{ hashFiles('date.txt') }}
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('dependencies.txt') }}
cache-${{ env.CACHE_VERSION }}-${{ runner.os }}-${{ matrix.ghc }}
# Now we install the dependencies. If the cache was found and restored in the previous step,
# this should be a no-op, but if the cache key was not found we need to build stuff so we can
# cache it for the next step.
- name: Install dependencies
run: cabal build all --enable-tests --only-dependencies -j --ghc-option=-j4
# Now we build.
- name: Build all
run: cabal build all --enable-tests
- name: Run tests
env:
TMPDIR: ${{ runner.temp }}
TMP: ${{ runner.temp }}
KEEP_WORKSPACE: 1
run: cabal test all --enable-tests --enable-benchmarks
check:
needs: build
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- uses: actions/checkout@v2
- name: Check if cabal project is sane
run: |
PROJECT_DIR=$PWD
mkdir -p $PROJECT_DIR/build/sdist
for i in $(git ls-files | grep '\.cabal'); do
cd $PROJECT_DIR && cd `dirname $i`
cabal check
done
- name: Tag new version
id: tag
if: ${{ github.ref == 'refs/heads/main' }}
env:
server: http://hackage.haskell.org
username: ${{ secrets.HACKAGE_USER }}
password: ${{ secrets.HACKAGE_PASS }}
run: |
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)"
echo "Package version is v$package_version"
git fetch --unshallow origin
if git tag "v$package_version"; then
echo "Tagging with new version "v$package_version""
if git push origin "v$package_version"; then
echo "Tagged with new version "v$package_version""
echo "::set-output name=tag::v$package_version"
fi
fi
release:
needs: [build, check]
runs-on: ubuntu-latest
if: ${{ needs.check.outputs.tag != '' }}
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- uses: actions/checkout@v2
- name: Create source distribution
run: |
PROJECT_DIR=$PWD
mkdir -p $PROJECT_DIR/build/sdist
for i in $(git ls-files | grep '\.cabal'); do
cd $PROJECT_DIR && cd `dirname $i`
cabal v2-sdist -o $PROJECT_DIR/build/sdist
done;
- name: Publish to hackage
env:
server: http://hackage.haskell.org
username: ${{ secrets.HACKAGE_USER }}
password: ${{ secrets.HACKAGE_PASS }}
candidate: false
run: |
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)"
for PACKAGE_TARBALL in $(find ./build/sdist/ -name "*.tar.gz"); do
PACKAGE_NAME=$(basename ${PACKAGE_TARBALL%.*.*})
if ${{ env.candidate }}; then
TARGET_URL="${{ env.server }}/packages/candidates";
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/candidate/docs"
else
TARGET_URL="${{ env.server }}/packages/upload";
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/docs"
fi
HACKAGE_STATUS=$(curl --silent --head -w %{http_code} -XGET --anyauth --user "${{ env.username }}:${{ env.password }}" ${{ env.server }}/package/$PACKAGE_NAME -o /dev/null)
if [ "$HACKAGE_STATUS" = "404" ]; then
echo "Uploading $PACKAGE_NAME to $TARGET_URL"
curl -X POST -f --user "${{ env.username }}:${{ env.password }}" $TARGET_URL -F "package=@$PACKAGE_TARBALL"
echo "Uploaded $PACKAGE_NAME"
else
echo "Package $PACKAGE_NAME" already exists on Hackage.
fi
done
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: Undocumented
draft: true
prerelease: false