Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AJ-1095: Publish Library and CLI #3

Merged
merged 89 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
c2fe637
First pass at enabling publish
snf2ye Jul 20, 2023
f9839c5
Add readme for publishing process
snf2ye Jul 24, 2023
c166dec
Add publishing to gradle and GHA
snf2ye Jul 24, 2023
d51d973
working local publish
snf2ye Jul 24, 2023
cb15888
Update name for package
snf2ye Jul 24, 2023
d18a403
Ensure git properties is correctly generated
snf2ye Jul 24, 2023
5b5ec0c
Update name
snf2ye Jul 24, 2023
841311b
Publish CLI to artifactory
snf2ye Jul 24, 2023
b71b879
Remaining TODO
snf2ye Jul 24, 2023
8eb9e51
undo downgrading gradle
snf2ye Jul 25, 2023
adc0d9b
Add import from library code
snf2ye Jul 25, 2023
a40b1d1
Update name to action
snf2ye Jul 25, 2023
e4f9313
Upgrade artifactory; set git properties config for CLI
snf2ye Jul 25, 2023
28bea6e
Add instructions for cli upgrade
snf2ye Jul 25, 2023
9231398
Add comments
snf2ye Jul 25, 2023
b2233d5
Use re-usable GHA workflows instead of dispatch
snf2ye Jul 25, 2023
d464abd
PR Review
snf2ye Jul 26, 2023
4070044
Add alias command
snf2ye Jul 27, 2023
40e1d56
test out new GHA
snf2ye Jul 31, 2023
26576f1
Add as release branch for testing
snf2ye Jul 31, 2023
119d925
try pattern
snf2ye Jul 31, 2023
e55b4e7
add slash
snf2ye Jul 31, 2023
7a1ad3e
bump 0.4.0
Jul 31, 2023
ae46970
Pull version from git config
snf2ye Jul 31, 2023
4404848
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Jul 31, 2023
2d1b752
Remove -SNAPSHOT from version
snf2ye Aug 1, 2023
17897c0
revert to v3
snf2ye Aug 1, 2023
74ae428
Updated main class declaration and add ability to run cli
snf2ye Aug 1, 2023
cae1cb6
Try adding automatic creation of release with CLI jar
snf2ye Aug 1, 2023
129cd0f
[undo before merge] add release job to tag action just for testing
snf2ye Aug 1, 2023
302b5ee
bump 0.4.0
Aug 1, 2023
ef6e5a2
test
snf2ye Aug 1, 2023
d536fc8
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
2d7ca3d
test
snf2ye Aug 1, 2023
ff47321
bump 0.5.0
Aug 1, 2023
ba39847
Revert "bump 0.5.0"
snf2ye Aug 1, 2023
d59de79
try using workspace path
snf2ye Aug 1, 2023
bb9c1c5
test
snf2ye Aug 1, 2023
a4a819d
bump 0.5.0
Aug 1, 2023
a53412b
test
snf2ye Aug 1, 2023
93d6baf
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
217dc79
bump 0.6.0
Aug 1, 2023
c9db1cd
try again
snf2ye Aug 1, 2023
14d5829
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
a4fccc4
variable name
snf2ye Aug 1, 2023
b381f4c
bump 0.7.0
Aug 1, 2023
73f7b2f
test
snf2ye Aug 1, 2023
2bf80a7
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
08b2666
bump 0.8.0
Aug 1, 2023
d63164e
try release upgrade command
snf2ye Aug 1, 2023
77de92a
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
aa6687e
bump 0.9.0
Aug 1, 2023
4ea5b58
create and upload files and generate notes
snf2ye Aug 1, 2023
c70964e
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
032fe8c
bump 0.10.0
Aug 1, 2023
1886829
remove github workspace
snf2ye Aug 1, 2023
b90a8c0
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
1ce9fa0
bump 0.11.0
Aug 1, 2023
162b07f
test
snf2ye Aug 1, 2023
d91b74b
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
0e1c911
bump 0.12.0
Aug 1, 2023
62d3db4
make sure we're checking out the tagged
snf2ye Aug 1, 2023
f67f49c
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
d98af31
fix formatting
snf2ye Aug 1, 2023
1aee392
bump 0.13.0
Aug 1, 2023
234c01d
Final changes to github actions; revert settings.gradle
snf2ye Aug 1, 2023
38d94a4
Merge branch 'sh-aj-1095-publilsh' of https://github.com/DataBiospher…
snf2ye Aug 1, 2023
172505f
Update cli release related code
snf2ye Aug 1, 2023
213eb49
Update readme for CLI release
snf2ye Aug 1, 2023
8cfff95
Fix spotbugs
snf2ye Aug 1, 2023
c100b79
Update README.md and include distribution in the release
snf2ye Aug 1, 2023
d0f51c9
pass output from tag to release-cli
snf2ye Aug 1, 2023
51e3b45
spotbugs fix
snf2ye Aug 1, 2023
a50708f
Add comment
snf2ye Aug 2, 2023
0d7456e
Add test coverage
snf2ye Aug 2, 2023
96d1b03
Add more info to readme on how to use published resources
snf2ye Aug 2, 2023
f8f2edd
Update GHA - fix inputs, outputs
snf2ye Aug 3, 2023
2d82292
UNDO BEFORE MERGE - undo main
snf2ye Aug 3, 2023
25809fc
Consolidate slack notifications and have single gradlew build call
snf2ye Aug 3, 2023
56f6a5b
add workflow dispatch
snf2ye Aug 3, 2023
1304203
add back ref
snf2ye Aug 3, 2023
2ceffbe
Need secrets inherit in order use secrets in called workflow
snf2ye Aug 3, 2023
ae5ccc7
test full workflow - undo before merge
snf2ye Aug 3, 2023
532fb34
Revert "test full workflow - undo before merge"
snf2ye Aug 3, 2023
56530d6
PR Review: Update GitConfiguration
snf2ye Aug 3, 2023
7af365e
PR Review: Remove workflow_dispatch trigger, Update required secrets
snf2ye Aug 8, 2023
68271bd
PR Review: Updated command
snf2ye Aug 8, 2023
0fa541f
PR Review: Remove artifact group
snf2ye Aug 8, 2023
083145d
update formatting
snf2ye Aug 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Build and Test
on:
push:
branches: [ main ]
paths-ignore: [ '*.md' ]
paths-ignore:
- '*.md'
- 'settings.gradle' # Avoid running workflows on version bumps
pull_request:
branches: [ '**' ]

