-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskfile.yaml
241 lines (216 loc) · 7.71 KB
/
Taskfile.yaml
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
version: "3"
env:
GO111MODULE: on
GOPROXY: https://proxy.golang.org,direct
tasks:
dev:
desc: Install git hooks
cmds:
- cp -f scripts/pre-commit.sh .git/hooks/pre-commit
setup:
desc: Install dependencies
cmds:
- go mod tidy
build:
desc: Build the app
run: when_changed
sources:
- "./**/*.go"
- "go.mod"
- "go.sum"
generates:
- "./papercrypt{{exeExt}}"
cmds:
- go build
test:
desc: Run all tests, including unit, end-to-end, and backwards compatibility
cmds:
- go vet ./...
- task: test:unit
- task: test:e2e
- task: test:backwards
- task: test:raw
- task: clean:test
test:unit:
desc: Run unit tests
vars:
TEST_OPTIONS: '{{default "" .TEST_OPTIONS}}'
SOURCE_FILES: '{{default "./..." .SOURCE_FILES}}'
TEST_PATTERN: '{{default "." .TEST_PATTERN}}'
cmds:
- go test {{.TEST_OPTIONS}} -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt {{.SOURCE_FILES}} -run {{.TEST_PATTERN}} -timeout=5m
test:e2e:
desc: Run end-to-end tests, including generating a PDF, extracting images, finding a QR code, reading a QR code, decoding the document, and comparing to the input
cmds:
# full pipeline test: generate pdf > extract images > scan 2d code > decode document > compare to input
# requires pdftoppm, which can be installed with `sudo apt-get install -y poppler-utils`
# if running on windows, installing it in WSL will allow the `bash -c` commands to work.
- >-
bash -c 'echo "{\"message\":\"Hello, world!\"}" > test-in.json
&& cat test-in.json
| go run . generate --purpose "Test" --comment "Test" --passphrase "test" -o test.pdf --force
&& pdftoppm -png -r 300 test.pdf t'
- >-
bash -c 'cat t-1.png
| go run . scan
| go run . decode -f -o test.json --passphrase "test"
&& diff -u test.json test-in.json
&& echo "Successfully reconstructed input document."'
- >-
bash -c 'cat t-1.png
| go run . scan --to-json
| go run . scan --from-json
| go run . decode -f -o test.json --passphrase "test"
&& diff -u test.json test-in.json
&& echo "Successfully reconstructed input document."'
- >-
bash -c 'rm -f test-in.json test.json t-*.png test.pdf'
test:raw:
cmds:
- >-
bash -c 'echo "{\"message\":\"Hello, world!\"}" > test-in.json
&& cat test-in.json
| go run . generate --purpose "Test" --comment "Test" --raw -o test.pdf -f --passphrase "test"
&& pdftoppm -png -r 300 test.pdf t'
- >-
bash -c 'cat t-1.png
| go run . scan
| go run . decode -f -o test.json --passphrase "test"
&& diff -u test.json test-in.json
&& echo "Successfully reconstructed input document."'
test:backwards:
desc: Run backwards compatibility e2e tests
cmds:
- bash -c 'pdftoppm -png -r 300 examples/v1/output.pdf t'
- >-
bash -c 'cat t-1.png
| go run . qr
| go run . decode -f -o test.json --passphrase "example"
&& diff -u test.json examples/v1/input.json
&& echo "Successfully reconstructed input document."'
cover:
desc: Open the cover tool
cmds:
- go tool cover -html=coverage.txt
fmt:
desc: gofumpt all code
cmds:
- gofumpt -w -l .
lint:
desc: Lint the code with golangci-lint
cmds:
- golangci-lint run ./...
ci:
desc: Run all CI steps
cmds:
- task: setup
- task: build
- task: test
release:
desc: Create a release. Will install goreleaser through go install if not present in PATH.
cmds:
- "npx -p @semantic-release/changelog -p @semantic-release/exec -p @semantic-release/git semantic-release"
reltest:
desc: Create a test release. Will install goreleaser through go install if not present in PATH.
cmds:
- goreleaser release --snapshot --clean --skip=publish,sign
docs:examples:
desc: Run the examples
sources:
- ./**/*.go
- go.mod
- go.sum
- examples/input.json
deps:
- build
generates:
- "examples/output.pdf"
- "examples/no_code.pdf"
- "examples/lowercase.pdf"
- "examples/phrase.pdf"
cmds:
- './papercrypt{{exeExt}} generate -i examples/input.json -o examples/output.pdf --force --passphrase "example" --purpose "Example Sheet" --comment "Regular PDF Example" && pdfcpu validate -m strict examples/output.pdf'
- './papercrypt{{exeExt}} generate -i examples/input.json -o examples/no_code.pdf --force --passphrase "example" --purpose "Example Sheet" --comment "PDF without QR Code Example" --no-qr && pdfcpu validate -m strict examples/no_code.pdf'
- './papercrypt{{exeExt}} generate -i examples/input.json -o examples/lowercase.pdf --force --passphrase "example" --purpose "Example Sheet" --comment "Lowercase PDF Example" --lowercase && pdfcpu validate -m strict examples/lowercase.pdf'
- "./papercrypt{{exeExt}} phrase-sheet -fo examples/phrase.pdf ExampleAbcA= && pdfcpu validate -m strict examples/phrase.pdf"
docs:examples:vhs:
sources:
- ./**/*.go
- go.mod
- go.sum
- examples/demo/*.tape
generates:
- examples/demo/demo.gif
- examples/demo/demo.webm
- examples/demo/generate.gif
- examples/demo/generate.webm
- examples/demo/generate.png
- examples/demo/key.gif
- examples/demo/key.webm
- examples/demo/decode.png
vars:
PWD: '{{ if eq OS "windows" }}${PWD}{{ else }}{{.Env.PWD}}{{ end }}'
cmds:
- task: docs:examples:vhs:render
vars:
FILE: examples/demo/demo.tape
- task: docs:examples:vhs:render
vars:
FILE: examples/demo/generate.tape
- task: docs:examples:vhs:render
vars:
FILE: examples/demo/key.tape
docs:examples:vhs:render:
desc: Render a single frame of a VHS tape
deps:
- docs:examples:vhs:image
vars:
PWD: '{{ if eq OS "windows" }}${PWD}{{ else }}{{.Env.PWD}}{{ end }}'
FILE: '{{default "examples/demo/demo.tape" .FILE}}'
cmds:
- docker run --rm -v {{.PWD}}:/vhs ghcr.io/tmuniversal/papercrypt/vhs {{.FILE}}
docs:examples:vhs:image:
run: when_changed
sources:
- vhs.Dockerfiles
- ./**/*.go
- go.mod
- go.sum
cmds:
- docker build -f vhs.Dockerfile -t ghcr.io/tmuniversal/papercrypt/vhs .
docs:third_party:
desc: Write third-party licenses to THIRD_PARTY.md
deps:
- setup # ensure go modules are downloaded
preconditions:
- sh: bash -c "go-licenses help > /dev/null"
msg: "go-licenses is not installed. Run 'go install github.com/google/go-licenses@latest' to install it."
cmds:
- bash -c "go-licenses report ./... --template=licenses.tpl > THIRD_PARTY.md"
completions:
desc: Generate shell completions. Running on Windows requires Go installed in WSL.
generates:
- completions/papercrypt.bash
- completions/papercrypt.fish
- completions/papercrypt.zsh
cmds:
- bash -c "./scripts/completions.sh"
manpages:
desc: Generate man pages. Running on Windows requires Go installed in WSL.
generates:
- manpages/papercrypt.1.gz
cmds:
- bash -c "./scripts/manpages.sh"
clean:
desc: Remove all generated files
cmds:
- "rm -f *.gen.txt"
- "rm -rf dist bin manpages completions"
clean:examples:
desc: Remove all generated files
cmds:
- "rm -f examples/output.pdf examples/no_code.pdf examples/lowercase.pdf examples/phrase.pdf"
clean:test:
desc: Remove all generated files
cmds:
- "rm -f test-in.json test.json t-*.png test.pdf"