From 368680a58da893da5b96afb5d463c1a7cbd18c92 Mon Sep 17 00:00:00 2001 From: Jakub Stejskal Date: Fri, 12 Jul 2024 13:27:01 +0200 Subject: [PATCH] Add scripts for releasing and update pom to allow pushing to sonatype (#12) ## Description This PR contains scripts and workflows that handles releasing to github and sonatype. ## Type of Change * New feature (non-breaking change which adds functionality) ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings --------- Signed-off-by: Jakub Stejskal --- .github/scripts/prepare-tag-release.sh | 15 +++++ .github/scripts/push-to-nexus.sh | 12 ++++ .github/scripts/settings.xml | 11 ++++ .github/workflows/publish-release.yaml | 40 ++++++++++++ .github/workflows/publish-snapshot.yaml | 45 ++++++++++++++ pom.xml | 83 +++++++++++++++++++++++++ src/assembly/dist.xml | 35 +++++++++++ 7 files changed, 241 insertions(+) create mode 100755 .github/scripts/prepare-tag-release.sh create mode 100755 .github/scripts/push-to-nexus.sh create mode 100644 .github/scripts/settings.xml create mode 100644 .github/workflows/publish-release.yaml create mode 100644 .github/workflows/publish-snapshot.yaml create mode 100644 src/assembly/dist.xml diff --git a/.github/scripts/prepare-tag-release.sh b/.github/scripts/prepare-tag-release.sh new file mode 100755 index 0000000..8db9fd8 --- /dev/null +++ b/.github/scripts/prepare-tag-release.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# Script change version and run build +# then adds changes and do a release commit +# then creates tag with version specified by argument +# user must then push tags using `git push --tags` and do a release in github + +TAG=$1 +echo "Tagging version to ${TAG}" + +mvn versions:set -DnewVersion=${TAG} +mvn clean install +git add "." +git diff --staged --quiet || git commit -m "Release ${TAG}" +git tag -a ${TAG} -m "${TAG}" diff --git a/.github/scripts/push-to-nexus.sh b/.github/scripts/push-to-nexus.sh new file mode 100755 index 0000000..49c169a --- /dev/null +++ b/.github/scripts/push-to-nexus.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +export GPG_TTY=$(tty) + +echo $GPG_SIGNING_KEY | base64 -d > signing.gpg +gpg --batch --import signing.gpg + +GPG_EXECUTABLE=gpg mvn -DskipTests -s ./.github/scripts/settings.xml -P central-sonatype clean deploy + +rm -rf signing.gpg +gpg --delete-keys +gpg --delete-secret-keys diff --git a/.github/scripts/settings.xml b/.github/scripts/settings.xml new file mode 100644 index 0000000..ee604d9 --- /dev/null +++ b/.github/scripts/settings.xml @@ -0,0 +1,11 @@ + + + + central + ${env.NEXUS_USERNAME} + ${env.NEXUS_PASSWORD} + + + \ No newline at end of file diff --git a/.github/workflows/publish-release.yaml b/.github/workflows/publish-release.yaml new file mode 100644 index 0000000..c5eaf4f --- /dev/null +++ b/.github/workflows/publish-release.yaml @@ -0,0 +1,40 @@ +name: Publish-release + +on: + push: + tags: + - '*' + +jobs: + publish-release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + server-id: github + settings-path: ${{ github.workspace }} + + - name: Cache m2 repo + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build + run: mvn clean install + + - name: Publish to sonatype + run: ./.github/scripts/push-to-nexus.sh + env: + BUILD_ENV: 'github-actions' + NEXUS_USERNAME: ${{ secrets.NEXUS_USERNAME }} + NEXUS_PASSWORD: ${{ secrets.NEXUS_PASSWORD }} + GPG_KEYNAME: ${{ secrets.GPG_KEYNAME }} + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }} diff --git a/.github/workflows/publish-snapshot.yaml b/.github/workflows/publish-snapshot.yaml new file mode 100644 index 0000000..dc5a07b --- /dev/null +++ b/.github/workflows/publish-snapshot.yaml @@ -0,0 +1,45 @@ +name: Publish-snapshot + +on: + push: + branches: [ main ] + +jobs: + publish-snapshot: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + server-id: github + settings-path: ${{ github.workspace }} + + - name: Setup Maven settings.xml + uses: whelk-io/maven-settings-xml-action@v11 + with: + servers: + '[ + { + "id": "github", + "username": "${env.GITHUB_USERNAME}", + "password": "${env.GITHUB_TOKEN}" + } + ]' + + - name: Cache m2 repo + uses: actions/cache@v4 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy + env: + GITHUB_USERNAME: x-access-token + GITHUB_TOKEN: ${{ secrets.TOKEN }} + BUILD_ENV: 'github-actions' diff --git a/pom.xml b/pom.xml index ffeb169..07b5f8c 100644 --- a/pom.xml +++ b/pom.xml @@ -79,6 +79,9 @@ 3.7.0 3.4.2 3.9.0 + 3.1.0 + 3.4.2 + 0.5.0 2.23.1 5.10.2 @@ -310,4 +313,84 @@ + + + + default + + true + + + + central-sonatype + + false + + + + ${env.GPG_EXECUTABLE} + + ${env.GPG_PASSPHRASE} + + ${env.GPG_KEYNAME} + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven.gpg.version} + + + sign-artifacts + deploy + + sign + + + + --batch + --pinentry-mode + loopback + + + + + + + org.sonatype.central + central-publishing-maven-plugin + ${sonatype.nexus.central} + true + + central + true + all + true + + + + org.apache.maven.plugins + maven-assembly-plugin + ${maven.assembly.version} + + + package + + single + + + false + posix + + src/main/assembly/dist.xml + + + + + + + + + diff --git a/src/assembly/dist.xml b/src/assembly/dist.xml new file mode 100644 index 0000000..839ea3b --- /dev/null +++ b/src/assembly/dist.xml @@ -0,0 +1,35 @@ + + zip + true + + + tar.gz + zip + dir + + + + ${project.basedir} + + README* + + 0644 + + + ${project.basedir} + + LICENSE + + 0644 + + + + + runtime + libs + 0644 + + +