-
Notifications
You must be signed in to change notification settings - Fork 85
/
Taskfile.yml
221 lines (194 loc) · 6.55 KB
/
Taskfile.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# https://taskfile.dev/#/installation
version: '3'
includes:
openapi-utilities:
taskfile: projects/openapi-utilities/Taskfile.yml
dir: projects/openapi-utilities
tasks:
default:
desc: Perform a clean build
cmds:
- task: setup
- task: clean
- task: build
setup:
desc: Install dependencies
cmds:
- yarn install
build:
desc: Build
cmds:
- yarn workspaces foreach -Apv --topological-dev --no-private run build
clean:
desc: Clean
cmds:
- yarn workspaces foreach -Apv --no-private run clean
lint:
desc: Lint
cmds:
- yarn run lint
test:
desc: Test
cmds:
- yarn workspaces foreach -Av --no-private run test {{.CLI_ARGS}}
update-snapshots:
desc: Update snapshots
cmds:
- yarn workspaces foreach -Av --no-private run test -u
publish:
desc: "Publish built artifacts. Passes CLI_ARGS to 'npm publish'"
cmds:
- yarn workspaces foreach -Av --no-private npm publish --access public {{.CLI_ARGS}}
#
# container image build tasks
#
docker:setup:
cmds:
- >
docker buildx create
--name optic-multiplatform-builder
--platform linux/amd64,linux/arm64
--driver-opt network=host
status:
- docker buildx ls | grep -Eq optic-multiplatform-builder
docker:registry:start:
cmds:
- docker run --name=registry --rm --detach --publish=5000:5000 registry:2
status:
- docker ps --filter "name=registry" | grep -Eq registry
docker:registry:stop:
cmds: ["docker stop registry"]
docker:build:local:
desc: Build an Optic image for your platform
summary: |
Build an Optic image and publish to a locally-running registry for testing.
This is useful for building and inspecting the Optic image locally
without needing to publish to an external registry. A multi-arch image
is built and published to `localhost:5000/useoptic/optic:local`.
Builds intended for publishing should use `docker:build:release`.
example:
task docker:build:local OPTIC_CLI_VERSION=latest
deps:
- docker:setup
- docker:registry:start
vars:
OPTIC_CLI_VERSION: '{{.OPTIC_CLI_VERSION | default "latest"}}'
env:
OPTIC_CLI_VERSION: '{{.OPTIC_CLI_VERSION | default "latest"}}'
cmds:
- >
docker buildx build --push {{.CLI_ARGS}}
--tag localhost:5000/useoptic/optic:local
--tag localhost:5000/useoptic/optic:${OPTIC_CLI_VERSION%.*}
--platform linux/amd64,linux/arm64
--builder optic-multiplatform-builder
--build-arg OPTIC_CLI_VERSION={{.OPTIC_CLI_VERSION}}
.
# ensure we have the latest image pulled from the registry, easy to forget to do this
- docker pull localhost:5000/useoptic/optic:local
docker:build:release:
desc: Build an Optic image for all supported platforms, suitable for publishing
summary: |
Build an Optic image for all supported platforms.
The version of Optic installed and the image tag is determined by the value of OPTIC_CLI_VERSION.
.CLI_ARGS are appended to the command. To publish images to DockerHub include `--push`.
example:
task docker:build:release OPTIC_CLI_VERSION=v0.43.5 -- --push
task docker:build:release OPTIC_CLI_VERSION=latest -- --push
Note that `OPTIC_CLI_VERSION` should match a tag from a published release at https://github.com/opticdev/optic/releases.
The only exception is `latest` which will resolve to the Optic's most recent stable release.
deps:
- docker:setup
vars:
OPTIC_CLI_VERSION: '{{.OPTIC_CLI_VERSION | default "latest"}}'
env:
OPTIC_CLI_VERSION: '{{.OPTIC_CLI_VERSION | default "latest"}}'
cmds:
- >
set -x;
docker buildx build {{.CLI_ARGS}}
--tag docker.io/useoptic/optic:{{.OPTIC_CLI_VERSION}}
--tag docker.io/useoptic/optic:${OPTIC_CLI_VERSION%.*}
--tag docker.io/useoptic/optic:latest
--tag public.ecr.aws/optic/optic:{{.OPTIC_CLI_VERSION}}
--tag public.ecr.aws/optic/optic:${OPTIC_CLI_VERSION%.*}
--tag public.ecr.aws/optic/optic:latest
--platform linux/amd64,linux/arm64
--builder optic-multiplatform-builder
--build-arg OPTIC_CLI_VERSION={{.OPTIC_CLI_VERSION}}
.
#
# SEA packaging
#
pkg:build:
dir: projects/optic
deps:
- setup
cmds:
- task: build
- npx --yes pkg package.json {{.CLI_ARGS}}
- task: pkg:rename
pkg:rename:
cmds:
# rename linuxstatic to linux
- |
for file in $(find ./dist -maxdepth 1 -iname '*linuxstatic*'); do
new_name=${file//linuxstatic/linux}
mv "$file" "$new_name"
done
# rename macos to darwin
- |
for file in $(find ./dist -maxdepth 1 -iname '*macos*'); do
new_name=${file//macos/darwin}
mv "$file" "$new_name"
done
# rename win to windows
- |
for file in $(find ./dist -maxdepth 1 -iname '*-win-*'); do
new_name=${file//win/windows}
mv "$file" "$new_name"
done
# rename x64 to amd64
- |
for file in $(find ./dist -maxdepth 1 -iname '*x64*'); do
new_name=${file//x64/amd64}
mv "$file" "$new_name"
done
- ls -l dist
pkg:clean:
cmds:
- rm -rf dist/*
pkg:archive:
cmds:
- mkdir -p dist/archives
- |
for bin in $(find ./dist -maxdepth 1 -type f); do
name=$(basename "$bin")
tar -czvf ./dist/archives/${name}.tar.gz -C dist $name
done
# rename windows archives from `optic-windows-amd64.exe.tar.gz` to `optic-windows-amd64.tar.gz`
- |
for file in ./dist/archives/*; do
[[ "$file" =~ "\.exe" ]] && mv "$file" "${file/\.exe/}"
done
- bash .github/scripts/create-checksums.sh
- ls -la ./dist/archives
pkg:upload:
cmds:
- gh release upload {{ .RELEASE_TAG }} ./dist/archives/*
#
# utility tasks
#
# `yarn version prerelease` won't increment the prerelease identifier when its already set
# to a prerelease version 🤔. this is our big hammer solution to arbitrarily set the version.
version:force:
summary: |
Usage: task version:force VERSION=0.0.0-0
vars:
VERSION: '{{default "SET_VERSION" .VERSION}}'
cmds:
- |
for pkgjson in $(find . -maxdepth 3 -name package.json -type f -not -path "./node_modules/*"); do
jq '.version |= "{{.VERSION}}"' "$pkgjson" > "${pkgjson}.tmp"
mv "${pkgjson}.tmp" "$pkgjson"
done