Skip to content

Commit 1c62a4f

Browse files
authored
Merge pull request #41 from codacy/luis-ferreira/patch/rework-circle-ci
Rework Circle CI configuration to tag the version automatically and use orbs
2 parents ec10aa3 + b18a52b commit 1c62a4f

File tree

10 files changed

+52
-296
lines changed

10 files changed

+52
-296
lines changed

.circleci/config.yml

Lines changed: 41 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,163 +1,57 @@
1-
# CircleCI 2.0 configuration file
2-
version: 2
1+
version: 2.1
32

4-
# Re-usable blocks to reduce boilerplate in job definitions.
5-
references:
6-
host_environment_defaults: &host_environment_defaults
7-
# Customize the JVM maximum heap limit
8-
JAVA_OPTS: -Xmx3200m
9-
docker_environment_defaults: &docker_environment_defaults
10-
# Customize the JVM to read correct memory values
11-
JAVA_OPTS: '-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1'
12-
13-
default_java_job: &default_java_job
14-
docker:
15-
- image: circleci/openjdk:8-jdk
16-
environment:
17-
<<: *docker_environment_defaults
18-
environment:
19-
<<: *host_environment_defaults
20-
working_directory: ~/workdir
21-
22-
restore_source_code: &restore_source_code
23-
restore_cache:
24-
keys:
25-
- source-code-1.0.0-{{ .Branch }}-{{ .Revision }}
26-
- source-code-1.0.0-{{ .Branch }}
27-
- source-code-1.0.0
28-
restore_dependencies: &restore_dependencies
29-
restore_cache:
30-
keys:
31-
- sbt-ivy2-dependencies-1.0.0-{{ checksum "/tmp/dependencies.cache.tmp" }}
32-
- sbt-ivy2-dependencies-1.0.0
33-
restore_build: &restore_build
34-
restore_cache:
35-
keys:
36-
- sbt-build-1.0.1-{{ .Branch }}-{{ .Revision }}
37-
- sbt-build-1.0.1
38-
39-
setup_dependencies_key: &setup_dependencies_key
40-
run:
41-
name: Generate cache key
42-
command: |
43-
shasum build.sbt \
44-
project/plugins.sbt \
45-
project/build.properties > /tmp/dependencies.cache.tmp
46-
47-
jobs:
48-
checkout_code:
49-
<<: *default_java_job
50-
steps:
51-
- *restore_source_code
52-
- checkout
53-
- save_cache:
54-
key: source-code-1.0.0-{{ .Branch }}-{{ .Revision }}
55-
paths:
56-
- ~/workdir
57-
58-
sbt_dependencies:
59-
<<: *default_java_job
60-
steps:
61-
- *restore_source_code
62-
- *setup_dependencies_key
63-
- *restore_dependencies
64-
- run:
65-
name: Resolve dependencies
66-
command: |
67-
sbt update
68-
- save_cache:
69-
paths:
70-
- ~/.ivy2
71-
- ~/.sbt
72-
- ~/.coursier/cache/v1
73-
key: sbt-ivy2-dependencies-1.0.0-{{ checksum "/tmp/dependencies.cache.tmp" }}
74-
75-
compile:
76-
<<: *default_java_job
77-
steps:
78-
- *restore_source_code
79-
- *setup_dependencies_key
80-
- *restore_dependencies
81-
- *restore_build
82-
- run:
83-
name: Compile
84-
command: ./scripts/compile.sh
85-
- save_cache:
86-
paths:
87-
- ~/workdir/target
88-
- ~/workdir/project/target
89-
key: sbt-build-1.0.0-{{ .Branch }}-{{ .Revision }}
90-
91-
test:
92-
<<: *default_java_job
93-
steps:
94-
- *restore_source_code
95-
- *setup_dependencies_key
96-
- *restore_dependencies
97-
- *restore_build
98-
- run:
99-
name: Test
100-
command: ./scripts/test.sh
101-
- run:
102-
name: Store test reports
103-
working_directory: ~/
104-
command: |
105-
mkdir -p ~/coverage-reports/scoverage
106-
cp -f ~/workdir/target/scala-2.12/coverage-report/cobertura.xml ~/coverage-reports/scoverage/results.xml
107-
- store_test_results:
108-
path: ~/coverage-reports
109-
- store_artifacts:
110-
path: ~/workdir/target/scala-2.12/coverage-report
111-
- store_artifacts:
112-
path: ~/workdir/target/scala-2.12/scoverage-report
113-
- store_artifacts:
114-
path: ~/workdir/target/scala-2.12/scoverage-data
115-
116-
publish:
117-
<<: *default_java_job
118-
steps:
119-
- *restore_source_code
120-
- *setup_dependencies_key
121-
- *restore_dependencies
122-
- *restore_build
123-
- run:
124-
name: Install AWS CLI
125-
command: |
126-
sudo apt -y update
127-
sudo apt -y install python3-pip
128-
sudo python3 -m pip install awscli
129-
- run:
130-
name: Setup AWS Credentials
131-
command: ./scripts/setup-aws-credentials.sh
132-
- run:
133-
name: Retrieve GPG Keys
134-
command: |
135-
mkdir -p ~/.gnupg
136-
aws s3 sync --profile shared-services --include '*.gpg' s3://$AWS_CREDENTIALS_BUCKET/gnupg/ ~/.gnupg
137-
- run:
138-
name: Publish to Sonatype
139-
command: ./scripts/publish.sh 3.0.$CIRCLE_BUILD_NUM
3+
orbs:
4+
codacy: codacy/[email protected]
1405

