From 040de3462ca12a60954eed72b959fe2816c41688 Mon Sep 17 00:00:00 2001 From: Renato Massaro Date: Tue, 9 May 2017 17:24:18 -0300 Subject: [PATCH 1/3] Add coveralls support --- Jenkinsfile | 12 ++++++++++++ coveralls.json | 6 ++++++ mix.exs | 14 +++++++++++--- mix.lock | 3 +++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 coveralls.json diff --git a/Jenkinsfile b/Jenkinsfile index 8a4a8e8e..0d88b3f8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,6 +92,11 @@ parallel ( stage('Tests') { step([$class: 'WsCleanup']) + env.HELIX_COVERALLS_TOKEN = sh( + script: '#!/bin/sh -e\n cat ~/private/coveralls_token_helix', + returnStdout: true + ).trim() + unstash 'source' unstash 'build-test' @@ -101,6 +106,13 @@ parallel ( // Unset debug flag, load env vars on ~/.profile & run mix test sh '#!/bin/sh -e\n' + '. ~/.profile && mix test.full' + + withEnv(['CI_NAME=jenkins', "CI_BUILD_NUMBER=${env.BUILD_NUMBER}", "CI_BUILD_URL=${env.BUILD_URL}", "CI_BRANCH=${env.BRANCH_NAME}", "COVERALLS_REPO_TOKEN=${env.HELIX_COVERALLS_TOKEN}"]) { + + // Run code coverage + sh '#!/bin/sh -e\n' + '. ~/.profile && mix ecto.reset && mix coveralls.post ' + "--sha ${env.sha1} --branch ${env.BRANCH_NAME}" + + } } } } diff --git a/coveralls.json b/coveralls.json new file mode 100644 index 00000000..e6808a49 --- /dev/null +++ b/coveralls.json @@ -0,0 +1,6 @@ +{ + "skip_files": [ + "deps", + "test" + ] +} diff --git a/mix.exs b/mix.exs index ba8d6df3..07eab455 100644 --- a/mix.exs +++ b/mix.exs @@ -19,6 +19,7 @@ defmodule Helix.Mixfile do deps: deps(), dialyzer: [plt_add_apps: [:mix, :phoenix_pubsub]], + test_coverage: [tool: ExCoveralls, test_task: "test.cover"], preferred_cli_env: %{ "test.quick": :test, @@ -26,7 +27,11 @@ defmodule Helix.Mixfile do "test.unit": :test, "test.cluster": :test, "test.external": :test, - "pr": :test + "test.cover": :test, + "pr": :test, + "coveralls": :test, + "coveralls.post": :test, + "coveralls.json": :test }, name: "Helix", @@ -69,7 +74,8 @@ defmodule Helix.Mixfile do {:earmark, "~> 1.1", only: :dev}, {:ex_doc, "~> 0.15", only: :dev}, - {:credo, "~> 0.7", only: [:dev, :test]} + {:credo, "~> 0.7", only: [:dev, :test]}, + {:excoveralls, "~> 0.6.3", only: [:dev, :test]} ] end @@ -77,7 +83,6 @@ defmodule Helix.Mixfile do [ "ecto.setup": ["ecto.create", "ecto.migrate", "helix.seeds"], "ecto.reset": ["ecto.drop", "ecto.setup"], - "test": ["test.quick"], "test.full": [ "helix.test --exclude sequential --exclude cluster --exclude external", "helix.test --no-prune --only sequential --exclude cluster --exclude external --max-cases 1", @@ -102,6 +107,9 @@ defmodule Helix.Mixfile do "helix.test --no-prune --only sequential --exclude cluster --exclude external --max-cases 1", "dialyzer --halt-exit-status", "credo --strict" + ], + "test.cover": [ + "helix.test --no-prune --exclude sequential --exclude cluster --exclude external --max-cases 1" ] ] end diff --git a/mix.lock b/mix.lock index fcd1526d..a8e86414 100644 --- a/mix.lock +++ b/mix.lock @@ -18,12 +18,15 @@ "ecto": {:git, "https://github.com/elixir-ecto/ecto.git", "945e1547d94a8be9007bbc61a578a142da5608f8", [ref: "945e154"]}, "ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]}, "ex_machina": {:hex, :ex_machina, "1.0.2", "1cc49e1a09e3f7ab2ecb630c17f14c2872dc4ec145d6d05a9c3621936a63e34f", [:mix], [{:ecto, "~> 2.0", [hex: :ecto, optional: true]}]}, + "excoveralls": {:hex, :excoveralls, "0.6.3", "894bf9254890a4aac1d1165da08145a72700ff42d8cb6ce8195a584cb2a4b374", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]}, + "exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]}, "gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []}, "hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]}, "hebroker": {:git, "https://github.com/HackerExperience/HeBroker.git", "2a653a43b512c6392f55508dfc1be8463a845b31", []}, "helf": {:git, "https://github.com/HackerExperience/HELF.git", "29e74cc58fdbf4abca8315a765a90dd64cbe5e68", []}, "httpoison": {:hex, :httpoison, "0.11.1", "d06c571274c0e77b6cc50e548db3fd7779f611fbed6681fd60a331f66c143a0b", [:mix], [{:hackney, "~> 1.7.0", [hex: :hackney, optional: false]}]}, "idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []}, + "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []}, "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []}, "mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [:mix], []}, "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []}, From 0afbef89a30f19460377ab88a0952622729536c6 Mon Sep 17 00:00:00 2001 From: Renato Massaro Date: Tue, 9 May 2017 20:47:37 -0300 Subject: [PATCH 2/3] Fix commit id var --- Jenkinsfile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0d88b3f8..05c8f177 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,11 +4,20 @@ node('elixir') { stage('Pre-build') { step([$class: 'WsCleanup']) - env.BUILD_VERSION = sh(script: 'date +%Y.%m.%d%H%M', returnStdout: true).trim() - def ARTIFACT_PATH = "${env.BRANCH_NAME}/${env.BUILD_VERSION}" - checkout scm + env.BUILD_VERSION = sh( + script: 'date +%Y.%m.%d%H%M', + returnStdout: true + ).trim() + + env.COMMIT_ID = sh( + script: 'git rev-parse --short HEAD', + returnStdout: true + ).trim() + + def ARTIFACT_PATH = "${env.BRANCH_NAME}/${env.BUILD_VERSION}" + sh 'mix local.hex --force' sh 'mix local.rebar --force' sh 'mix clean' @@ -110,7 +119,7 @@ parallel ( withEnv(['CI_NAME=jenkins', "CI_BUILD_NUMBER=${env.BUILD_NUMBER}", "CI_BUILD_URL=${env.BUILD_URL}", "CI_BRANCH=${env.BRANCH_NAME}", "COVERALLS_REPO_TOKEN=${env.HELIX_COVERALLS_TOKEN}"]) { // Run code coverage - sh '#!/bin/sh -e\n' + '. ~/.profile && mix ecto.reset && mix coveralls.post ' + "--sha ${env.sha1} --branch ${env.BRANCH_NAME}" + sh '#!/bin/sh -e\n' + '. ~/.profile && mix ecto.reset && mix coveralls.post ' + "--sha ${env.COMMIT_ID} --branch ${env.BRANCH_NAME}" } } From 7c4c8195456ddae50f8e55ccb90826532cb70125 Mon Sep 17 00:00:00 2001 From: Renato Massaro Date: Tue, 9 May 2017 21:41:39 -0300 Subject: [PATCH 3/3] Add travis.yml --- .travis.yml | 24 ++++++++++++++++++++++++ Jenkinsfile | 27 +++------------------------ mix.exs | 3 +-- 3 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..36ca6830 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +dist: trusty +sudo: false +language: elixir +elixir: + - 1.4.2 +otp_release: + - 19.3 +script: +- "MIX_ENV=test mix do deps.get, compile, ecto.setup, coveralls.travis" +services: + - postgresql +addons: + postgresql: "9.6" +env: + global: + - HELIX_DB_USER=postgres + - HELIX_DB_PASS= + - HELIX_DB_HOST=127.0.0.1 + - HELIX_DB_POOL_SIZE=3 + - HELIX_DB_PREFIX=travis + - HELIX_ENDPOINT_URL=127.0.0.1 + - HELIX_ENDPOINT_SECRET=uhauhauhhauuhahuahuaha + - HELIX_NODE_NAME=travis + - HELIX_CLUSTER_COOKIE=uehauehuaheuaheuaheuhe diff --git a/Jenkinsfile b/Jenkinsfile index 05c8f177..8a4a8e8e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,20 +4,11 @@ node('elixir') { stage('Pre-build') { step([$class: 'WsCleanup']) - checkout scm - - env.BUILD_VERSION = sh( - script: 'date +%Y.%m.%d%H%M', - returnStdout: true - ).trim() - - env.COMMIT_ID = sh( - script: 'git rev-parse --short HEAD', - returnStdout: true - ).trim() - + env.BUILD_VERSION = sh(script: 'date +%Y.%m.%d%H%M', returnStdout: true).trim() def ARTIFACT_PATH = "${env.BRANCH_NAME}/${env.BUILD_VERSION}" + checkout scm + sh 'mix local.hex --force' sh 'mix local.rebar --force' sh 'mix clean' @@ -101,11 +92,6 @@ parallel ( stage('Tests') { step([$class: 'WsCleanup']) - env.HELIX_COVERALLS_TOKEN = sh( - script: '#!/bin/sh -e\n cat ~/private/coveralls_token_helix', - returnStdout: true - ).trim() - unstash 'source' unstash 'build-test' @@ -115,13 +101,6 @@ parallel ( // Unset debug flag, load env vars on ~/.profile & run mix test sh '#!/bin/sh -e\n' + '. ~/.profile && mix test.full' - - withEnv(['CI_NAME=jenkins', "CI_BUILD_NUMBER=${env.BUILD_NUMBER}", "CI_BUILD_URL=${env.BUILD_URL}", "CI_BRANCH=${env.BRANCH_NAME}", "COVERALLS_REPO_TOKEN=${env.HELIX_COVERALLS_TOKEN}"]) { - - // Run code coverage - sh '#!/bin/sh -e\n' + '. ~/.profile && mix ecto.reset && mix coveralls.post ' + "--sha ${env.COMMIT_ID} --branch ${env.BRANCH_NAME}" - - } } } } diff --git a/mix.exs b/mix.exs index 07eab455..17329d30 100644 --- a/mix.exs +++ b/mix.exs @@ -30,8 +30,7 @@ defmodule Helix.Mixfile do "test.cover": :test, "pr": :test, "coveralls": :test, - "coveralls.post": :test, - "coveralls.json": :test + "coveralls.travis": :test }, name: "Helix",