Skip to content

Commit e9ccf00

Browse files
authored
eu available in build (#15)
* Fetch script for retrieving eu binary. * Configure build to pull an existing eu binary * Fix config syntax. * Try to resolve encoding issue with pipenv * Move to stretch-based release image. * Try to fetch eu to /usr/local/bin. * Build arch / os into package.yaml * Correct build.eu path * Fix typo. * Tweak build.eu * Fix typo * Echo eu metadata after build * Fix typo * Correct step name
1 parent f24dd15 commit e9ccf00

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

.circleci/config.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ jobs:
88
steps:
99
- checkout
1010

11+
- run:
12+
name: Make a recent eu binary available to the build
13+
command: |
14+
cd ci
15+
pipenv install
16+
pipenv run python fetch.py /usr/local/bin
17+
eu --version
18+
1119
- restore_cache:
1220
keys:
1321
- cache-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
@@ -38,6 +46,16 @@ jobs:
3846
- ~/.stack
3947
key: cache-{{ checksum "stack.yaml" }}-{{ checksum "package.yaml" }}
4048

49+
- run:
50+
name: Update build / release details in package.yaml
51+
command: |
52+
export OSTYPE=$(uname)
53+
export HOSTTYPE=$(uname -m)
54+
eu package=package.yaml ci/build.eu > new-package.yaml
55+
mv -f new-package.yaml package.yaml
56+
echo --- replaced package.yaml ---
57+
cat package.yaml
58+
4159
- run:
4260
name: Build, run unit tests with coverage
4361
command: stack build --fast --pedantic --no-terminal --test --coverage
@@ -49,9 +67,13 @@ jobs:
4967
hlint .
5068
5169
- run:
52-
name: Build with no coverage instrumentation
70+
name: Build without coverage
5371
command: stack build --pedantic --no-terminal --ghc-options="-O2"
5472

73+
- run:
74+
name: Check build metadata for generated executable
75+
command: stack exec eu -- -e 'eu.build'
76+
5577
- persist_to_workspace:
5678
root: .stack-work
5779
paths:

ci/build.eu

+13-8
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,36 @@
1313
version: package.version
1414
str.match-with("(\d+)\.(\d+)\.([^.]+)\.([^.]+)")
1515
drop(1)
16-
with-keys([:major, :minor, :revision, :build])
16+
with-keys([:major, :minor, :patch, :build])
1717

1818
build: {
1919

2020
` "Circle build number"
21-
number: io.env lookup-or(:CIRCLE_BUILD_NUM, version.revision)
21+
number: io.env lookup-or(:CIRCLE_BUILD_NUM, version.patch)
2222

2323
` "SHA1 of the repo commit we're building"
2424
commit: io.env lookup-or(:CIRCLE_SHA1, "working-copy")
2525

2626
` "URL of build"
2727
url: io.env lookup-or(:CIRCLE_BUILD_URL, "(none)")
2828

29+
` "Architecture of build environment"
30+
arch: io.env lookup-alts([:HOSTTYPE, :_system_arch], "unknown")
31+
32+
` "Architecture of build environment"
33+
os: io.env lookup-alts([:OSTYPE, :_system_name], "unknown")
34+
35+
` "Seconds since epoch at eu build time"
36+
epoch-time: io.epoch-time
2937
}
3038

3139
new-version: [version.major,
3240
version.minor,
33-
build.number,
34-
str.of(io.epoch-time)] str.join-on(".")
41+
version.patch,
42+
build.number] str.join-on(".")
3543

3644
` :main
3745
main: package {
3846
version: new-version
39-
eu-build: {
40-
commit: build.commit
41-
url: build.url
42-
}
47+
eu-build: build
4348
}

ci/fetch.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
from pathlib import Path
5+
import re
6+
import os
7+
import subprocess
8+
import tarfile
9+
from github3 import login
10+
11+
def fetch(bindir):
12+
13+
""" Download the latest binary release for this platform to `bindir`. """
14+
15+
token = os.environ['GITHUB_API_TOKEN']
16+
if not token:
17+
raise EnvironmentError("No Github API Token available")
18+
19+
gh = login(token=token)
20+
r = gh.repository("curvelogic", "eucalypt-hs")
21+
22+
release = r.latest_release()
23+
asset = [a for a in release.assets() if "linux" in a.name][0]
24+
25+
print("Downloading {}".format(asset.name))
26+
asset.download()
27+
28+
print("Extracting {}".format(asset.name))
29+
with tarfile.open(asset.name, "r:gz") as tar:
30+
files = [f for f in tar if f.isreg()]
31+
print(" - extracting {}".format(f.name for f in files))
32+
tar.extractall(members = files)
33+
print(" - moving to ~/local/bin")
34+
for f in files:
35+
os.rename(f.name, bindir / Path(f.name).name)
36+
37+
def main(args):
38+
39+
if len(args) > 1:
40+
bindir = Path(args[1])
41+
else:
42+
bindir = Path.home() / "bin"
43+
44+
fetch(bindir)
45+
46+
if __name__ == '__main__':
47+
main(sys.argv)

0 commit comments

Comments
 (0)