This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
toast.yml
191 lines (165 loc) · 4.73 KB
/
toast.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
image: ubuntu:18.04
default: build
tasks:
prepare_system:
description: Install system packages and set up a non-root user.
command: |
set -euo pipefail
# Create a non-root user.
adduser --disabled-password --gecos '' user
# Set up a directory for the non-root user's executables.
mkdir -p /home/user/.local/bin
chown user /home/user/.local/bin
echo 'export PATH="/home/user/.local/bin:$PATH"' >> /home/user/.profile
# Install system packages.
apt-get update
apt-get install --yes build-essential curl ruby
# Without this, Ruby will assume files are encoded as ASCII.
echo 'export LANG="C.UTF-8"' >> /home/user/.profile
# Install Stack.
curl -sSL https://get.haskellstack.org/ | sh
install_tools:
description: Install the tools needed to build, test, lint, and format Haskell programs.
dependencies:
- prepare_system
user: user
command: |
set -euo pipefail
# Download a resolver and set up the Stack user configuration.
stack --resolver lts-12.14 setup
# Tell Stack to install other executables in `$HOME/.local/bin`.
echo 'local-bin-path: /home/user/.local/bin' >> \
/home/user/.stack/config.yaml
# Install a formatter and linter.
stack install hindent hlint
fetch_dependencies:
description: Download and compile dependencies.
dependencies:
- install_tools
input_paths:
- package.yaml
- stack.yaml
- stack.yaml.lock
user: user
command: |
set -euo pipefail
# Set up an empty project to build just to cache the dependencies for the real codebase.
touch README.md
mkdir app src test
echo 'module Main (main) where main :: IO (); main = pure ()' > \
app/Main.hs
echo 'main :: IO (); main = pure ()' > \
test/Spec.hs
stack --allow-different-user build
stack --allow-different-user test
# Remove build artifacts for the empty project. This will force Stack/GHC to rebuild the
# project, which is a workaround for an issue in which Stack/GHC does not detect when source
# files are changed.
stack --allow-different-user clean
build:
description: Build the program.
dependencies:
- fetch_dependencies
input_paths:
- app
- src
user: user
command: |
set -euo pipefail
# Build the program.
stack --allow-different-user build
run:
description: Run the program.
dependencies:
- build
user: user
command: |
set -euo pipefail
# Run the program.
stack --allow-different-user exec effects-exe
test:
description: Run the test suite.
dependencies:
- build
input_paths:
- test
user: user
command: |
set -euo pipefail
# Run the test suite.
stack --allow-different-user test
lint:
description: Lint the code.
dependencies:
- fetch_dependencies
input_paths:
- app
- scripts
- src
- test
- toast.yml
user: user
command: |
set -euo pipefail
# Make sure (a) `$PATH` contains `/home/user/.local/bin` and (b) the `LANG` environment
# variable is set for Ruby.
source ~/.profile
# Run the Haskell linter.
hlint .
# Run the general linter.
./scripts/lint-general.rb $(
find . -type d \( \
-path ./.git -o \
-path ./.stack-work \
\) -prune -o \( \
-name '*.hs' -o \
-name '*.rb' -o \
-name '*.sh' -o \
-name '*.yml' -o \
-name 'Dockerfile' -o \
-name 'Makefile' \
\) -print
)
# Check that the code is correctly formatted.
for file in $(
find . -type d \( \
-path ./.git -o \
-path ./.stack-work \
\) -prune -o \( \
-name '*.hs' \
\) -print \
); do
cat "$file" | hindent > "$file.tmp"
(cmp "$file.tmp" "$file" && rm "$file.tmp") ||
(rm "$file.tmp" && false) || exit 1
done
format:
description: Format the code.
dependencies:
- fetch_dependencies
input_paths:
- app
- src
- test
output_paths:
- app
- src
- test
user: user
command: |
set -euo pipefail
# Make sure `$PATH` contains `/home/user/.local/bin`.
source ~/.profile
# Format the code.
for file in $(
find . -type d \( \
-path ./.git -o \
-path ./.stack-work \
\) -prune -o \( \
-name '*.hs' \
\) -print \
); do
cat "$file" | hindent > "$file.tmp"
(cmp --quiet "$file.tmp" "$file" && rm "$file.tmp") ||
mv "$file.tmp" "$file"
done