Skip to content

Commit

Permalink
Release Workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
3dgiordano authored Apr 27, 2022
1 parent 2626aea commit a20823f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/maven-central-deploy.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions .github/semver-check.sh
Original file line number Diff line number Diff line change
@@ -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" ]]
27 changes: 27 additions & 0 deletions .github/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">

<servers>
<server>
<id>ossrh</id>
<username>${env.SONATYPE_USERNAME}</username>
<password>${env.SONATYPE_PASSWORD}</password>
</server>
</servers>

<profiles>
<profile>
<id>ossrh</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<gpg.executable>${env.GPG_EXECUTABLE}</gpg.executable>
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
</properties>
</profile>
</profiles>

</settings>
39 changes: 39 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit a20823f

Please sign in to comment.