Publish to Maven Central #11
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: Publish to Maven Central | |
on: | |
release: | |
types: [created] | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 8 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'adopt' | |
java-version: '8' | |
server-id: 'central' | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
gpg-private-key: '${{ secrets.GPG_PRIVATE_KEY }}' | |
gpg-passphrase: GPG_PASSPHRASE | |
- name: Extract version from tag | |
id: extract_version | |
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
- name: Find branch associated with tag | |
id: find_branch | |
run: | | |
TAG_NAME=${GITHUB_REF#refs/tags/} | |
BRANCH_NAME=$(git branch -r --contains $TAG_NAME | grep -v '\->' | head -n 1 | sed 's/.*origin\///' | tr -d ' ') | |
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | |
- name: Set version in pom.xml | |
run: mvn versions:set -DgenerateBackupPoms=false -DnewVersion=${{ env.VERSION }} | |
- name: Commit version change | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git checkout -b bump-version-to-${{ env.VERSION }} | |
git add . | |
git commit -m "Set version to ${{ env.VERSION }}" | |
git push origin bump-version-to-${{ env.VERSION }} | |
- name: Create pull request | |
uses: peter-evans/create-pull-request@v3 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
branch: bump-version-to-${{ env.VERSION }} | |
title: "Set version to ${{ env.VERSION }}" | |
body: "This PR sets the version to ${{ env.VERSION }} based on the release tag." | |
base: ${{ env.BRANCH_NAME }} | |
- name: Build with Maven | |
run: mvn clean install | |
- name: Deploy to Maven Central | |
run: mvn -B -P release deploy | |
env: | |
MAVEN_USERNAME: ${{ secrets.SONATYPE_USER_TOKEN_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.SONATYPE_USER_TOKEN_PASSWORD }} | |
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
working-directory: sdk |