Skip to content

Commit 2ddc8f0

Browse files
authored
Merge pull request #20 from codacy/publish-on-circleci
Publish on circle ci
2 parents 7bee753 + 3d96a7e commit 2ddc8f0

File tree

6 files changed

+213
-10
lines changed

6 files changed

+213
-10
lines changed

.circleci/config.yml

Lines changed: 156 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,162 @@
1+
# CircleCI 2.0 configuration file
12
version: 2
2-
jobs:
3-
build:
3+
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
414
docker:
5-
- image: hseeberger/scala-sbt:8u151-2.12.5-1.1.2
15+
- image: circleci/openjdk:8-jdk
16+
environment:
17+
<<: *docker_environment_defaults
18+
environment:
19+
<<: *host_environment_defaults
620
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.0-{{ .Branch }}-{{ .Revision }}
37+
- sbt-build-1.0.0
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
750
steps:
51+
- *restore_source_code
852
- checkout
9-
- restore_cache:
10-
key: scala-library-dependencies-{{ checksum "build.sbt" }}
11-
- run: sbt compile
12-
- run: sbt test:compile
1353
- save_cache:
14-
key: scala-library-dependencies-{{ checksum "build.sbt" }}
15-
paths: [ "~/.m2", "~/.ivy2", "~/.cache/coursier" ]
16-
- run: ./scripts/test.sh
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+
key: sbt-ivy2-dependencies-1.0.0-{{ checksum "/tmp/dependencies.cache.tmp" }}
73+
74+
compile:
75+
<<: *default_java_job
76+
steps:
77+
- *restore_source_code
78+
- *setup_dependencies_key
79+
- *restore_dependencies
80+
- *restore_build
81+
- run:
82+
name: Compile
83+
command: ./scripts/compile.sh
84+
- save_cache:
85+
paths:
86+
- ~/workdir/target
87+
- ~/workdir/project/target
88+
key: sbt-build-1.0.0-{{ .Branch }}-{{ .Revision }}
89+
90+
test:
91+
<<: *default_java_job
92+
steps:
93+
- *restore_source_code
94+
- *setup_dependencies_key
95+
- *restore_dependencies
96+
- *restore_build
97+
- run:
98+
name: Test
99+
command: ./scripts/test.sh
100+
- run:
101+
name: Store test reports
102+
working_directory: ~/
103+
command: |
104+
mkdir -p ~/coverage-reports/scoverage
105+
cp -f ~/workdir/target/scala-2.11/coverage-report/cobertura.xml ~/coverage-reports/scoverage/results.xml
106+
- store_test_results:
107+
path: ~/coverage-reports
108+
- store_artifacts:
109+
path: ~/workdir/target/scala-2.11/coverage-report
110+
- store_artifacts:
111+
path: ~/workdir/target/scala-2.11/scoverage-report
112+
- store_artifacts:
113+
path: ~/workdir/target/scala-2.11/scoverage-data
114+
115+
publish:
116+
<<: *default_java_job
117+
steps:
118+
- *restore_source_code
119+
- *setup_dependencies_key
120+
- *restore_dependencies
121+
- *restore_build
122+
- run:
123+
name: Install AWS CLI
124+
command: |
125+
sudo apt -y update
126+
sudo apt -y install python3-pip
127+
sudo python3 -m pip install awscli
128+
- run:
129+
name: Setup AWS Credentials
130+
command: ./scripts/setup-aws-credentials.sh
131+
- run:
132+
name: Retrieve GPG Keys
133+
command: |
134+
mkdir -p ~/.gnupg
135+
aws s3 sync --profile shared-services --include '*.gpg' s3://$AWS_CREDENTIALS_BUCKET/gnupg/ ~/.gnupg
136+
- run:
137+
name: Publish to Sonatype
138+
command: ./scripts/publish.sh 3.0.$CIRCLE_BUILD_NUM
139+
140+
workflows:
141+
version: 2
142+
test-and-publish:
143+
jobs:
144+
- checkout_code
145+
- sbt_dependencies:
146+
requires:
147+
- checkout_code
148+
- compile:
149+
requires:
150+
- checkout_code
151+
- sbt_dependencies
152+
- test:
153+
requires:
154+
- compile
155+
- publish:
156+
context: CodacyAWS
157+
requires:
158+
- test
159+
filters:
160+
branches:
161+
only:
162+
- master

scripts/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
current_directory="$( cd "$( dirname "$0" )" && pwd )"
6+
7+
${current_directory}/compile.sh
8+
${current_directory}/test.sh

scripts/clean.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
sbt clean

scripts/compile.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
sbt compile
6+
sbt test:compile

scripts/publish.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
CURRENT_BRANCH="$(git symbolic-ref --short HEAD)"
6+
PUBLISH_BRANCH="master"
7+
8+
BASE_VERSION="0.1.0-pre"
9+
DEFAULT_VERSION="${BASE_VERSION}.${CURRENT_BRANCH}-SNAPSHOT"
10+
11+
if [ -n "$1" ]; then
12+
VERSION="$1"
13+
else
14+
VERSION="$DEFAULT_VERSION"
15+
fi
16+
17+
echo "Publishing version ${VERSION}"
18+
if [[ -n "$CI" ]] && [[ "$CURRENT_BRANCH" == "$PUBLISH_BRANCH" || "$CIRCLE_BRANCH" == "$PUBLISH_BRANCH" ]]; then
19+
sbt 'set version := "'"${VERSION}"'"' 'set pgpPassphrase := Some("'"$SONATYPE_GPG_PASSPHRASE"'".toCharArray)' +publishSigned
20+
sbt 'set version := "'"${VERSION}"'"' +sonatypeRelease
21+
else
22+
sbt 'set version := "'"${VERSION}"'"' +publishLocal
23+
fi

scripts/setup-aws-credentials.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
mkdir -p ~/.aws && touch ~/.aws/credentials
6+
7+
cat >> ~/.aws/credentials << EOF
8+
[default]
9+
aws_access_key_id=$ACCESS_KEY_ID
10+
aws_secret_access_key=$SECRET_ACCESS_KEY
11+
12+
[shared-services]
13+
source_profile = default
14+
role_arn = arn:aws:iam::$ACCOUNT_ID:role/CredentialsBucketReader
15+
EOF

0 commit comments

Comments
 (0)