Expand Down Expand Up @@ -68,8 +70,30 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

notify-slack:
tag:
needs: [ build, unit-tests-and-sonarqube, source-clear ]
uses: ./.github/workflows/tag.yml
if: success() && github.ref == 'refs/heads/main'
secrets: inherit

publish-library:
needs: [ tag ]
uses: ./.github/workflows/publish.yml
if: success() && github.ref == 'refs/heads/main'
secrets: inherit
with:
tag: ${{ needs.tag.outputs.tag }}

release-cli:
needs: [ tag ]
uses: ./.github/workflows/release-cli.yml
secrets: inherit
if: success() && github.ref == 'refs/heads/main'
with:
tag: ${{ needs.tag.outputs.tag }}
Comment on lines +73 to +93
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I commented on this before, but I can't find the comment now. I think all three steps can be run as part of a single job. Something like

  tag-and-release:
    needs: [ unit-tests-and-sonarqube, source-clear ]
    if: success() && github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - name: Tag
        uses: .github/workflows/tag.yml
        secrets: inherit
      - name: Publish library
        uses: .github/workflows/publish.yml
        with:
          tag: ${{ tag.outputs.tag }}
        secrets: inherit
      - name: Release CLI
        uses: .github/workflows/release-cli.yml
        with:
          tag: ${{ tag.outputs.tag }}
        secrets: inherit

Although the yaml lint is complaining about the secrets: inherit lines. Not sure why, to me it looks the same as the examples here: https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-inputs-and-secrets-in-a-reusable-workflow

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I probably missed that suggestion!

I'd rather keep them as separate jobs. If nothing else, I like the diagram it produces 😀. I also have it so that the published library and publish cli jobs can run at the same time once the tag job completes (not that it saves that much time- they're both quick jobs).
image


notify-slack-on-failure:
needs: [ build, unit-tests-and-sonarqube, source-clear, tag, publish-library, release-cli ]
runs-on: ubuntu-latest

if: failure() && github.ref == 'refs/heads/main'
Expand All @@ -86,16 +110,3 @@ jobs:
fields: job,message
text: 'Build failed :sadpanda:'
username: 'Java-PFB GitHub Action'

dispatch-tag:
needs: [ build, unit-tests-and-sonarqube, source-clear ]
runs-on: ubuntu-latest

if: success() && github.ref == 'refs/heads/main'

steps:
- name: Fire off tag action
uses: broadinstitute/workflow-dispatch@v1
with:
workflow: Tag
token: ${{ secrets.BROADBOT_TOKEN }}
61 changes: 24 additions & 37 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Publish and deploy
on: create
name: Publish Library to Artifactory
on:
workflow_call:
inputs:
tag:
required: true
type: string
snf2ye marked this conversation as resolved.
Show resolved Hide resolved

