Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit d74771b

Browse files
authored
DW-3544 - Adding CircleCI build and import instructions (#2)
* DW-3544 - Adding CircleCI build and import instructions * DW-3544 - updating docs * DW-3544 - Resolving build issues * DW-3544 - more fixes * DW-3544 - more fixes * DW-3544 - add execute perms to gradle wrapper * DW-3544 - more fixes
1 parent 949b7f7 commit d74771b

4 files changed

Lines changed: 164 additions & 12 deletions

File tree

.circleci/config.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Java Gradle CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2.1
6+
7+
orbs:
8+
snyk: snyk/snyk@0.0.8
9+
10+
jobs:
11+
build:
12+
docker:
13+
# specify the version you desire here
14+
- image: circleci/openjdk:11.0.3-jdk-stretch
15+
16+
environment:
17+
# Customize the JVM maximum heap limit
18+
JVM_OPTS: -Xmx3200m
19+
TERM: dumb
20+
21+
steps:
22+
- checkout
23+
24+
# Download and cache dependencies
25+
- restore_cache:
26+
keys:
27+
- v1-dependencies-{{ checksum "build.gradle.kts" }}
28+
# fallback to using the latest cache if no exact match is found
29+
- v1-dependencies-
30+
31+
- run:
32+
name: Run gradle build
33+
command: |
34+
set -u
35+
set +o pipefail
36+
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
37+
set -o pipefail
38+
[ -z "$LATEST_VERSION" ] && LATEST_VERSION="0.0.0"
39+
VERSION=$(echo $LATEST_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
40+
sed -i s/version=.*/version=$VERSION/ gradle.properties
41+
./gradlew build
42+
43+
- save_cache:
44+
paths:
45+
- ~/.gradle
46+
key: v1-dependencies-{{ checksum "build.gradle.kts" }}
47+
48+
- run:
49+
name: mkdir for artifact
50+
command: |
51+
mkdir artifacts
52+
cp build/libs/dataworks-common-logging-*.jar ./artifacts/
53+
54+
- persist_to_workspace:
55+
root: artifacts
56+
paths:
57+
- dataworks-common-logging-*.jar
58+
59+
test:
60+
docker:
61+
- image: circleci/openjdk:11.0.3-jdk-stretch
62+
steps:
63+
- checkout
64+
- run:
65+
name: Run gradle tests
66+
command: |
67+
./gradlew test
68+
69+
snyk-pr:
70+
docker:
71+
- image: circleci/openjdk:11.0.3-jdk-stretch
72+
steps:
73+
- checkout
74+
# Snyk scan examines build.gradle for sev:high and will fail if found
75+
- snyk/scan:
76+
organization: dwp-dataworks
77+
severity-threshold: high
78+
target-file: build.gradle.kts
79+
project: '${CIRCLE_PROJECT_REPONAME}/pr-kotlin'
80+
81+
snyk-master:
82+
docker:
83+
- image: circleci/openjdk:11.0.3-jdk-stretch
84+
steps:
85+
- checkout
86+
# Snyk scan examines build.gradle for sev:all and will fail if found
87+
- snyk/scan:
88+
organization: dwp-dataworks
89+
severity-threshold: high
90+
target-file: build.gradle.kts
91+
project: '${CIRCLE_PROJECT_REPONAME}/master-kotlin'
92+
93+
94+
publish-github-release:
95+
docker:
96+
- image: cibuilds/github:0.10
97+
steps:
98+
- attach_workspace:
99+
at: ./artifacts
100+
- run:
101+
name: Publish Release on GitHub
102+
command: |
103+
set -u
104+
set +o pipefail
105+
LATEST_VERSION=$(curl --silent "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
106+
set -o pipefail
107+
[ -z "$LATEST_VERSION" ] && LATEST_VERSION="0.0.0"
108+
VERSION=$(echo $LATEST_VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
109+
ghr \
110+
-t ${GITHUB_TOKEN} \
111+
-u ${CIRCLE_PROJECT_USERNAME} \
112+
-r ${CIRCLE_PROJECT_REPONAME} \
113+
-c ${CIRCLE_SHA1} -delete \
114+
${VERSION} ./artifacts/
115+
116+
workflows:
117+
version: 2
118+
build-and-deploy:
119+
jobs:
120+
- build
121+
- test
122+
- snyk-pr:
123+
filters:
124+
branches:
125+
ignore: master
126+
- snyk-master:
127+
filters:
128+
branches:
129+
only: master
130+
- publish-github-release:
131+
requires:
132+
- build
133+
filters:
134+
branches:
135+
only: master

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
11
# dataworks-common-logging
22
Kotlin utility library to be used in Dataworks applications to ensure common logging format.
33

4+
## Using in your project
5+
JAR files for this project are published to this repositories [GitHub Packages page](https://github.com/dwp/dataworks-common-logging/packages). To include it in your project, follow the [official github instructions](https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-gradle-for-use-with-github-packages). Configuration should look similar to the below.
6+
7+
#### Inclusion via Gradle
8+
```kotlin
9+
repositories {
10+
maven {
11+
name = "GitHubPackages"
12+
url = uri("https://maven.pkg.github.com/dwp/dataworks-common-logging")
13+
credentials {
14+
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
15+
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
16+
}
17+
}
18+
}
19+
```
20+
Where `gpr.user` or `USERNAME` resolves to your GH username and `gpr.key` or `TOKEN` resolves to a GH PAT code.
21+
22+
#### Logger configuration
23+
To utilise this library in your project, you will need to include the compiled this projects`.jar` file. You are also required to add a logback XML file in the resources for your project, and add the following code as an `appender`. This will inform the logging framework to use `LoggerLayoutAppender` to parse messages into our format.
24+
```xml
25+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
26+
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
27+
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
28+
<layout class="app.utils.logging.LoggerLayoutAppender"/>
29+
</encoder>
30+
</appender>
31+
```
32+
433
## Log formatting
534
Dataworks common logging provides opinionated ways to write messages into log files, using [sl4j](http://www.slf4j.org/).
635

@@ -15,17 +44,6 @@ Out of the box, it provides functionality to convert log messages to JSON and ap
1544
| correlation_id | 1 |
1645
| hostname | 127.0.0.1 |
1746

18-
## Using in projects
19-
To include this library in your project you will need to include the compiled this projects`.jar` file. You are also required to add a logback XML file in the resources for your project, and add the following code as an `appender`. This will inform the logging framework to use `LoggerLayoutAppender` to parse messages into our format.
20-
```xml
21-
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
22-
<!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
23-
<encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
24-
<layout class="app.utils.logging.LoggerLayoutAppender"/>
25-
</encoder>
26-
</appender>
27-
```
28-
2947
## Custom fields in log messages
3048
For the case where you would like to add custom values to the logging lines which are output, `LogFields` provides functionality to do this.
3149
```kotlin
@@ -118,4 +136,3 @@ Some example outputs are displayed below. Note that in actuality these will be o
118136
"hostname": "127.0.0.1"
119137
}
120138
```
121-

gradlew

100644100755
File mode changed.

gradlew.bat

100644100755
File mode changed.

0 commit comments

Comments
 (0)