Skip to content

Commit

Permalink
Compile
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jan 2, 2021
1 parent cb559e8 commit cfefbe3
Show file tree
Hide file tree
Showing 15 changed files with 459 additions and 4 deletions.
1 change: 1 addition & 0 deletions .carve/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:paths ["src" "test"]}
183 changes: 179 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ jobs:
jvm:
docker:
# specify the version you desire here
- image: circleci/clojure:lein-2.8.1
- image: circleci/clojure:lein-2.9.3-buster
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
steps:
- checkout
- run:
name: Get rid of erroneous git config
command: |
rm -rf /home/circleci/.gitconfig
- restore_cache:
keys:
- v1-dependencies-{{ checksum "deps.edn" }}
Expand All @@ -21,9 +25,9 @@ jobs:
- 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
wget -nc https://download.clojure.org/install/linux-install-1.10.1.727.sh
chmod +x linux-install-1.10.1.727.sh
sudo ./linux-install-1.10.1.727.sh
- run:
name: Run JVM tests
command: |
Expand All @@ -32,9 +36,180 @@ jobs:
paths:
- ~/.m2
key: v1-dependencies-{{ checksum "deps.edn" }}
linux:
docker:
- image: circleci/clojure:lein-2.9.3-buster
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
GRAALVM_HOME: /home/circleci/graalvm-ce-java11-20.3.0
APP_PLATFORM: linux # used in release script
APP_TEST_ENV: native
steps:
- checkout
- run:
name: Get rid of erroneous git config
command: |
rm -rf /home/circleci/.gitconfig
- restore_cache:
keys:
- linux-{{ checksum "deps.edn" }}-{{ checksum ".circleci/config.yml" }}
- run:
name: Install Clojure
command: |
wget https://download.clojure.org/install/linux-install-1.10.1.727.sh
chmod +x linux-install-1.10.1.727.sh
sudo ./linux-install-1.10.1.727.sh
- run:
name: Install native dev tools
command: |
sudo apt-get update
sudo apt-get -y install gcc g++ zlib1g-dev
- run:
name: Download GraalVM
command: |
cd ~
if ! [ -d graalvm-ce-java11-20.3.0 ]; then
curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.3.0/graalvm-ce-java11-linux-amd64-20.3.0.tar.gz
tar xzf graalvm-ce-java11-linux-amd64-20.3.0.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-java11-20.3.0
key: linux-{{ checksum "deps.edn" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
destination: release
mac:
macos:
xcode: "12.0.0"
environment:
GRAALVM_HOME: /Users/distiller/graalvm-ce-java11-20.3.0/Contents/Home
APP_PLATFORM: macos # used in release script
APP_TEST_ENV: native
steps:
- checkout
- run:
name: Get rid of erroneous git config
command: |
rm -rf ~/.gitconfig
- restore_cache:
keys:
- mac-{{ checksum "deps.edn" }}-{{ 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-java11-20.3.0 ]; then
curl -O -sL https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.3.0/graalvm-ce-java11-darwin-amd64-20.3.0.tar.gz
tar xzf graalvm-ce-java11-darwin-amd64-20.3.0.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-java11-20.3.0
key: mac-{{ checksum "deps.edn" }}-{{ checksum ".circleci/config.yml" }}
- store_artifacts:
path: /tmp/release
destination: release
deploy:
docker:
- image: circleci/clojure:lein-2.9.3-buster
working_directory: ~/repo
environment:
LEIN_ROOT: "true"
steps:
- checkout
- run:
name: Get rid of erroneous git config
command: |
rm -rf /home/circleci/.gitconfig
- restore_cache:
keys:
- v1-dependencies-{{ checksum "deps.edn" }}
# 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 "deps.edn" }}
# 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.727.tar.gz
tar xzf clojure-tools-1.10.1.727.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.727.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/2.9.1/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 jet --from edn --to json
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 carve /tmp/release
VERSION=$(cat resources/CARVE_VERSION)

cd /tmp/release

## release binary as zip archive

zip "carve-$VERSION-$APP_PLATFORM-amd64.zip" carve

## cleanup

rm carve
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"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.cpcache
/target/
.dir-locals.el
/carve
/carve.jar
Loading

0 comments on commit cfefbe3

Please sign in to comment.