1416
workflows:
1427
version: 2
143-
test-and-publish:
8+
compile_test_deploy:
1449
jobs:
145-
- checkout_code
146-
- sbt_dependencies:
10+
- codacy/checkout_and_version:
11+
write_sbt_version: true
12+
- codacy/sbt:
13+
name: populate_cache
14+
cmd: sbt "set scalafmtUseIvy in ThisBuild := false;update"
15+
persist_to_workspace: true
14716
requires:
148-
- checkout_code
149-
- compile:
17+
- codacy/checkout_and_version
18+
- codacy/sbt:
19+
name: check_fmt
20+
cmd: sbt "scalafmt::test;test:scalafmt::test;sbt:scalafmt::test"
15021
requires:
151-
- checkout_code
152-
- sbt_dependencies
153-
- test:
22+
- populate_cache
23+
- codacy/sbt:
24+
name: compile
25+
cmd: |
26+
sbt +compile
27+
sbt +test:compile
28+
requires:
29+
- check_fmt
30+
- codacy/sbt:
31+
name: test
32+
cmd: |
33+
sbt "coverage;coverageReport;coverageAggregate"
34+
sbt +test
35+
36+
if [ -z "$CODACY_PROJECT_TOKEN" ]; then
37+
echo "CODACY_PROJECT_TOKEN not found. Skipping send coverage to Codacy."
38+
else
39+
sbt codacyCoverage
40+
fi
15441
requires:
15542
- compile
156-
- publish:
43+
- codacy/sbt:
44+
name: publish
45+
cmd: |
46+
sbt "clean;retrieveGPGKeys"
47+
sbt "+publishSigned;sonatypeRelease"
15748
context: CodacyAWS
15849
requires:
15950
- test
16051
filters:
16152
branches:
16253
only:
16354
- master
55+
- codacy/tag_version:
56+
requires:
57+
- publish

build.sbt

Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
val scala211 = "2.11.12"
22
val scala212 = "2.12.8"
3-
val scala213 = "2.13.0"
3+
val scala213 = "2.13.1"
44

55
name := "codacy-plugins-api"
66
organization := "com.codacy"
77

88
scalaVersion := scala212
9+
910
crossScalaVersions := Seq(scala211, scala212, scala213)
1011

11-
libraryDependencies ++= Seq(
12-
"org.specs2" %% "specs2-core" % "4.6.0" % Test
13-
)
12+
libraryDependencies ++= Seq("org.specs2" %% "specs2-core" % "4.7.1" % Test)
1413