env:
SERVICE_NAME: ${{ github.event.repository.name }}
Expand All @@ -12,39 +17,21 @@ jobs:
contents: 'read'
id-token: 'write'
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- name: Enable publish with AJ-1095
run: echo "TODO"
# - uses: actions/checkout@v3
# - name: Set up JDK
# uses: actions/setup-java@v3
# with:
# java-version: '17'
# distribution: 'temurin'
# cache: 'gradle'

# - name: Parse tag
# id: tag
# run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT
#
# - name: Publish to Artifactory
# run: ./gradlew --build-cache :client:artifactoryPublish
# env:
# ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
# ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
# ARTIFACTORY_REPO_KEY: "libs-release-local"
#
# - name: Notify slack on failure
# uses: broadinstitute/action-slack@v3.8.0
# if: failure()
# env:
# SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# with:
# channel: '#dsp-analysis-journeys-alerts'
# status: failure
# author_name: Publish to dev
# fields: job
# text: 'Publish failed :sadpanda:'
# username: 'Java-PFB GitHub Action'
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: ${{ inputs.tag }}
token: ${{ secrets.BROADBOT_TOKEN }}
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Publish Library Artifactory
run: ./gradlew --build-cache :library:artifactoryPublish
env:
ARTIFACTORY_USERNAME: ${{ secrets.ARTIFACTORY_USERNAME }}
ARTIFACTORY_PASSWORD: ${{ secrets.ARTIFACTORY_PASSWORD }}
ARTIFACTORY_REPO_KEY: "libs-release-local"
30 changes: 30 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Create Github Release with CLI Jar and Distribution
on:
workflow_call:
inputs:
tag:
required: true
type: string

jobs:
release-job:
runs-on: "ubuntu-latest"
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: ${{ inputs.tag }}
token: ${{ secrets.BROADBOT_TOKEN }}
- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'gradle'
- name: Build jar with latest tagged version
run: |
./gradlew --build-cache jar assembleDist
- name: Create tagged release with CLI jar
run: gh release create ${{ inputs.tag }} 'cli/build/libs/java-pfb-cli-${{ inputs.tag }}.jar' 'cli/build/distributions/cli-${{ inputs.tag }}.zip' --generate-notes --verify-tag
env:
GH_TOKEN: ${{ secrets.BROADBOT_TOKEN }}
11 changes: 9 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: Tag
on: workflow_dispatch
on:
workflow_dispatch: {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still called on workflow_dispatch? If not I think you can remove this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove it!

Just wanted to note that this trigger enables the "run workflow" button in the GitHub UI. But, I agree, I don't think it's needed for the tag action.
image

workflow_call:
outputs:
tag:
value: ${{ jobs.tag-job.outputs.tag }}

jobs:
tag-job:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.tag }}
steps:
- name: Checkout current code
uses: actions/checkout@v3
Expand All @@ -19,4 +26,4 @@ jobs:
DEFAULT_BUMP: minor
RELEASE_BRANCHES: main
VERSION_FILE_PATH: settings.gradle
VERSION_LINE_MATCH: "^\\s*gradle.ext.releaseVersion\\s*=\\s*'.*'"
VERSION_LINE_MATCH: "^\\s*gradle.ext.releaseVersion\\s*=\\s*'.*'"
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

A java implementation of the [pyPFB](https://github.com/uc-cdis/pypfb) library that includes a CLI and a java library.


## Getting Started
See the [library README](library/README.md) for more details on how to reference the lbirary in your project.

The CLI is a wrapper around the library. See the [CLI README](cli/README.md) for more information.

## Running SourceClear locally
## Developer Information

### Publishing

See [library](library/README.md) and [cli](cli/README.md) readmes for more details.

### Running SourceClear locally

[SourceClear](https://srcclr.github.io) is a static analysis tool that scans a project's Java
dependencies for known vulnerabilities. If you get a build failure due a SourceClear error and want
Expand All @@ -18,7 +28,7 @@ export SRCCLR_API_TOKEN=$(vault read -field=api_token secret/secops/ci/srcclr/gr

Results of the scan are uploaded to [Veracode](https://sca.analysiscenter.veracode.com/workspaces/jppForw/projects/768265/issues). You can request an account to view results from #dsp-infosec-champions.

## Running SonarQube locally
### Running SonarQube locally

[SonarQube](https://www.sonarqube.org) is a static analysis code that scans code for a wide
range of issues, including maintainability and possible bugs. If you get a build failure due to
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ dependencies {
implementation 'com.srcclr.gradle:com.srcclr.gradle.gradle.plugin:3.1.12'
implementation 'org.sonarqube:org.sonarqube.gradle.plugin:4.2.1.3168'
implementation 'info.picocli:picocli:4.7.4'
implementation 'com.gorylenko.gradle-git-properties:gradle-git-properties:2.3.1'
implementation 'org.jfrog.buildinfo:build-info-extractor-gradle:5.0.3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
plugins {
id 'bio.terra.pfb.java-common-conventions'
id 'application'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'java'
id 'org.sonarqube'
id 'com.diffplug.spotless'
id 'com.gorylenko.gradle-git-properties'
}

boolean isCiServer = System.getenv().containsKey("CI")
Expand All @@ -14,20 +15,6 @@ java {
}
}

repositories {
maven {
// Terra proxy for maven central
url 'https://broadinstitute.jfrog.io/broadinstitute/maven-central/'
}
mavenCentral()
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-release/'
}
maven {
url 'https://broadinstitute.jfrog.io/broadinstitute/libs-snapshot-local/'
}
}

dependencies {
testImplementation 'org.hamcrest:hamcrest:2.2'

Expand Down
74 changes: 67 additions & 7 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
Current usage of CLI:
First, run "jar" gradle task in cli project.
Java PFB CLI
===

## Available Commands
- hello
- getNumber5
- --version
- --help

## Local Run and Development

### Option 1 - Run via Gradle (Suggested workflow)

Run the following command to build the library and CLI jar and execute a command:
```shell
./gradlew run --args=<command>
```

### Option 2: Assemble distribution zip and run
Run the following command to build the library and CLI jar:
```shell
./gradlew :cli:assembleDist
```
Unzip the distribution
```shell
unzip cli/build/distributions/cli-<VERSION>.zip
```
Run commands
```shell
./cli-<VERSION>/bin/cli <command>
```

### Option 3: Build and run jar
Run the following command to build the library and CLI jar:
```shell
./gradlew :cli:jar
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
```

Then, you can use the CLI with the following command:
```shell
java -cp "cli/build/libs/java-pfb-cli.jar" bio.terra.pfb.JavaPfbCommand <command>
java -cp "cli/build/libs/java-pfb-cli-<VERSION>.jar" bio.terra.pfb.JavaPfbCommand <command>
```
Available Commands:
- hello
- --version
- --help
An alias can be created to simplify this command:
```shell
alias pfb='java -cp "cli/build/libs/java-pfb-cli-<VERSION>.jar" bio.terra.pfb.JavaPfbCommand'
```
Example usage of the alias:
```shell
pfb --version
```

# Download and run the CLI
## Option 1 - Run from Jar Downloaded from Github Release
1) Download Jar from latest Github release.
2) Note the location of the downloaded jar and run the jar with the following command:
```shell
java -cp "<PATH-TO-JAR>" bio.terra.pfb.JavaPfbCommand <command>
```
## Option 2 - Run from Distribution Downloaded from Github Release
1) Download Distribution zip from latest Github release.
2) Unzip the distribution
```shell
unzip <PATH-TO-ZIP>/cli-<VERSION>.zip
```
3) Note the location of the unzipped distribution and run the CLI with the following command:
```shell
./cli-<VERSION>/bin/cli --version
```

## Upgrade the CLI

Github release containing the CLI jar is automatically generated via Github actions when a change is pushed to main.


15 changes: 10 additions & 5 deletions cli/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
plugins {
id 'bio.terra.pfb.java-common-conventions'
id 'bio.terra.pfb.java-application-conventions'
}

version 'unspecified'
application {
mainClass = 'bio.terra.pfb.JavaPfbCommand'
}

version gradle.releaseVersion
apply from: "generators.gradle"

repositories {
mavenCentral()
}

dependencies {
implementation 'info.picocli:picocli:4.7.4'
implementation project(':library')
}

jar {
manifest {
attributes 'Main-Class': 'bio.terra.pfb.JavaPfbCommand'
}
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
archiveBaseName.set('java-pfb-cli')
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(':library:jar')
}

sonar {
Expand Down
10 changes: 10 additions & 0 deletions cli/generators.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def artifactGroup = "${group}.javapfb.cli"
snf2ye marked this conversation as resolved.
Show resolved Hide resolved

// see https://github.com/n0mer/gradle-git-properties
gitProperties {
keys = []
customProperty('javapfb.cli.version.gitTag', { it.describe(tags: true) })
customProperty('javapfb.cli.version.gitHash', { it.head().abbreviatedId })
customProperty('javapfb.cli.version.github', { "https://github.com/DataBiosphere/java-pfb/tree/${it.describe(tags: true)}" })
customProperty('javapfb.cli.version.build', version)
}
Loading