release new version to Maven Central #27
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: release new version to Maven Central | |
on: | |
schedule: | |
# twice per month, always on the 3rd and 17th at 17:17 UTC | |
- cron: '17 17 3,17 * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
Monthly_Release: | |
runs-on: ubuntu-latest | |
env: | |
changes_found: '' | |
steps: | |
- name: Checkout main branch | |
uses: actions/checkout@v3 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Identify release-relevant changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Jenkins" | |
echo "changes_found=$(git diff --name-only release-latest..main src/main | head -n 1)" >> $GITHUB_ENV | |
- name: Install gpg secret key | |
if: env.changes_found != '' | |
run: | | |
cat <(echo -e "${{ secrets.OSSRH_GPG_SECRET_KEY }}") | gpg --batch --import | |
gpg --list-secret-keys --keyid-format LONG | |
- name: Set up JDK 17 | |
if: env.changes_found != '' | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
server-id: ossrh | |
server-username: MAVEN_USERNAME | |
server-password: MAVEN_PASSWORD | |
cache: maven | |
- name: Prepare new release | |
if: env.changes_found != '' | |
run: | | |
OLD_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout | strings) | |
mvn build-helper:parse-version versions:set '-DnewVersion=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}' | |
NEW_VERSION=$(mvn -q help:evaluate -Dexpression=project.version -DforceStdout | strings) | |
sed -i -e "s/'"${OLD_VERSION}"'/'"${NEW_VERSION}"'/g" -e 's/"'${OLD_VERSION}'"/"'${NEW_VERSION}'"/g' -e "s/>${OLD_VERSION}</>${NEW_VERSION}</g" README.md | |
git add pom.xml README.md | |
git commit -m "release new version $NEW_VERSION" | |
git tag "release-$NEW_VERSION" | |
- name: Publish to Central Repository | |
if: env.changes_found != '' | |
env: | |
MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} | |
MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} | |
run: | | |
mvn \ | |
--no-transfer-progress \ | |
--batch-mode \ | |
-Dgpg.passphrase=${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} \ | |
clean deploy | |
- name: Update tags | |
if: env.changes_found != '' | |
run: | | |
git tag -f release-latest | |
git push -f --tags | |
git push |