Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 9, 2019
0 parents commit 6dee50b
Show file tree
Hide file tree
Showing 23 changed files with 866 additions and 0 deletions.
207 changes: 207 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Clojure CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-clojure/ for more details
#
version: 2.1
jobs:
jvm:
docker:
# specify the version you desire here
- image: circleci/clojure:lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Install Clojure
command: |
wget -nc https://download.clojure.org/install/linux-install-1.10.1.447.sh
chmod +x linux-install-1.10.1.447.sh
sudo ./linux-install-1.10.1.447.sh
- run:
name: Run JVM tests
command: |
script/test
# - run:
# name: Run as tools.deps dependency
# command: |
# .circleci/script/tools.deps
- run:
name: Run as lein command
command: |
.circleci/script/lein
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}
linux:
docker:
- image: circleci/clojure:lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
GRAALVM_HOME: /home/circleci/graalvm-ce-19.1.1
BABASHKA_PLATFORM: linux # used in release script
BABASHKA_TEST_ENV: native
steps:
- checkout
- restore_cache:
keys:
- linux-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Install Clojure
command: |
wget https://download.clojure.org/install/linux-install-1.10.1.447.sh
chmod +x linux-install-1.10.1.447.sh
sudo ./linux-install-1.10.1.447.sh
- run:
name: Install native dev tools
command: |
sudo apt-get update
sudo apt-get -y install gcc zlib1g-dev
- run:
name: Download GraalVM
command: |
cd ~
if ! [ -d graalvm-ce-19.1.1 ]; then
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.1.1/graalvm-ce-linux-amd64-19.1.1.tar.gz
tar xzf graalvm-ce-linux-amd64-19.1.1.tar.gz
fi
- run:
name: Build binary
command: |
script/compile
no_output_timeout: 30m
- run:
name: Run tests
command: |
script/test
# - run:
# name: Performance report
# command: |
# .circleci/script/performance
- run:
name: Release
command: |
.circleci/script/release
- save_cache:
paths:
- ~/.m2
- ~/graalvm-ce-19.1.1
key: linux-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
destination: release
mac:
macos:
xcode: "9.0"
environment:
GRAALVM_HOME: /Users/distiller/graalvm-ce-19.1.1/Contents/Home
BABASHKA_PLATFORM: macos # used in release script
BABASHKA_TEST_ENV: native
steps:
- checkout
- restore_cache:
keys:
- mac-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Install Clojure
command: |
.circleci/script/install-clojure /usr/local
- run:
name: Install Leiningen
command: |
.circleci/script/install-leiningen
- run:
name: Download GraalVM
command: |
cd ~
ls -la
if ! [ -d graalvm-ce-19.1.1 ]; then
curl -O -sL https://github.com/oracle/graal/releases/download/vm-19.1.1/graalvm-ce-darwin-amd64-19.1.1.tar.gz
tar xzf graalvm-ce-darwin-amd64-19.1.1.tar.gz
fi
- run:
name: Build binary
command: |
script/compile
no_output_timeout: 30m
- run:
name: Run tests
command: |
script/test
# - run:
# name: Performance report
# command: |
# .circleci/script/performance
- run:
name: Release
command: |
.circleci/script/release
- save_cache:
paths:
- ~/.m2
- ~/graalvm-ce-19.1.1
key: mac-{{ checksum "project.clj" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
destination: release
deploy:
docker:
- image: circleci/clojure:lein-2.8.1
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "project.clj" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: .circleci/script/deploy
- save_cache:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "project.clj" }}
# docker:
# docker:
# - image: circleci/buildpack-deps:stretch
# steps:
# - checkout
# - setup_remote_docker:
# docker_layer_caching: true
# - run:
# name: Build Docker image
# command: .circleci/script/docker

workflows:
version: 2
ci:
jobs:
- jvm
- linux
- mac
- deploy:
filters:
branches:
only: master
requires:
- jvm
- linux
- mac
# - docker:
# filters:
# branches:
# only: master
# requires:
# - jvm
# - linux
# - mac
8 changes: 8 additions & 0 deletions .circleci/script/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]
then
lein deploy clojars
fi

exit 0;
32 changes: 32 additions & 0 deletions .circleci/script/docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

image_name="borkdude/clj-kondo"
image_tag=$(cat resources/CLJ_KONDO_VERSION)
latest_tag="latest"

if [[ $image_tag =~ SNAPSHOT$ ]]; then
echo "This is a snapshot version"
snapshot="true"
else
echo "This is a non-snapshot version"
snapshot="false"
fi

if [ -z "$CIRCLE_PULL_REQUEST" ] && [ "$CIRCLE_BRANCH" = "master" ]; then
echo "Building Docker image $image_name:$image_tag"
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USER" --password-stdin
docker build -t "$image_name" .
docker tag "$image_name:$latest_tag" "$image_name:$image_tag"
# we only update latest when it's not a SNAPSHOT version
if [ "false" = "$snapshot" ]; then
echo "Pushing image $image_name:$latest_tag"
docker push "$image_name:$latest_tag"
fi
# we update the version tag, even if it's a SNAPSHOT version
echo "Pushing image $image_name:$image_tag"
docker push "$image_name:$image_tag"
else
echo "Not publishing Docker image"
fi

