Skip to content

Commit

Permalink
feature: print version on start of execution and always pull image ch…
Browse files Browse the repository at this point in the history
…anges
  • Loading branch information
pedrocodacy committed Aug 23, 2021
1 parent 7966f09 commit 45bb1b7
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 25 deletions.
1 change: 1 addition & 0 deletions bin/codacy-analysis-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ run() {
output_volume="--volume ${OUTPUT_DIRECTORY}:${OUTPUT_DIRECTORY}";
fi
local CODACY_ANALYSIS_CLI_VERSION="${CODACY_ANALYSIS_CLI_VERSION:-stable}"
docker pull codacy/codacy-analysis-cli:${CODACY_ANALYSIS_CLI_VERSION}
docker run \
--rm \
--env CODACY_CODE="$CODACY_CODE" \
Expand Down
11 changes: 11 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ lazy val codacyAnalysisCli = project
name := "codacy-analysis-cli",
coverageExcludedPackages := "<empty>;com\\.codacy\\..*CLIError.*",
Common.dockerSettings,
Compile / sourceGenerators += Def.task {
val file = (Compile / sourceManaged).value / "com" / "codacy" / "cli" / "Versions.scala"
IO.write(
file,
s"""package com.codacy.cli
|object Versions {
| val cliVersion: String = "${version.value}"
|}
|""".stripMargin)
Seq(file)
}.taskValue,
Common.genericSettings,
Universal / javaOptions ++= Seq("-XX:MinRAMPercentage=60.0", "-XX:MaxRAMPercentage=90.0"),
publish := (Docker / publish).value,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.codacy.analysis.cli.command

import java.nio.file.Path

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.{HttpRequest, HttpResponse}
Expand All @@ -17,7 +16,7 @@ import com.codacy.analysis.cli.analysis.AnalyseExecutor.{
import com.codacy.analysis.cli.analysis.{AnalyseExecutor, ExitStatus, ToolSelector}
import com.codacy.analysis.cli.clients.Credentials
import com.codacy.analysis.cli.configuration.{CLIConfiguration, Environment}
import com.codacy.analysis.cli.formatter.Formatter
import com.codacy.analysis.cli.formatter.{Formatter, Text}
import com.codacy.analysis.clientapi.tools.ToolsClient
import com.codacy.analysis.core.analysis.Analyser
import com.codacy.analysis.core.clients.CodacyClient
Expand All @@ -28,6 +27,7 @@ import com.codacy.analysis.core.model._
import com.codacy.analysis.core.upload.ResultsUploader
import com.codacy.analysis.core.utils.Logger
import com.codacy.analysis.core.utils.SeqOps._
import com.codacy.cli.Versions
import com.codacy.toolRepository.remote.ToolRepositoryRemote
import com.codacy.toolRepository.remote.storage.{PatternSpecDataStorage, ToolSpecDataStorage}
import org.log4s.getLogger
Expand Down Expand Up @@ -94,6 +94,10 @@ class AnalyseCommand(analyze: Analyze,

Logger.setLevel(analyze.options.verboseValue)

if (analyze.options.verboseValue || configuration.analysis.output.format == Text.name) {
Console.println(s"Running codacy-analysis-cli version ${Versions.cliVersion}")
}

private val logger: org.log4s.Logger = getLogger

def run(): ExitStatus.ExitCode = {
Expand All @@ -117,8 +121,7 @@ class AnalyseCommand(analyze: Analyze,
.fold(
{ _ =>
Right(())
},
{ repository =>
}, { repository =>
for {
_ <- validateNoUncommitedChanges(repository, configuration.upload.upload)
_ <- validateGitCommitUuid(repository, analyze.commitUuid, analyze.skipCommitUuidValidationValue)
Expand All @@ -130,8 +133,7 @@ class AnalyseCommand(analyze: Analyze,
repository.uncommitedFiles.fold(
{ _ =>
Right(())
},
{ uncommitedFiles =>
}, { uncommitedFiles =>
if (uncommitedFiles.nonEmpty) {
val error: CLIError = CLIError.UncommitedChanges(uncommitedFiles)
if (upload) {
Expand Down
13 changes: 4 additions & 9 deletions cli/src/main/scala/com/codacy/analysis/cli/command/CLIApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import com.codacy.analysis.cli.analysis.ExitStatus
import com.codacy.analysis.cli.command.ArgumentParsers._
import com.codacy.analysis.cli.formatter.Formatter
import com.codacy.analysis.core.analysis.Analyser
import com.codacy.analysis.core.clients.{ProjectName, UserName, OrganizationProvider}
import com.codacy.analysis.core.clients.{OrganizationProvider, ProjectName, UserName}
import com.codacy.analysis.core.git.Commit
import com.codacy.cli.Versions

import scala.concurrent.duration.Duration
import scala.util.matching.Regex
Expand Down Expand Up @@ -77,14 +78,8 @@ object ArgumentParsers {
}
}

object Version {

val version: String =
Option(getClass.getPackage.getImplementationVersion).getOrElse("0.1.0-SNAPSHOT")
}

@AppName("Codacy Analysis Cli")
@AppVersion(Version.version)
@AppVersion(Versions.cliVersion)
@ProgName("codacy-analysis-cli")
final case class DefaultCommand(
@ExtraName("v") @ValueDescription("Prints the version of the program")
Expand All @@ -95,7 +90,7 @@ final case class DefaultCommand(

def run(): Unit = {
if (versionValue) {
Console.println(s"codacy-analysis-cli is on version ${Version.version}")
Console.println(s"codacy-analysis-cli is on version ${Versions.cliVersion}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.log4s.{Logger, getLogger}

trait FormatterCompanion {
def name: String

def apply(printStream: PrintStream, executionDirectory: File, ghCodeScanningCompat: Boolean): Formatter
}

Expand Down
17 changes: 9 additions & 8 deletions cli/src/main/scala/com/codacy/analysis/cli/formatter/Sarif.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ private[formatter] class Sarif(val stream: PrintStream, val executionDirectory:
(for {
issue <- issues.groupBy(_.patternId.value).collect { case (_, issue :: _) => issue }
modelPattern <- patternsMap.get(issue.patternId.value)
} yield SarifReport.Rule(
id = issue.patternId.value,
name = modelPattern.title,
shortDescription = SarifReport.Message(modelPattern.description.getOrElse(modelPattern.title)),
help = SarifReport
.Message(text = modelPattern.description.getOrElse(modelPattern.title), markdown = modelPattern.explanation),
properties =
SarifReport.RuleProperties(category = issue.category.getOrElse(Pattern.Category.CodeStyle).toString))).toList
} yield
SarifReport.Rule(
id = issue.patternId.value,
name = modelPattern.title,
shortDescription = SarifReport.Message(modelPattern.description.getOrElse(modelPattern.title)),
help = SarifReport
.Message(text = modelPattern.description.getOrElse(modelPattern.title), markdown = modelPattern.explanation),
properties =
SarifReport.RuleProperties(category = issue.category.getOrElse(Pattern.Category.CodeStyle).toString))).toList
}

private def createArtifacts(issues: Seq[Issue]): List[SarifReport.Artifact] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ class AnalyseExecutorSpec extends Specification with NoLanguageFeatures with Moc
}

private def runAnalyseExecutor(analyserName: String, configuration: CLIConfiguration.Analysis) = {
val formatter: Formatter = Formatter(configuration.output, configuration.projectDirectory)
val formatter: Formatter =
Formatter(configuration.output, configuration.projectDirectory)
val analyser: Analyser[Try] = Analyser(analyserName)
val fileCollector: FileCollector[Try] = FileCollector.defaultCollector()

Expand Down
2 changes: 1 addition & 1 deletion project/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import com.typesafe.sbt.packager.Keys._
import com.typesafe.sbt.packager.docker.DockerPlugin.autoImport.Docker
import com.typesafe.sbt.packager.docker.{Cmd, CmdLike, DockerAlias}
import sbt.Keys._
import sbt.{Def, _}
import sbt.{Compile, Def, IO, _}

import scala.util.Properties

Expand Down

0 comments on commit 45bb1b7

Please sign in to comment.