Skip to content

Commit

Permalink
Added versioning from CI
Browse files Browse the repository at this point in the history
  • Loading branch information
mirzakaracic committed Jan 4, 2025
1 parent 3b6836d commit 02ffd46
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: create-new-release

on:
workflow_dispatch:
inputs:
version:
type: string
required: true
description: New version to set
commit:
type: string
required: false
description: Commit of of which to build new version. If not provided will use HEAD
default: dev/dev-ci-fixes-stage # todo: Update this for after demo

jobs:
build-stage:
name: Build stage
uses: ./.github/workflows/release-stage.yaml
with:
ref: ${{ inputs.commit }}
version: ${{ inputs.version }}
build-number: ${{ github.run_number }}
secrets: inherit
3 changes: 2 additions & 1 deletion .github/workflows/push-to-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ jobs:
name: Build stage
uses: ./.github/workflows/release-stage.yaml
with:
branch: ${{ github.ref }}
ref: ${{ github.ref }}
build-number: ${{ github.run_number }}
secrets: inherit
20 changes: 16 additions & 4 deletions .github/workflows/release-stage.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
on:
workflow_call:
inputs:
branch:
ref:
type: string
required: true
version:
type: string
required: false
build-number:
type: number
required: true
is-snapshot:
type: boolean
required: false
default: true

jobs:
debug-job:
runs-on: ${{ vars.BUILD_CONTAINER_DISTRO_VERSION }}
steps:
- name: debug
run: |
echo "${{ inputs.branch }}"
echo "${{ inputs.ref }}"
echo "${{ github.base_ref }}"
java-version:
Expand All @@ -23,7 +33,7 @@ jobs:
- name: Checkout client
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}
ref: ${{ inputs.ref }}

- name: Get java version
id: get-java-version
Expand All @@ -41,9 +51,11 @@ jobs:
matrix:
crypto-type: [bouncycastle, gnu]
with:
ref: ${{ inputs.ref }}
java-version: ${{ needs.java-version.outputs.java-version }}
branch: ${{ inputs.branch }}
crypto-type: ${{ matrix.crypto-type }}
version: ${{ inputs.version }}
is-snapshot: ${{ inputs.is-snapshot }}
secrets: inherit

aggregate-published-artifacts:
Expand Down
41 changes: 37 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permissions:
on:
workflow_call:
inputs:
branch:
ref:
type: string
required: true
java-version:
Expand All @@ -14,6 +14,12 @@ on:
crypto-type:
type: string
required: true
version:
type: string
required: true
is-snapshot:
type: boolean
required: true
secrets:
GPG_SECRET_KEY_ORG:
required: true
Expand All @@ -31,8 +37,8 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}

ref: ${{ inputs.ref }}
# Java plugin will setup gpg but we are not using maven to deploy do JFrog.
# - jf mvn clean install on publish does not publish POM we would like to publish
- name: Setup Java
Expand All @@ -43,9 +49,26 @@ jobs:
gpg-private-key: ${{ secrets.GPG_SECRET_KEY_ORG }}
gpg-passphrase: GPG_PASS

- name: Get release or snapshot-version
id: get-release-version
shell: bash
run: |
IS_SNAPSHOT='${{ inputs.IS_SNAPSHOT }}'
if [ $IS_SNAPSHOT == 'true' ];then
echo release-version="$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)_$GITHUB_SHA" >> $GITHUB_OUTPUT
else
echo release-version="${{ inputs.version }}"
fi
- name: Set version
shell: bash
run: |
VERSION:
./set_version ${{ steps.get-release-version.outputs.release-version }} ${{ inputs.crypto-type }}
- name: Build all modules
shell: bash
run: mvn clean install -P ${{ inputs.crypto-type }} # The crypto profile is usually set with set_crypto but since we need to toggle multiple prfiles set_crypto option is not being picked up
run: mvn clean install -P ${{ inputs.crypto-type }} # The crypto profile is usually set with set_crypto but since we need to toggle multiple profiles set_crypto option is not being picked up

- name: Stage artifacts for publish
working-directory: client
Expand All @@ -72,6 +95,16 @@ jobs:
run: |
echo artifact-version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) >> $GITHUB_OUTPUT
- name: Commit new version
# Only committing version if this is a release and not snapshot build
if: ${{ inputs.is-snapshot != 'true' }}
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: 'Bumping version to ${{ inputs.version }} [skip ci]'
commit_author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
tagging_message: Bumping version ${{ inputs.version }}
branch: ${{ inputs.ref }}

- name: Publish to JFrog
uses: ./.github/actions/publish-to-jfrog
with:
Expand Down
56 changes: 56 additions & 0 deletions set_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

#
# Function definitions
#
function update_version() {
VERSION="$1"
BUILD_TYPE=$2
PARENT_POM="pom.xml"
PUBLIC_POM="client/deploy-resources/${BUILD_TYPE}_pom.xml"

# Detecting host type. `sed` on bsd and linux are not the same
if [[ "$(uname)" == "Darwin" ]]; then
sed -i "" "s#<revision>[^<]*</revision>#<revision>${VERSION}</revision>#g" "$PARENT_POM"
sed -i "" "1,/<version>[^<]*<\/version>/ s#<version>[^<]*</version>#<version>${VERSION}</version>#" "$PUBLIC_POM"
else
sed -i "s#<revision>[^<]*</revision>#<revision>${VERSION}</revision>#g" "$PARENT_POM"
sed -i "0,/<version>[^<]*<\/version>/ s//<version>${VERSION}<\/version>/" "$PUBLIC_POM"
fi
}

function main() {
VERSION=$1
BUILD_TYPE=$2

# If version has been set using set_crypto we are honoring that setting
if [ -f "bouncycastle.config" ];then
BUILD_TYPE="bouncycastle"
elif [ -f "gnu.config" ];then
BUILD_TYPE="gnu"
fi

update_version $VERSION $BUILD_TYPE
}

#
# Main entry
#
VERSION=$1
BUILD_TYPE=${2:-"gnu"}
REGEX="^[0-9]+\.[0-9]+\.[0-9]+$"

if [ -z $VERSION ];then
printf "Missing version ..."

exit 1
elif [[ ! "$1" =~ $REGEX ]];then
printf "Version format not valid. Valid format are [0 - 9].[0 - 9].[0 - 9]"

exit 1
else
# Call main
main $VERSION $BUILD_TYPE

exit 0
fi

0 comments on commit 02ffd46

Please sign in to comment.