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 74 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
26 changes: 16 additions & 10 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,7 +70,7 @@ jobs:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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

Expand All @@ -87,15 +89,19 @@ jobs:
text: 'Build failed :sadpanda:'
username: 'Java-PFB GitHub Action'

dispatch-tag:
tag:
needs: [ build, unit-tests-and-sonarqube, source-clear ]
runs-on: ubuntu-latest
uses: ./.github/workflows/tag.yml
Copy link
Member

Choose a reason for hiding this comment

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

I could be wrong but I seem to recall it was done using workflow-dispatch because otherwise the tag job would trigger another CI build and the you'd end up with an infinite loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for calling that out -- I'd like to continue to use the "workflow-call" because it's the new standard and workflow-dispatch introduces its own complications. (The tag action won't necessarily complete before the following publish actions, it's only dispatched.) So, I've added an ignore path on "settings.gradle" so that the action won't be triggered when there are only changes to settings.gradle. https://github.com/DataBiosphere/java-pfb/pull/3/files#diff-bc668a2c9f2299cef15b222055b4b4d5311646caec2e7610e540cee18ae9b948R8

Copy link
Member

Choose a reason for hiding this comment

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

I see, I missed the paths-ignore change above. I'm torn on which is the better approach; I don't like workflow-dispatch that much but way means that the paths-ignore setting depends on the regex in tag.yml and there's no way to directly link the two together. Still it'd be nice to have a single common way to do this across all our repos so if this is agreed to be better we should promote it elsewhere too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

While I do see that there are some cons to the workflow_call method; I would say that workflow_call is the better method and think that we should convert to this across DSP. If at all possible, I try to avoid using third-party GH actions. In order to use workflow_dispatch to trigger another action, we use a forked GHA (https://github.com/broadinstitute/workflow-dispatch). Workflow_call method is a native way to do this with GHA that also has a few good built-in features. One big one is the ability to have the workflow diagram automatically capture the reusable workflows.

I've already been making the switch where it makes sense in TDR (DataBiosphere/jade-data-repo#1404). Once we land on a good setup, I'll make these changes in the java template project.

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

publish-library:
needs: [ build, unit-tests-and-sonarqube, source-clear, tag ]
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
uses: ./.github/workflows/publish.yml
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 }}
release-cli:
needs: [ build, unit-tests-and-sonarqube, source-clear, tag, publish-library ]
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
uses: ./.github/workflows/release-cli.yml
if: success() && github.ref == 'refs/heads/main'
with:
tag: ${{ needs.tag.outputs.tag }}
66 changes: 32 additions & 34 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Publish and deploy
on: create
name: Publish Library to Artifactory
on: workflow_call

env:
SERVICE_NAME: ${{ github.event.repository.name }}
Expand All @@ -15,36 +15,34 @@ jobs:
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'
- 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: Parse tag
id: tag
run: echo "tag=$(git describe --tags)" >> $GITHUB_OUTPUT

- 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"

- 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 Library to Artifactory
fields: job
text: 'Publish failed :sadpanda:'
username: 'Java-PFB GitHub Action'
42 changes: 42 additions & 0 deletions .github/workflows/release-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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: ${{ needs.tag-job.outputs.tag }}
- 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 :cli:jar
./gradlew --build-cache :cli:assembleDist
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
- name: Create tagged release with CLI jar
run: gh release create ${{ needs.tag-job.outputs.tag }} 'cli/build/libs/java-pfb-cli-${{ needs.tag-job.outputs.tag }}.jar' 'cli/build/distributions/cli-${{ needs.tag-job.outputs.tag }}.zip' --generate-notes --verify-tag
env:
GH_TOKEN: ${{ github.token }}
- name: Notify slack on failure
snf2ye marked this conversation as resolved.
Show resolved Hide resolved
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: Create Github Release with CLI Jar
fields: job
text: 'Publish failed :sadpanda:'
username: 'Java-PFB GitHub Action'
10 changes: 8 additions & 2 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: Tag
on: workflow_dispatch
on:
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 +25,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*'.*'"
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ A java implementation of the [pyPFB](https://github.com/uc-cdis/pypfb) library t

The CLI is a wrapper around the library. See the [CLI README](cli/README.md) for more 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
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