Skip to content

Commit a49d68c

Browse files
authored
AJ-1094: Initial Project Setup and Hello World CLI (#1)
undefined
1 parent e8fcf63 commit a49d68c

23 files changed

+891
-1
lines changed

.github/workflows/build-and-test.yml

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore: [ '*.md' ]
7+
pull_request:
8+
branches: [ '**' ]
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up JDK
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
cache: 'gradle'
22+
23+
- name: Build all projects without running tests
24+
run: ./gradlew --build-cache build -x test
25+
26+
source-clear:
27+
needs: [ build ]
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v3
32+
- name: Set up JDK
33+
uses: actions/setup-java@v3
34+
with:
35+
java-version: '17'
36+
distribution: 'temurin'
37+
cache: 'gradle'
38+
39+
- name: SourceClear scan
40+
env:
41+
SRCCLR_API_TOKEN: ${{ secrets.SRCCLR_API_TOKEN }}
42+
run: ./gradlew --build-cache srcclr
43+
44+
unit-tests-and-sonarqube:
45+
needs: [ build ]
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
# Needed by sonar to get the git history for the branch the PR will be merged into.
50+
with:
51+
fetch-depth: 0
52+
- name: Set up JDK
53+
uses: actions/setup-java@v3
54+
with:
55+
java-version: '17'
56+
distribution: 'temurin'
57+
cache: 'gradle'
58+
- name: Test with coverage
59+
run: ./gradlew --build-cache test jacocoTestReport
60+
- name: SonarQube scan for library
61+
run: ./gradlew --build-cache :library:sonar --info
62+
env:
63+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
64+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65+
- name: SonarQube scan for cli
66+
run: ./gradlew --build-cache :cli:sonar --info
67+
env:
68+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
69+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70+
71+
notify-slack:
72+
needs: [ build, unit-tests-and-sonarqube, source-clear ]
73+
runs-on: ubuntu-latest
74+
75+
if: failure() && github.ref == 'refs/heads/main'
76+
77+
steps:
78+
- name: Notify slack on failure
79+
uses: broadinstitute/[email protected]
80+
env:
81+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
82+
with:
83+
channel: '#dsp-analysis-journeys-alerts'
84+
status: failure
85+
author_name: Build on dev
86+
fields: job,message
87+
text: 'Build failed :sadpanda:'
88+
username: 'Java-PFB GitHub Action'
89+
90+
dispatch-tag:
91+
needs: [ build, unit-tests-and-sonarqube, source-clear ]
92+
runs-on: ubuntu-latest
93+
94+
if: success() && github.ref == 'refs/heads/main'
95+
96+
steps:
97+
- name: Fire off tag action
98+
uses: broadinstitute/workflow-dispatch@v1
99+
with:
100+
workflow: Tag
101+
token: ${{ secrets.BROADBOT_TOKEN }}

.github/workflows/publish.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Publish and deploy
2+
on: create
3+
4+
env:
5+
SERVICE_NAME: ${{ github.event.repository.name }}
6+
GOOGLE_PROJECT: broad-dsp-gcr-public
7+
8+
jobs:
9+
publish-job:
10+
if: startsWith(github.ref, 'refs/tags/')
11+
permissions:
12+
contents: 'read'
13+
id-token: 'write'
14+
runs-on: ubuntu-latest
15+
outputs:
16+
tag: ${{ steps.tag.outputs.tag }}
17+
steps:
18+
- name: Enable publish with AJ-1095
19+
run: echo "TODO"
20+
# - uses: actions/checkout@v3
21+
# - name: Set up JDK
22+
# uses: actions/setup-java@v3
23+
# with:
24+
# java-version: '17'
25+
# distribution: 'temurin'
26+
# cache: 'gradle'
27+
28+
# - name: Parse tag
29+
# id: tag
30+
# run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
31+
#
32+
# - name: Publish to Artifactory
33+
# run: ./gradlew --build-cache :client:artifactoryPublish
34+
# env:
35+
# ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
36+
# ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
37+
# ARTIFACTORY_REPO_KEY: "libs-release-local"
38+
#
39+
# - name: Notify slack on failure
40+
# uses: broadinstitute/[email protected]
41+
# if: failure()
42+
# env:
43+
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
44+
# with:
45+
# channel: '#dsp-analysis-journeys-alerts'
46+
# status: failure
47+
# author_name: Publish to dev
48+
# fields: job
49+
# text: 'Publish failed :sadpanda:'
50+
# username: 'Java-PFB GitHub Action'

.github/workflows/tag.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tag
2+
on: workflow_dispatch
3+
4+
jobs:
5+
tag-job:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout current code
9+
uses: actions/checkout@v3
10+
with:
11+
token: ${{ secrets.BROADBOT_TOKEN }} # this allows the push to succeed later
12+
- name: Bump the tag to a new version
13+
# https://github.com/DataBiosphere/github-actions/tree/master/actions/bumper
14+
uses: databiosphere/github-actions/actions/[email protected]
15+
id: tag
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.BROADBOT_TOKEN }}
18+
HOTFIX_BRANCHES: hotfix.*
19+
DEFAULT_BUMP: minor
20+
RELEASE_BRANCHES: main
21+
VERSION_FILE_PATH: settings.gradle
22+
VERSION_LINE_MATCH: "^\\s*gradle.ext.releaseVersion\\s*=\\s*'.*'"

