Java - Publish to Sonatype Repo #20
Workflow file for this run
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
name: Java - Publish to Sonatype Repo | |
on: | |
release: | |
types: [published] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set env | |
run: | | |
echo "VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV | |
- name: Print Version | |
run: | | |
echo $VERSION | |
echo ${{ env.VERSION }} | |
- name: Set up Maven Central Repository | |
uses: actions/setup-java@v2 | |
with: | |
java-version: "11" | |
distribution: "adopt" | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
- name: Set project version | |
run: mvn versions:set -DnewVersion=${{ env.VERSION }} | |
- name: Install GPG secret key | |
run: echo "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | gpg --batch --import | |
- name: Check Imported GPG Keys | |
run: gpg --list-secret-keys --keyid-format LONG | |
- name: Retrieve bearer token | |
id: get_bearer_token | |
run: | | |
response=$(curl -X POST ${{secrets.OKTA_ACCESS_TOKEN_URL}}/connect/token \ | |
-H "Content-Type: application/x-www-form-urlencoded" \ | |
-d "grant_type=client_credentials&client_id=${{secrets.OKTA_CLIENT_ID}}&client_secret=${{secrets.OKTA_CLIENT_SECRET}}") | |
token=$(echo $response | jq -r '.access_token') | |
echo "BEARER_TOKEN=${token}" >> $GITHUB_ENV | |
- name: Build with Maven | |
run: mvn --batch-mode --update-snapshots verify | |
env: | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PASSPHRASE }} | |
- name: Update resources | |
uses: test-room-7/action-update-file@v1 | |
with: | |
file-path: pom.xml | |
commit-msg: Commit Pom updated version | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Publish to Maven Central | |
run: | | |
mvn --no-transfer-progress --batch-mode deploy -DskipTests | |
env: | |
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} |