Skip to content

Commit c177444

Browse files
committed
Add some test & deploy code.
The test is more of a demonstration than an actual test.
1 parent c36198f commit c177444

File tree

4 files changed

+183
-0
lines changed

4 files changed

+183
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ fixture like so:
2020
(clojure.test/use-fixtures :once (with-junit-output "/where/you/want.xml"))
2121
```
2222

23+
See `clojure-test-junit-output.test-core` for a complete example.
24+
2325
## License
2426

2527
This library is distributed under a two clause BSD-style license. See the

circle.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
machine:
2+
java:
3+
version: oraclejdk8
4+
5+
test:
6+
override:
7+
- lein test || true
8+
9+
deployment:
10+
all:
11+
branch: /.*/
12+
commands:
13+
- bash release.sh

release.sh

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/bin/bash
2+
3+
set -o nounset
4+
5+
export GITHUB_USER=conormcd
6+
export GITHUB_REPO=clojure-test-junit-output
7+
8+
abort() {
9+
echo "$@"
10+
exit 1
11+
}
12+
13+
current_version() {
14+
grep -m1 '(defproject' project.clj | \
15+
sed -e 's,^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$,\1,'
16+
}
17+
18+
major() {
19+
current_version | cut -d. -f1
20+
}
21+
22+
minor() {
23+
current_version | cut -d. -f2
24+
}
25+
26+
patch() {
27+
if [ -n "${CIRCLE_BUILD_NUM:-}" ]; then
28+
echo "${CIRCLE_BUILD_NUM}"
29+
else
30+
current_version | cut -d. -f3
31+
fi
32+
}
33+
34+
branch() {
35+
if [ -n "${CIRCLE_BRANCH:-}" ]; then
36+
echo "${CIRCLE_BRANCH}"
37+
else
38+
git rev-parse --abbrev-ref HEAD
39+
fi
40+
}
41+
42+
sha() {
43+
if [ -n "${CIRCLE_SHA1:-}" ]; then
44+
echo "${CIRCLE_SHA1}"
45+
else
46+
git rev-parse HEAD
47+
fi
48+
}
49+
50+
sha_short() {
51+
sha | sed -e 's,^\(........\).*,\1,'
52+
}
53+
54+
new_version() {
55+
if [ "$(branch)" != "master" ]; then
56+
echo "$(major).$(minor).$(patch)-$(branch)-$(sha_short)"
57+
else
58+
echo "$(major).$(minor).$(patch)"
59+
fi
60+
}
61+
62+
sed_inplace() {
63+
if sed --help 2>&1 | grep -q -m 1 GNU; then
64+
sed -i -e "$@"
65+
else
66+
sed -i '' -e "$@"
67+
fi
68+
}
69+
70+
update_project_clj() {
71+
local _v=$1
72+
echo "Updating project.clj to version ${_v}"
73+
sed_inplace "s,\((defproject ${GITHUB_REPO} \)\"[^\"]*\",\1\"${_v}\"," project.clj
74+
}
75+
76+
build_jars() {
77+
echo "Building JARs..."
78+
lein jar 2>&1 | sed -e 's,^, ,'
79+
}
80+
81+
save_artifacts() {
82+
if [ -n "${CIRCLE_ARTIFACTS:-}" ]; then
83+
echo "Copying JARs to CircleCI artifacts..."
84+
find . -name '*.jar' -exec cp {} "${CIRCLE_ARTIFACTS}" \;
85+
echo "Copying junit.xml to CircleCI artifacts..."
86+
cp test/junit.xml "${CIRCLE_ARTIFACTS}/"
87+
fi
88+
}
89+
90+
ensure_github_release_tool_installed() {
91+
local _cwd
92+
_cwd=$(pwd)
93+
94+
if [ -z "${GOPATH:-}" ]; then
95+
export GOPATH=${_cwd}/.go
96+
fi
97+
export PATH="${PATH}:${GOPATH}/bin"
98+
if ! which github-release > /dev/null 2>&1; then
99+
echo "Installing github-release..."
100+
go get github.com/aktau/github-release
101+
fi
102+
}
103+
104+
github_release() {
105+
local _version
106+
_version=$1
107+
108+
echo "Releasing ${_version}"
109+
github-release release \
110+
--user "${GITHUB_USER}" \
111+
--repo "${GITHUB_REPO}" \
112+
--tag "${_version}" \
113+
--target "$(sha)" \
114+
--description "Release version ${_version}"
115+
find . -name '*.jar' | while read -r _jar; do
116+
github-release upload \
117+
--user "${GITHUB_USER}" \
118+
--repo "${GITHUB_REPO}" \
119+
--tag "${_version}" \
120+
--name "$(basename "${_jar}")" \
121+
--file "${_jar}"
122+
done
123+
}
124+
125+
clojars_deploy() {
126+
lein deploy clojars 2>&1 | sed -e 's,^, ,'
127+
}
128+
129+
cleanup() {
130+
git clean -ffdx
131+
}
132+
133+
v=$(new_version)
134+
update_project_clj "${v}"
135+
build_jars
136+
save_artifacts
137+
if [ "$(branch)" = "master" ]; then
138+
if [ -z "${CLOJARS_USERNAME:-}" ]; then
139+
abort "Missing environment variable: CLOJARS_USERNAME"
140+
fi
141+
if [ -z "${CLOJARS_PASSWORD:-}" ]; then
142+
abort "Missing environment variable: CLOJARS_PASSWORD"
143+
fi
144+
if [ -z "${GITHUB_TOKEN:-}" ]; then
145+
abort "Missing environment variable: GITHUB_TOKEN"
146+
fi
147+
148+
# Make a GitHub release
149+
ensure_github_release_tool_installed
150+
github_release "${v}"
151+
152+
# Push to clojars
153+
clojars_deploy
154+
fi
155+
cleanup
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns clojure-test-junit-output.test-core
2+
(:require [clojure.test :refer :all]
3+
[clojure-test-junit-output.core :refer (with-junit-output)]))
4+
5+
(use-fixtures :once (with-junit-output "test/junit.xml"))
6+
7+
(deftest some-sort-of-a-test
8+
(testing "Success works"
9+
(is (= 1 1)))
10+
(testing "Failure works"
11+
(is (= 1 0)))
12+
(testing "Errors work."
13+
(throw (Exception. "This shouldn't really kill things."))))

0 commit comments

Comments
 (0)