1514
unmanagedSourceDirectories in Compile += {
1615
val sourceDir = (sourceDirectory in Compile).value
@@ -20,68 +19,11 @@ unmanagedSourceDirectories in Compile += {
2019
}
2120
}
2221

23-
// Sonatype repository settings
24-
ThisBuild / credentials += Credentials(
25-
"Sonatype Nexus Repository Manager",
26-
"oss.sonatype.org",
27-
sys.env.getOrElse("SONATYPE_USER", "username"),
28-
sys.env.getOrElse("SONATYPE_PASSWORD", "password")
29-
)
30-
ThisBuild / organization := "com.codacy"
31-
ThisBuild / organizationName := "Codacy"
32-
ThisBuild / organizationHomepage := Some(url("https://www.codacy.com"))
22+
pgpPassphrase := Option(System.getenv("SONATYPE_GPG_PASSPHRASE")).map(_.toCharArray)
3323

34-
ThisBuild / scmInfo := Some(
35-
ScmInfo(
36-
url("https://github.com/codacy/codacy-plugins-api"),
37-
"scm:[email protected]:codacy/codacy-plugins-api"
38-
)
39-
)
40-
ThisBuild / developers := List(
41-
Developer(
42-
id = "johannegger",
43-
name = "Johann",
44-
email = "johann [at] codacy.com",
45-
url = url("https://github.com/johannegger")
46-
),
47-
Developer(
48-
id = "rtfpessoa",
49-
name = "Rodrigo Fernandes",
50-
email = "rodrigo [at] codacy.com",
51-
url = url("https://github.com/rtfpessoa")
52-
),
53-
Developer(
54-
id = "bmbferreira",
55-
name = "Bruno Ferreira",
56-
email = "bruno.ferreira [at] codacy.com",
57-
url = url("https://github.com/bmbferreira")
58-
),
59-
Developer(id = "xplosunn",
60-
name = "Hugo Sousa",
61-
email = "hugo [at] codacy.com",
62-
url = url("https://github.com/xplosunn")),
63-
Developer(
64-
id = "pedrocodacy",
65-
name = "Pedro Amaral",
66-
email = "pamaral [at] codacy.com",
67-
url = url("https://github.com/pedrocodacy")
68-
)
69-
)
24+
description := "A dependency free api for Codacy Tools"
7025

71-
ThisBuild / startYear := Some(2016)
72-
ThisBuild / description := "Library to develop Codacy tool plugins"
73-
ThisBuild / licenses := List(
74-
"The Apache Software License, Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt"))
75-
ThisBuild / homepage := Some(url("http://www.github.com/codacy/codacy-plugins-api/"))
26+
scmInfo := Some(
27+
ScmInfo(url("https://github.com/codacy/codacy-plugins-api"), "scm:git:[email protected]:codacy/codacy-plugins-api.git"))
7628

77-
// Remove all additional repository other than Maven Central from POM
78-
ThisBuild / pomIncludeRepository := { _ =>
79-
false
80-
}
81-
ThisBuild / publishTo := {
82-
val nexus = "https://oss.sonatype.org/"
83-
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
84-
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
85-
}
86-
ThisBuild / publishMavenStyle := true
87-
ThisBuild / publishArtifact in Test := false
29+
publicMvnPublish

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.3.0
1+
sbt.version=1.3.2

project/plugins.sbt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
// Sonatype publishing
2-
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
3-
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2-1")
1+
resolvers += Resolver.jcenterRepo
42

5-
// Dependency updates
6-
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.3.4")
7-
8-
// Coverage
9-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
10-
addSbtPlugin("com.codacy" % "sbt-codacy-coverage" % "1.3.15")
3+
addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "17.1.2")

scripts/build.sh

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/clean.sh

Lines changed: 0 additions & 5 deletions
This file was deleted.

scripts/compile.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

scripts/publish.sh

Lines changed: 0 additions & 22 deletions
This file was deleted.

scripts/setup-aws-credentials.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

scripts/test.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)