diff --git a/.github/maven-central-deploy.sh b/.github/maven-central-deploy.sh new file mode 100644 index 0000000..07f1358 --- /dev/null +++ b/.github/maven-central-deploy.sh @@ -0,0 +1,12 @@ +#!/bin/bash +# +# This script takes care of deploying tagged versions to maven central and updating the pom.xml +# version with next development version. +# +# Required environment variables: GPG_SECRET_KEYS, GPG_OWNERTRUST, GPG_EXECUTABLE + +set -eo pipefail + +echo $GPG_SECRET_KEYS | base64 --decode | $GPG_EXECUTABLE --batch --import +echo $GPG_OWNERTRUST | base64 --decode | $GPG_EXECUTABLE --batch --import-ownertrust +mvn --batch-mode deploy -Prelease -DskipTests --settings .github/settings.xml diff --git a/.github/semver-check.sh b/.github/semver-check.sh new file mode 100644 index 0000000..1f682f1 --- /dev/null +++ b/.github/semver-check.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This script checks that the version number of the release is an expected one, and avoid erroneous releases which don't follow semver +set -eo pipefail + +git fetch --tags --quiet +VERSION="$1" +PREV_VERSION=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) +PREV_VERSION=${PREV_VERSION#v} +PREV_MAJOR="${PREV_VERSION%%.*}" +PREV_VERSION="${PREV_VERSION#*.}" +PREV_MINOR="${PREV_VERSION%%.*}" +PREV_PATCH="${PREV_VERSION#*.}" +if [[ "$PREV_VERSION" == "$PREV_PATCH" ]]; then + PREV_PATCH="0" +fi + +[[ "$VERSION" == "$PREV_MAJOR.$PREV_MINOR.$((PREV_PATCH + 1))" || "$VERSION" == "$PREV_MAJOR.$((PREV_MINOR + 1))" || "$VERSION" == "$((PREV_MAJOR + 1)).0" ]] diff --git a/.github/settings.xml b/.github/settings.xml new file mode 100644 index 0000000..a54ac13 --- /dev/null +++ b/.github/settings.xml @@ -0,0 +1,27 @@ + + + + + ossrh + ${env.SONATYPE_USERNAME} + ${env.SONATYPE_PASSWORD} + + + + + + ossrh + + true + + + ${env.GPG_EXECUTABLE} + ${env.GPG_PASSPHRASE} + + + + + diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2f4aed5 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,39 @@ +name: publish release +on: + release: + types: [ published ] +jobs: + release: + runs-on: ubuntu-latest + concurrency: blazemeter_test + steps: + - uses: actions/checkout@v2 + - name: Setup Java 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Get version + id: version + run: echo "release_version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV + - name: Check version + run: .github/semver-check.sh ${{ env.release_version }} + - name: set maven project version + run: mvn --batch-mode --no-transfer-progress versions:set -DnewVersion=${{ env.release_version }} --settings .github/settings.xml + - name: package release + run: mvn --batch-mode --no-transfer-progress clean package --settings .github/settings.xml + - name: Upload built jar into release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: target/*.jar + file_glob: true + tag: ${{ github.ref }} + - name: publish to Nexus + run: .github/maven-central-deploy.sh + env: + GPG_SECRET_KEYS: ${{ secrets.GPG_SECRET_KEYS }} + GPG_OWNERTRUST: ${{ secrets.GPG_OWNERTRUST }} + GPG_EXECUTABLE: gpg + GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}