Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add deployment workflow #49

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/mvn-central-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release new version to Maven Central
on:
push:
branches: [main]
jobs:
release-maven-central:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Configure Git user
run: |
git config user.email "actions@github.com"
git config user.name "GitHub Actions"
- name: Import GPG signing key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.MAVEN_SIGNING_KEY }}
passphrase: ${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }}
- name: Setup SSH
run: |
echo "Setting up SSH..."
mkdir ~/.ssh
echo "$SSH_KEY" > ~/.ssh/appforge-key
chmod 600 ~/.ssh/appforge-key
cat <<EOF > ~/.ssh/config
Host github.com
User git
IdentityFile ~/.ssh/appforge-key
ForwardAgent yes
EOF
cat ~/.ssh/config
echo "Starting SSH agent"
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/appforge-key
shell: bash
env:
SSH_KEY: ${{ secrets.APPFORGE_DEPLOY_PRIV_KEY }}
- name: Install JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
cache: 'maven'
server-id: maven-central-release
server-username: MVN_CENTRAL_USERNAME
server-password: MVN_CENTRAL_PASSWORD
- name: Release to Maven repo
run: |
export VERSION=$(./cicd/version.sh)
echo "Version to set: $VERSION"
echo "TAG_NAME=$VERSION" >> $GITHUB_ENV
mvn -P release -Dgpg.keyname=${{ secrets.GPG_KEY_NAME }} -Dgpg.passphrase=${{ secrets.MAVEN_SIGNING_KEY_PASSPHRASE }} \
-Drevision=$VERSION deploy
env:
MVN_CENTRAL_USERNAME: ${{ vars.MVN_CENTRAL_USERNAME }}
MVN_CENTRAL_PASSWORD: ${{ secrets.MVN_CENTRAL_PASSWORD }}
- name: Tag version
run: |
git tag v${{ env.TAG_NAME }}
git push origin --tags

59 changes: 59 additions & 0 deletions cicd/semver-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#! /bin/bash
#
# /*
# * Copyright (c) 2023 Bitshift D.O.O (http://bitshifted.co)
# *
# * This Source Code Form is subject to the terms of the Mozilla Public
# * License, v. 2.0. If a copy of the MPL was not distributed with this
# * file, You can obtain one at http://mozilla.org/MPL/2.0/.
# */
#

# Parse command line options.

while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done

shift $(($OPTIND - 1))

version=$1

# Build array from version string.

a=( ${version//./ } )

# If version string is missing or has the wrong number of members, show usage message.

if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi

# Increment version numbers as requested.

if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi

if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi

if [ ! -z $patch ]
then
((a[2]++))
fi

echo "${a[0]}.${a[1]}.${a[2]}"
47 changes: 47 additions & 0 deletions cicd/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /bin/bash
#
# /*
# * Copyright (c) 2023 Bitshift D.O.O (http://bitshifted.co)
# *
# * This Source Code Form is subject to the terms of the Mozilla Public
# * License, v. 2.0. If a copy of the MPL was not distributed with this
# * file, You can obtain one at http://mozilla.org/MPL/2.0/.
# */
#

PATCH_REGEX='^(build|chore|ci|docs|fix|perf|refactor|revert|style|test)\s?(\(.+\))?\s?:\s*(.+)'
MINOR_REGEX='^(feat)\s*(\(.+\))?\s?:\s*(.+)'
MAJOR_REGEX='^(BREAKING CHANGE)\s*(\(.+\))?\s?:\s*(.+)'

# get the latest tag
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2> /dev/null)
if [ -z $LATEST_TAG ]; then
LATEST_TAG="v1.0.0"
echo "1.0.0"
exit 0
fi

LATEST_VERSION=""
if [[ $LATEST_TAG =~ [0-9]+\.[0-9]+\.[0-9]+$ ]]; then
LATEST_VERSION=${BASH_REMATCH[0]}
else
echo "Failed to extract current version" >&2
exit 1
fi

SCRIPT_DIR=$( dirname -- "$0"; )
# process last commit message
MESSAGE=$(git log -1 --pretty=%B)
if [[ "$MESSAGE" =~ $PATCH_REGEX ]]; then
"$SCRIPT_DIR"/semver-bump.sh -p $LATEST_VERSION
elif [[ "$MESSAGE" =~ $MINOR_REGEX ]]; then
"$SCRIPT_DIR"/semver-bump.sh -m $LATEST_VERSION
elif [[ $MESSAGE =~ $MAJOR_REGEX ]]; then
"$SCRIPT_DIR"/semver-bump.sh -M $LATEST_VERSION
else
"$SCRIPT_DIR"/semver-bump.sh -p $LATEST_VERSION
fi