Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #60 from codacy/update-dependencies-FT-6107
Browse files Browse the repository at this point in the history
update coverage parser and remove unnecessary dependencies
  • Loading branch information
rtfpessoa committed Nov 30, 2018
2 parents 21875a0 + 04ed8dd commit 8474349
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 40 deletions.
116 changes: 116 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# CircleCI 2.0 configuration file
version: 2

# Re-usable blocks to reduce boilerplate in job definitions.
references:
host_environment_defaults: &host_environment_defaults
# Customize the JVM maximum heap limit
JAVA_OPTS: -Xmx3200m

docker_environment_defaults: &docker_environment_defaults
# Customize the JVM to read correct memory values
JAVA_OPTS: '-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1'

default_java_job: &default_java_job
docker:
- image: circleci/openjdk:8-jdk
environment:
<<: *docker_environment_defaults
environment:
<<: *host_environment_defaults
working_directory: ~/workdir

restore_dependencies: &restore_dependencies
restore_cache:
keys:
- sbt-ivy2-dependencies-1.0.11-{{ checksum "/tmp/dependencies.cache.tmp" }}-extras
- sbt-ivy2-dependencies-1.0.11-{{ checksum "/tmp/dependencies.cache.tmp" }}
- sbt-ivy2-dependencies-1.0.11

clean_sbt_dependencies_cache: &clean_sbt_dependencies_cache
run:
name: Clean sbt dependencies cache
command: |
find ~/.sbt -name "*.lock" -delete
find ~/.ivy2 -name "ivydata-*.properties" -delete
setup_dependencies_key: &setup_dependencies_key
run:
name: Generate cache key
command: |
shasum build.sbt \
project/plugins.sbt \
project/build.properties \
project/Dependencies.scala > /tmp/dependencies.cache.tmp
jobs:
checkout_compile:
<<: *default_java_job
steps:
- checkout
- attach_workspace:
at: ~/workdir
- *setup_dependencies_key
- *restore_dependencies
- run:
name: Resolve dependencies
command: |
sbt update
- run:
name: Compile
command: ./scripts/compile.sh
- *clean_sbt_dependencies_cache
- save_cache:
paths:
- ~/.ivy2
- ~/.sbt
- ~/.m2
- ~/.coursier
key: sbt-ivy2-dependencies-1.0.11-{{ checksum "/tmp/dependencies.cache.tmp" }}
- persist_to_workspace:
root: ~/workdir
paths:
- target
- project/target
- project/project/target

publish_lib:
<<: *default_java_job
steps:
- checkout
- attach_workspace:
at: ~/workdir
- *setup_dependencies_key
- *restore_dependencies
- run:
name: Install AWS CLI
command: |
sudo apt -y update
sudo apt -y install python3-pip
sudo python3 -m pip install awscli
- run:
name: Setup AWS Credentials
command: ./scripts/setup-aws-credentials.sh
- run:
name: Retrieve GPG Keys
command: |
mkdir -p ~/.gnupg
aws s3 sync --profile shared-services --include '*.gpg' s3://$AWS_CREDENTIALS_BUCKET/gnupg/ ~/.gnupg
- run:
name: Export publish version
command: echo 'export PUBLISH_VERSION="2.$CIRCLE_BUILD_NUM"' >> $BASH_ENV
- run:
name: Publish to Sonatype
command: ./scripts/publish_lib.sh $PUBLISH_VERSION

workflows:
version: 2
test-and-publish:
jobs:
- checkout_compile
- publish_lib:
context: CodacyAWS
filters:
branches:
only:
- master
13 changes: 8 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Dependencies._
import sbt.Credentials

name := "sbt-codacy-coverage"

Expand All @@ -7,8 +8,8 @@ version := "0.0.1-SNAPSHOT"
crossSbtVersions := Seq("0.13.16", "1.0.1")

scalaVersion := (CrossVersion partialVersion (sbtVersion in pluginCrossBuild).value match {
case Some((0, 13)) => "2.10.6"
case Some((1, _)) => "2.12.2"
case Some((0, 13)) => "2.10.7"
case Some((1, _)) => "2.12.7"
case _ => sys error s"Unhandled sbt version ${(sbtVersion in pluginCrossBuild).value}"
})

Expand All @@ -25,9 +26,7 @@ resolvers ++= Seq(
)

libraryDependencies ++= Seq(
codacyScalaApi,
coverageParser,
raptureJsonCirce,
Codacy.coverageParser,
javaxActivation
)

Expand All @@ -50,6 +49,10 @@ publishTo := {
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
credentials += Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
sys.env.getOrElse("SONATYPE_USER", "username"),
sys.env.getOrElse("SONATYPE_PASSWORD", "password"))

startYear := Some(2014)

Expand Down
11 changes: 0 additions & 11 deletions circle.yml

This file was deleted.

8 changes: 3 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import sbt._

object Dependencies {

val codacyScalaApi = "com.codacy" %% "codacy-api-scala" % "3.0.7"
val coverageParser = "com.codacy" %% "coverage-parser" % "2.0.7"
val raptureJsonCirce = "com.propensive" %% "rapture-json-circe" % "2.0.0-M8" exclude("org.spire-math", "jawn-parser_2.11")
object Codacy {
val coverageParser = "com.codacy" %% "coverage-parser" % "2.0.12"
}
val javaxActivation = "com.sun.activation" % "javax.activation" % "1.2.0"

}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.16
sbt.version=1.2.3
8 changes: 5 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ resolvers ++= Seq(
Classpaths.sbtPluginReleases
)

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")

addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
5 changes: 5 additions & 0 deletions scripts/compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

sbt ^compile ^test:compile
22 changes: 22 additions & 0 deletions scripts/publish_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

set -e

CURRENT_BRANCH="$(git symbolic-ref --short HEAD)"
PUBLISH_BRANCH="master"

BASE_VERSION="0.1.0-pre"
DEFAULT_VERSION="${BASE_VERSION}.${CURRENT_BRANCH}-SNAPSHOT"

if [ -n "$1" ]; then
VERSION="$1"
else
VERSION="$DEFAULT_VERSION"
fi

echo "Publishing version ${VERSION}"
if [[ -n "$CI" ]] && [[ "$CURRENT_BRANCH" == "$PUBLISH_BRANCH" || "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]]; then
sbt 'set version := "'"${VERSION}"'"' 'set pgpPassphrase := Some("'"$SONATYPE_GPG_PASSPHRASE"'".toCharArray)' ^publishSigned sonatypeReleaseAll
else
sbt 'set version := "'"${VERSION}"'"' ^publishLocal
fi
14 changes: 14 additions & 0 deletions scripts/setup-aws-credentials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

mkdir -p ~/.aws && touch ~/.aws/credentials

cat >> ~/.aws/credentials << EOF
[default]
aws_access_key_id=$ACCESS_KEY_ID
aws_secret_access_key=$SECRET_ACCESS_KEY
[shared-services]
source_profile = default
role_arn = arn:aws:iam::$ACCOUNT_ID:role/CredentialsBucketReader
EOF
31 changes: 16 additions & 15 deletions src/main/scala/com/codacy/CodacyCoveragePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ import java.io.File
import com.codacy.api.client.{CodacyClient, FailedResponse, SuccessfulResponse}
import com.codacy.api.helpers.FileHelper
import com.codacy.api.service.CoverageServices
import com.codacy.api.{CoverageFileReport, Language}
import com.codacy.parsers.implementation.CoberturaParser
import rapture.json.{Json, _}
import com.codacy.plugins.api.languages.Languages.Scala
import sbt.Keys._
import sbt._
import sbt.{Def, _}

object CodacyCoveragePlugin extends AutoPlugin {

implicit val (ast, stringParser, jsonSerializer) = {
import rapture.json.jsonBackends.circe._
(implicitJsonAst, implicitJsonStringParser, circeJValueSerializer)
}

private implicit lazy val ser = implicitly[Serializer[CoverageFileReport, Json]]

object AutoImport {
val codacyCoverage = taskKey[Unit]("Upload coverage reports to Codacy.")
Expand All @@ -29,9 +22,14 @@ object CodacyCoveragePlugin extends AutoPlugin {

lazy val baseSettings: Seq[Def.Setting[_]] = Seq(
codacyCoverage := {
codacyCoverageCommand(state.value, baseDirectory.value, coberturaFile.value,
crossTarget.value / "coverage-report" / "codacy-coverage.json",
codacyProjectToken.value, codacyApiBaseUrl.value, codacyCommit.value)
codacyCoverageCommand(
state = state.value,
rootProjectDir = baseDirectory.value,
coberturaFile = coberturaFile.value,
codacyCoverageFile = crossTarget.value / "coverage-report" / "codacy-coverage.json",
codacyToken = codacyProjectToken.value,
codacyApiBaseUrl = codacyApiBaseUrl.value,
sbtCodacyCommit = codacyCommit.value)
},
aggregate in codacyCoverage := false,
codacyProjectToken := None,
Expand All @@ -45,7 +43,7 @@ object CodacyCoveragePlugin extends AutoPlugin {

override def trigger: PluginTrigger = allRequirements

override val projectSettings = baseSettings
override val projectSettings: Seq[Def.Setting[_]] = baseSettings

private val publicApiBaseUrl = "https://api.codacy.com"

Expand All @@ -67,7 +65,10 @@ object CodacyCoveragePlugin extends AutoPlugin {
FileHelper.withTokenAndCommit(codacyToken, commitUUIDOpt) {
case (projectToken, commitUUID) =>

val reader = new CoberturaParser(Language.Scala, rootProjectDir, coberturaFile)
val reader = new CoberturaParser(
language = Scala,
rootProject = rootProjectDir,
coverageReport = coberturaFile)
val report = reader.generateReport()

FileHelper.writeJsonToFile(codacyCoverageFile, report)
Expand All @@ -77,7 +78,7 @@ object CodacyCoveragePlugin extends AutoPlugin {

logger.info(s"Uploading coverage data...")

coverageServices.sendReport(commitUUID, Language.Scala.toString, report) match {
coverageServices.sendReport(commitUUID, Scala.toString, report) match {
case FailedResponse(error) =>
sys.error(s"Failed to upload data. Reason: $error")
state.exit(ok = false)
Expand Down

0 comments on commit 8474349

Please sign in to comment.