-
Notifications
You must be signed in to change notification settings - Fork 2
/
.drone.star
295 lines (258 loc) · 9.96 KB
/
.drone.star
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#
# NOTE: This file is not being used currently due to issues with it not detecting pre-release
# tag pushes. For now we are using the .drone.yml file instead. We will switch back to using this
# script later when we fix the problems.
#
def main(ctx):
# Config used by pipeline functions
config = {}
# The drone context
config["ctx"] = ctx
# The version of rust to use for building Lucky
config["rust_version"] = "nightly-2019-11-24"
pipelines = []
# Skip all pipelines on feature branches to prevent building twice:
# one time for PR and one time for feature branch push.
if ctx.build.branch.startswith("feature/"):
return []
# Add Linux pipelines
pipelines.extend(linux_pipelines(config))
# Add Windows pipelines
pipelines.extend(windows_pipelines(config))
# Add MacOS pipelines
pipelines.extend(macos_pipelines(config))
return pipelines
def linux_pipelines(config):
# ( arch name, rust target, download name ) tuple pairs
archs = [
("amd64", "x86_64-unknown-linux-musl", "x86_64"),
# TODO: Figure out how to make the ARM builds work
# ("arm64", "aarch64-unknown-linux-musl"),
# ("arm", "arm-unknown-linux-musleabi")
]
# Return pipelines for each architecture
return [linux_pipeline(config, arch) for arch in archs]
# Build a linux pipeline for a specific arch
def linux_pipeline(config, arch):
pipeline = {
"kind": "pipeline",
"name": "linux-" + (arch[0]),
}
# Pipeline steps
steps = []
# Build Lucky
steps.append({
"name": "build",
"image": "clux/muslrust:" + config["rust_version"],
"commands": [
# Install rust target for platform
"rustup target add " + arch[1],
# Compile Lucky
"cargo build --release --target " + arch[1],
# Create tarball
"mkdir -p build",
"mv target/" + arch[1] + "/release/lucky build",
"cd build/",
"tar -czf lucky-linux-" + arch[2] + ".tgz lucky"
]
})
# Build Documentation ( only on amd64 just so that we only do it once )
if arch[0] == "amd64":
# Generate CLI documentation
steps.append({
"name": "generate-cli-doc",
"image": "clux/muslrust:" + config["rust_version"],
"depends_on": ["build"], # Wait for build because of cargo target lock
"commands": [
"cargo run --release --features doc-gen docs/book/src/"
]
})
# Build markdown book
steps.append({
"name": "build-book",
"image": "hrektts/mdbook:latest",
"depends_on": ["generate-cli-doc"],
"commands": [
"cd docs/book",
"mdbook build"
]
})
# Publish documentation if pushed to master
if config["ctx"].build.branch == "master":
steps.append({
"name": "publish-book",
"image": "plugins/gh-pages",
"depends_on": ["build-book"],
"settings": {
"pages_directory": "docs/book/build",
"username": {
"from_secret": "github_username",
},
"password": {
"from_secret": "github_access_key"
}
}
})
# Pre-release steps
# TODO: This is not working consistantly on Drone cloud for some reason
if config["ctx"].build.ref == "refs/tags/pre-release":
steps.append({
"name": "publish-github-pre-release",
"image": "plugins/github-release",
"depends_on": ["build"],
"settings": {
"title": "pre-release",
"prerelease": True,
"api_key": {
"from_secret": "github_access_key",
},
"files": [
"build/lucky-linux-" + arch[2] + ".tgz"
]
}
})
# TODO: Add release step for v* tags
# Set the pipeline steps
pipeline["steps"] = steps
return pipeline
def windows_pipelines(config):
# Create the primary ( and only, so far ) Windows pipeline
pipeline = {
"kind": "pipeline",
"name": "windows",
}
# Pipeline steps
steps = []
# Build step: Compile Lucky for Windows
steps.append({
"name": "build",
"image": "rust:latest",
"commands": [
# Install MingW
"apt-get update",
"apt-get install -y gcc-mingw-w64-x86-64 zip",
# Install the version of Rust that we need
"rustup default " + config["rust_version"],
"rustup target install x86_64-pc-windows-gnu",
# Patch Some MingW Libs. See https://github.com/rust-lang/rust/issues/47048#issuecomment-474118132
"cp -f /usr/x86_64-w64-mingw32/lib/dllcrt2.o /usr/local/rustup/toolchains/nightly-2019-11-24-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/dllcrt2.o",
"cp -f /usr/x86_64-w64-mingw32/lib/crt2.o /usr/local/rustup/toolchains/nightly-2019-11-24-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-pc-windows-gnu/lib/crt2.o",
# Configure Cargo to use the MingW linker
"mkdir -p .cargo",
"""printf '[target.x86_64-pc-windows-gnu]\nlinker = "x86_64-w64-mingw32-gcc"' >> .cargo/config""",
# Compile Lucky for Windows
"cargo build --target x86_64-pc-windows-gnu --release --no-default-features --features default_devkit",
# Zip up the Lucky executable
"mkdir -p build",
"mv target/x86_64-pc-windows-gnu/release/lucky.exe build",
"cd build/",
"zip -r lucky-windows-x86_64.zip lucky.exe"
]
})
# Pre-release steps
if config["ctx"].build.ref == "refs/tags/pre-release":
# Publish pre-release to GitHub releases
steps.append({
"name": "publish-github-pre-release",
"image": "plugins/github-release",
"depends_on": ["build"],
"settings": {
"title": "pre-release",
"prerelease": True,
"api_key": {
"from_secret": "github_access_key",
},
"files": [
"build/lucky-windows-x86_64.zip"
]
}
})
# TODO: Add release step for v* tags
# Set pipeline steps
pipeline["steps"] = steps
# Return our only Windows pipeline
return [pipeline]
def macos_pipelines(config):
# Create the primary ( and only, so far ) MacOS pipeline
pipeline = {
"kind": "pipeline",
"name": "macos",
}
# Pipeline steps
steps = []
# Build step
steps.append({
"name": "build",
"image": "katharostech/rust-osxcross:rust-latest_v0.1.0",
"commands": [
# Add OSXCross tools to the PATH
"PATH=\"$PATH:/build/osxcross/target/bin\"",
# Install our target version of Rust
"rustup default " + config["rust_version"],
"rustup target install x86_64-apple-darwin",
# Configure cargo to use the Mac linker and libraries
"export CC=x86_64-apple-darwin15-clang",
"mkdir -p /drone/src/.cargo",
"""printf '[target.x86_64-apple-darwin]\\nlinker = "x86_64-apple-darwin15-clang"' >> /drone/src/.cargo/config""",
# Compile Lucky
"cargo build --target x86_64-apple-darwin --release --no-default-features --features default_devkit",
# Create a tarball
"mkdir -p build",
"mv target/x86_64-apple-darwin/release/lucky build",
"cd build/",
"tar -czf lucky-mac-x86_64.tgz lucky",
# Calculate the sha256sum ( used for the homebrew cask )
"sha256sum lucky-mac-x86_64.tgz | awk -F ' ' '{print $1}' > sha256.txt"
]
})
# Pre-release steps
if config["ctx"].build.ref == "refs/tags/pre-release":
# Publish pre-release to GitHub releases
steps.append({
"name": "publish-github-pre-release",
"image": "plugins/github-release",
"depends_on": ["build"],
"prerelease": True,
"settings": {
"title": "pre-release",
"api_key": {
"from_secret": "github_access_key",
},
"files": [
"build/lucky-mac-x86_64.tgz"
]
}
})
# Update the Lucky pre-release Homebrew cask
steps.append({
"name": "publish-homebrew-pre-release",
"image": "alpine/git",
"depends_on": ["publish-github-pre-release"],
"environment": {
"USER": {
"from_secret": "github_username",
},
"PASSWORD": {
"from_secret": "github_access_key"
}
},
"commands": [
# Configure Git
'git config --global user.email "[email protected]"',
'git config --global user.name "Zicklag"',
# Clone our Homebrew tap
"git clone https://$${USER}:$${PASSWORD}@github.com/katharostech/homebrew-tap.git",
# Substitue the sha256 inside the cask file with the newly calculated sum
"""sed -i "/\\\\w*sha256/s/\\\\'[a-z0-9]*\\\\'/\\\\'$(cat build/sha256.txt)\\\\'/" homebrew-tap/Casks/lucky-pre-release.rb""",
"cd homebrew-tap",
# Commit and push the update
"git add .",
"git commit -m 'Update Lucky Pre-Release'",
"git push"
]
})
# TODO: Add release step for v* tags
# Set pipeline steps
pipeline["steps"] = steps
# Return our only MacOS pipeline
return [pipeline]