.gitignore

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
7+
bootrun.log
8+
9+
### STS ###
10+
.apt_generated
11+
.classpath
12+
.factorypath
13+
.project
14+
.settings
15+
.springBeans
16+
.sts4-cache
17+
bin/
18+
!**/src/main/**/bin/
19+
!**/src/test/**/bin/
20+
21+
# Emacs backup files #
22+
*.*~
23+
24+
### IntelliJ IDEA ###
25+
.idea/
26+
*.iml
27+
28+
### VS Code ###
29+
.vscode/
30+
31+
# Mac directory metadata
32+
.DS_Store
33+
34+
# PyEnv environment files
35+
.env/
36+
37+
# Ignore generated credentials from google-github-actions/auth
38+
gha-creds-*.json

LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2023, Broad Institute
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+40-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1-
# java-pfb
1+
# Java-PFB
2+
3+
A java implementation of the [pyPFB](https://github.com/uc-cdis/pypfb) library that includes a CLI and a java library.
4+
5+
The CLI is a wrapper around the library. See the [CLI README](cli/README.md) for more information.
6+
7+
## Running SourceClear locally
8+
9+
[SourceClear](https://srcclr.github.io) is a static analysis tool that scans a project's Java
10+
dependencies for known vulnerabilities. If you get a build failure due a SourceClear error and want
11+
to debug the problem locally, you need to get the API token from vault before running the gradle
12+
task.
13+
14+
```shell
15+
export SRCCLR_API_TOKEN=$(vault read -field=api_token secret/secops/ci/srcclr/gradle-agent)
16+
./gradlew srcclr
17+
```
18+
19+
Results of the scan are uploaded to [Defect DOJO](https://defectdojo.dsp-appsec.broadinstitute.org/dashboard).
20+
21+
## Running SonarQube locally
22+
23+
[SonarQube](https://www.sonarqube.org) is a static analysis code that scans code for a wide
24+
range of issues, including maintainability and possible bugs. If you get a build failure due to
25+
SonarQube and want to debug the problem locally, you need to get the the sonar token from vault
26+
before runing the gradle task.
27+
28+
```shell
29+
export SONAR_TOKEN=$(vault read -field=sonar_token secret/secops/ci/sonarcloud/java-pfb)
30+
./gradlew sonar
31+
```
32+
33+
Unlike SourceClear, running this task produces no output unless your project has errors. To always
34+
generate a report, run using `--info`:
35+
36+
```shell
37+
./gradlew sonar --info
38+
```
39+
40+
We run the scans for two projects: [java-pfb](https://sonarcloud.io/project/overview?id=DataBiosphere_java-pfb) and [java-pfb-cli](https://sonarcloud.io/project/overview?id=DataBiosphere_java-pfb-cli). The results are uploaded to the sonarcloud dashbaord.

buildSrc/build.gradle

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
plugins {
2+
id 'groovy-gradle-plugin'
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
8+
9+
dependencies {
10+
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0'
11+
implementation 'com.srcclr.gradle:com.srcclr.gradle.gradle.plugin:3.1.12'
12+
implementation 'org.sonarqube:org.sonarqube.gradle.plugin:4.2.1.3168'
13+
implementation 'info.picocli:picocli:4.7.4'
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
plugins {
2+
id 'idea'
3+
id 'jacoco'
4+
id 'java'
5+
id 'org.sonarqube'
6+
id 'com.diffplug.spotless'
7+
}
8+
9+
boolean isCiServer = System.getenv().containsKey("CI")
10+
11+
java {
12+
toolchain {
13+
languageVersion = JavaLanguageVersion.of(17)
14+
}
15+
}
16+
17+
repositories {
18+
maven {
19+
// Terra proxy for maven central
20+
url 'https://broadinstitute.jfrog.io/broadinstitute/maven-central/'
21+
}
22+
mavenCentral()
23+
maven {
24+
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-release/'
25+
}
26+
maven {
27+
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-snapshot-local/'
28+
}
29+
}
30+
31+
dependencies {
32+
testImplementation 'org.hamcrest:hamcrest:2.2'
33+
34+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
35+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
36+
}
37+
38+
version = gradle.releaseVersion
39+
group = 'bio.terra'
40+
41+
spotless {
42+
java {
43+
targetExclude "${buildDir}/**"
44+
googleJavaFormat()
45+
}
46+
}
47+
48+
// Run spotless check when running in github actions, otherwise run spotless apply.
49+
compileJava {
50+
if (isCiServer) {
51+
dependsOn(spotlessCheck)
52+
} else {
53+
dependsOn(spotlessApply)
54+
}
55+
}
56+
57+
test {
58+
useJUnitPlatform()
59+
}
60+
61+
jacocoTestReport {
62+
reports {
63+
// sonarqube requires XML coverage output to upload coverage data
64+
xml.required = true
65+
}
66+
}
67+
68+
sonar {
69+
properties {
70+
property "sonar.projectKey", "DataBiosphere_java-pfb"
71+
property "sonar.projectName", "java-pfb"
72+
property "sonar.organization", "broad-databiosphere"
73+
property "sonar.host.url", "https://sonarcloud.io"
74+
}
75+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
plugins {
2+
id 'bio.terra.pfb.java-common-conventions'
3+
id 'java-library'
4+
}

0 commit comments

Comments
 (0)