exit 0;
23 changes: 23 additions & 0 deletions .circleci/script/install-clojure
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

install_dir=${1:-/tmp/clojure}
mkdir -p "$install_dir"
cd /tmp
curl -O -sL https://download.clojure.org/install/clojure-tools-1.10.1.447.tar.gz
tar xzf clojure-tools-1.10.1.447.tar.gz
cd clojure-tools
clojure_lib_dir="$install_dir/lib/clojure"
mkdir -p "$clojure_lib_dir/libexec"
cp ./*.jar "$clojure_lib_dir/libexec"
cp deps.edn "$clojure_lib_dir"
cp example-deps.edn "$clojure_lib_dir"

sed -i -e 's@PREFIX@'"$clojure_lib_dir"'@g' clojure
mkdir -p "$install_dir/bin"
cp clojure "$install_dir/bin"
cp clj "$install_dir/bin"

cd /tmp
rm -rf clojure-tools-1.10.1.447.tar.gz
rm -rf clojure-tools
echo "Installed clojure to $install_dir/bin"
6 changes: 6 additions & 0 deletions .circleci/script/install-leiningen
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > lein
sudo mkdir -p /usr/local/bin/
sudo mv lein /usr/local/bin/lein
sudo chmod a+x /usr/local/bin/lein
3 changes: 3 additions & 0 deletions .circleci/script/lein
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo '{:a 1}' | lein bb '(:a *in*)'
36 changes: 36 additions & 0 deletions .circleci/script/performance
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

err=0
function _trap_error() {
local exit_code="$1"
if [ "$exit_code" -ne 2 ] && [ "$exit_code" -ne 3 ]; then
echo "EXIT CODE :( $exit_code"
(( err |= "$exit_code" ))
fi
}

trap '_trap_error $?' ERR
trap 'exit $err' SIGINT SIGTERM


rm -rf performance.txt
echo -e "==== Build initial cache" | tee -a performance.txt
cp="$(clojure -R:cljs -Spath)"
read -r -d '' config <<'EOF' || true
{:linters
{:not-a-function
{:skip-args [clojure.pprint/defdirectives
cljs.pprint/defdirectives
clojure.data.json/codepoint-case]}}}
EOF

(time ./clj-kondo --lint "$cp" --cache --config "$config") 2>&1 | tee -a performance.txt

echo -e "\n==== Lint a single file (emulate in-editor usage)" | tee -a performance.txt
(time ./clj-kondo --lint src/clj_kondo/impl/core.clj --cache) 2>&1 | tee -a performance.txt

count=$(find . -name "*.clj*" -type f | wc -l | tr -d ' ')
echo -e "\n==== Launch clj-kondo for each file in project ($count)" | tee -a performance.txt
(time find src -name "*.clj*" -type f -exec ./clj-kondo --lint {} --cache \; ) 2>&1 | tee -a performance.txt

exit "$err"
16 changes: 16 additions & 0 deletions .circleci/script/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

rm -rf /tmp/release
mkdir -p /tmp/release
cp bb /tmp/release
VERSION=$(cat resources/BABASHKA_VERSION)

cd /tmp/release

## release binary as zip archive

zip "babashka-$VERSION-$BABASHKA_PLATFORM-amd64.zip" bb

## cleanup

rm bb
31 changes: 31 additions & 0 deletions .circleci/script/tools.deps
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

err=0
function _trap_error() {
local exit_code="$1"
if [ "$exit_code" -ne 2 ] && [ "$exit_code" -ne 3 ]; then
(( err |= "$exit_code" ))
fi
}

trap '_trap_error $?' ERR
trap 'exit $err' SIGINT SIGTERM


# Run as local root dependency
rm -rf /tmp/proj
mkdir -p /tmp/proj
cd /tmp/proj
clojure -Sdeps '{:deps {clj-kondo {:local/root "/home/circleci/repo"}}}' \
-m clj-kondo.main --lint /home/circleci/repo/src /home/circleci/repo/test

# Run as git dependency
rm -rf /tmp/proj
mkdir -p /tmp/proj
cd /tmp/proj

github_user=${CIRCLE_PR_USERNAME:-borkdude}
clojure -Sdeps "{:deps {clj-kondo {:git/url \"https://github.com/$github_user/clj-kondo\" :sha \"$CIRCLE_SHA1\"}}}" \
-m clj-kondo.main --lint /home/circleci/repo/src /home/circleci/repo/test

exit "$err"
1 change: 1 addition & 0 deletions .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:lint-as {me.raynes.conch/let-programs clojure.core/let}}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
.hgignore
.hg/
/bb
.clj-kondo/.cache
Loading

0 comments on commit 6dee50b

Please sign in to comment.