Publish to the Maven Central Repository #6
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: Publish to the Maven Central Repository | |
on: | |
workflow_dispatch: | |
inputs: | |
version: | |
description: Version to be released | |
required: true | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.RELEASE_PERSONAL_ACCESS_TOKEN }} | |
- name: Validate ${{ github.event.inputs.version }} release exists | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const response = await github.rest.repos.listReleases({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
if (!response) { | |
throw new Error(`There are no available releases`); | |
} | |
for (const release of response.data) { | |
if (release.name === "${{ github.event.inputs.version }}") { | |
return | |
} | |
} | |
throw new Error(`Release ${{ github.event.inputs.version }} is not available`); | |
- name: Set up JDK | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} | |
gpg-passphrase: MAVEN_GPG_PASSPHRASE | |
- name: Update version | |
run: | | |
./mvnw --batch-mode --no-transfer-progress versions:set -DnewVersion=${{ github.event.inputs.version }} versions:commit | |
git config user.name "jenkins" | |
git config user.email "jenkins@playtika.com" | |
git commit -m "Release ${{ github.event.inputs.version }}" -a | |
git push | |
- name: Publish to the Maven Central Repository | |
run: ./mvnw --batch-mode --no-transfer-progress -Dgib.disable=true -Ddocker.cleanup.skip=true -P ossrh -DskipTests deploy | |
env: | |
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | |
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
- name: Publish release on GitHub | |
uses: test-room-7/action-publish-release-drafts@v0 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
tag-name: ${{ github.event.inputs.version }} |