-
Notifications
You must be signed in to change notification settings - Fork 50
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
[DEVOPS-1751] Pipeline for publishing java sdk to gradle #740
Merged
michalchecinski
merged 13 commits into
main
from
DEVOPS-1751-Pipeline-for-publishing-Java-SDK-to-Gradle
May 10, 2024
+111
−16
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9a28e77
Update java sdk to version bump
michalchecinski eec8e65
Update build.gradle file
michalchecinski 74a1270
Update build-java.yml workflow file and fix publish argument in Maven…
michalchecinski 30d35c7
Change for package
michalchecinski 7b4f738
Add publish java pipeline
michalchecinski 0e14859
Update Azure login and retrieve secrets in publish-java workflow
michalchecinski 76379f0
Update secrets in publish-java workflow
michalchecinski 77a35ad
Update Maven credentials in publish-java workflow
michalchecinski 1859d3e
Update publish-java workflow to conditionally run the package publish…
michalchecinski 9916f55
Fix
michalchecinski 5472112
Update build.gradle file to include Javadoc and sources JAR generation
michalchecinski 2a4ae73
Merge branch 'main' into DEVOPS-1751-Pipeline-for-publishing-Java-SDK…
michalchecinski 9116ee0
Merge branch 'main' into DEVOPS-1751-Pipeline-for-publishing-Java-SDK…
michalchecinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Publish Java SDK | ||
run-name: Publish Java SDK ${{ inputs.release_type }} | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
release_type: | ||
description: "Release Options" | ||
required: true | ||
default: "Release" | ||
type: choice | ||
options: | ||
- Release | ||
- Dry Run | ||
|
||
env: | ||
_KEY_VAULT: "bitwarden-ci" | ||
|
||
jobs: | ||
validate: | ||
name: Setup | ||
runs-on: ubuntu-22.04 | ||
outputs: | ||
version: ${{ steps.version.outputs.version }} | ||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Branch check | ||
if: ${{ inputs.release_type != 'Dry Run' }} | ||
run: | | ||
if [[ "$GITHUB_REF" != "refs/heads/rc" ]] && [[ "$GITHUB_REF" != "refs/heads/hotfix-rc" ]]; then | ||
echo "===================================" | ||
echo "[!] Can only release from the 'rc' or 'hotfix-rc' branches" | ||
echo "===================================" | ||
exit 1 | ||
fi | ||
|
||
- name: Get version | ||
id: version | ||
run: | | ||
VERSION=$(cat languages/java/build.gradle | grep -Eo 'version = "[0-9]+\.[0-9]+\.[0-9]+"' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+') | ||
echo "version=$VERSION" >> $GITHUB_OUTPUT | ||
|
||
publish: | ||
name: Publish | ||
runs-on: ubuntu-22.04 | ||
needs: validate | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 | ||
|
||
- name: Azure login | ||
uses: Azure/login@e15b166166a8746d1a47596803bd8c1b595455cf # v1.6.0 | ||
with: | ||
creds: ${{ secrets.AZURE_KV_CI_SERVICE_PRINCIPAL }} | ||
|
||
- name: Retrieve secrets | ||
id: retrieve-secrets | ||
uses: bitwarden/gh-actions/get-keyvault-secrets@main | ||
with: | ||
keyvault: ${{ env._KEY_VAULT }} | ||
secrets: "maven-sonartype-ssrh-username, | ||
maven-sonartype-ossrh-password" | ||
|
||
- name: Setup java | ||
uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 | ||
with: | ||
distribution: temurin | ||
java-version: 17 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0 | ||
|
||
- name: Publish package to GitHub Packages | ||
if: ${{ inputs.release_type != 'Dry Run' }} | ||
run: ./gradlew publish | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
MAVEN_USERNAME: ${{ steps.retrieve-secrets.outputs.maven-sonartype-ssrh-username }} | ||
MAVEN_PASSWORD: ${{ steps.retrieve-secrets.outputs.maven-sonartype-ossrh-password }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,14 +19,14 @@ repositories { | |
api 'net.java.dev.jna:jna-platform:5.12.1' | ||
} | ||
|
||
description = 'BitwardenSDK' | ||
description = 'Bitwarden Secrets Manager Java SDK' | ||
java.sourceCompatibility = JavaVersion.VERSION_1_8 | ||
|
||
publishing { | ||
publications { | ||
maven(MavenPublication) { | ||
groupId = 'com.bitwarden' | ||
artifactId = 'sdk' | ||
artifactId = 'sdk-secrets' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
// Determine the version from the git history. | ||
// | ||
|
@@ -35,13 +35,8 @@ repositories { | |
|
||
def branchName = "git branch --show-current".execute().text.trim() | ||
|
||
if (branchName == "main") { | ||
def content = ['grep', '-o', '^version = ".*"', '../../Cargo.toml'].execute().text.trim() | ||
def match = ~/version = "(.*)"/ | ||
def matcher = match.matcher(content) | ||
matcher.find() | ||
|
||
version = "${matcher.group(1)}-SNAPSHOT" | ||
if (branchName == "main" || branchName == "rc" || branchName == "hotfix-rc") { | ||
version = "0.1.0" | ||
} else { | ||
// branchName-SNAPSHOT | ||
version = "${branchName.replaceAll('/', '-')}-SNAPSHOT" | ||
|
@@ -61,6 +56,14 @@ repositories { | |
password = System.getenv("GITHUB_TOKEN") | ||
} | ||
} | ||
maven { | ||
name = "OSSRH" | ||
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" | ||
credentials { | ||
username = System.getenv("MAVEN_USERNAME") | ||
password = System.getenv("MAVEN_PASSWORD") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -73,6 +76,11 @@ tasks.withType(Javadoc) { | |
options.encoding = 'UTF-8' | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
|
||
// Gradle build requires GitHub workflow to copy native library to resources | ||
// Uncomment copyNativeLib and jar tasks to use the local build (modify architecture if needed) | ||
//tasks.register('copyNativeLib', Copy) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should publish with java docs (and optionally source code), maybe add: