Skip to content

Commit

Permalink
Merge pull request #19 from hivemq/feature/metric-2-topic
Browse files Browse the repository at this point in the history
#18 Feature/metric 2 topic
  • Loading branch information
skobow authored May 16, 2024
2 parents e550fca + 1826e79 commit 18204c8
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 59 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/check.yml

This file was deleted.

44 changes: 44 additions & 0 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Extension Build and Test
on:
push:
branches:
- feature/**
tags:
- '*'
pull_request:
branches:
- main

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Cache gradle
uses: actions/cache@v3.3.3
with:
path: |
~/.gradle
key: gradle-${{ hashFiles('**/build.gradle.kts') }}

- name: Set up JDK 11
uses: actions/setup-java@v4.0.0
with:
java-version: '11'
distribution: 'temurin'
check-latest: true
cache: gradle

- name: Build with Gradle
run: |
./gradlew check test build
153 changes: 153 additions & 0 deletions .github/workflows/gradle-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Create Release
on:
workflow_dispatch:
branches:
- main
- feature/**
inputs:
version:
description: 'Version to release (e.g. 0.0.0)'
required: true
default: '4.28.0'
nextVersion:
description: 'Next version for development (e.g. 0.0.0; do not include -SNAPSHOT)'
required: true
default: '4.29.0'
preRelease:
description: 'Is this a pre-release?'
required: true
default: false
# updateWorkflow:
# description: 'Update workflow default versions? NOTE: A personal access token must be available as secret WORKFLOW_TOKEN for this to work!'
# required: false
# default: false

permissions:
contents: write
actions: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate versions
run: |
VERSION_REGEX="^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(-(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*)?(\+[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*)?$"
echo "Checking if version and nextVersion comply with semantic versioning..."
if [[ ! "${{ github.event.inputs.version }}" =~ $VERSION_REGEX ]] || [[ ! "${{ github.event.inputs.nextVersion }}" =~ $VERSION_REGEX ]]; then
echo "Error: version does not comply with semantic versioning! Use MAJOR.MINOR.PATCH pattern."
exit 1
fi
echo "Checking if version and nextVersion are identical..."
if [[ ( "${{ github.event.inputs.version }}" == "${{ github.event.inputs.nextVersion }}" ) ]]; then
echo "Error: version and nextVersion may not be identical."
exit 1
fi
echo "Checking if nextVersion is higher than version..."
IFS='.' read -ra VERSION_ARR <<< "${{ github.event.inputs.version }}"
IFS='.' read -ra NEXT_VERSION_ARR <<< "${{ github.event.inputs.nextVersion }}"
for i in "${!VERSION_ARR[@]}"; do
if (( NEXT_VERSION_ARR[i] < VERSION_ARR[i] )); then
echo "Error: next version needs to be higher than release version"
exit 1
elif (( NEXT_VERSION_ARR[i] > VERSION_ARR[i] )); then
break
fi
done
echo "Checking if tag v${{ github.event.inputs.version }} already exists..."
if git rev-parse "v${{ github.event.inputs.version }}" >/dev/null 2>&1; then
echo "Tag v${{ github.event.inputs.version }} already exists!"
exit 1
fi
echo "Creating release with version v${{ github.event.inputs.version }}."
echo "Next version will be v${{ github.event.inputs.nextVersion }}-SNAPSHOT."
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
echo "NEXT_VERSION=${{ github.event.inputs.nextVersion }}" >> $GITHUB_ENV
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Check pre-release
run: |
echo "Creating pre-release: ${{ github.event.inputs.preRelease }}"
if [[ ${{ github.event.inputs.preRelease }} == "true" ]]; then
echo "PRE_RELEASE=true" >> $GITHUB_ENV
else
echo "Creating final release from ${{ env.BRANCH_NAME }}."
if [[ "${{ env.BRANCH_NAME }}" != "main" ]]; then
echo "Error: final releases can only be created from main branch."
exit 1
fi
echo "PRE_RELEASE=false" >> $GITHUB_ENV
fi
- name: Set up JDK 11
uses: actions/setup-java@v4.0.0
with:
java-version: '11'
distribution: 'temurin'
check-latest: true
cache: gradle

- name: Setup Gradle
uses: gradle/gradle-build-action@v3.0.0

- name: Setup git config
run: |
git config --global user.name "GitHub Action"
git config --global user.email "<>"
- name: Release with Gradle
run: ./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.VERSION }} -Prelease.newVersion=${{ env.NEXT_VERSION }}-SNAPSHOT

- name: Generate changelog
id: changelog
run: |
CHANGELOG=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s")
echo "::set-output name=changelog::$CHANGELOG"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ env.VERSION }}
tag_name: ${{ env.VERSION }}
prerelease: ${{ env.PRE_RELEASE }}
body: ${{ steps.changelog.outputs.changelog }}
files: |
./build/hivemq-extension/hivemq-sparkplug-aware-extension-*.zip
./build/hivemq-extension/hivemq-sparkplug-aware-extension-*.zip.sha256
# - name: Update workflow
# run: |
#
# if [[ ${{ github.event.inputs.updateWorkflow }} == "false" ]]; then
# echo "Skipping workflow update."
# exit 0
# fi
#
# IFS='.' read -ra NEXT_VERSION_ARR <<< "${{ env.NEXT_VERSION }}"
# NEXT_VERSION_MINOR=$((NEXT_VERSION_ARR[1] + 1))
# NEW_NEXT_VERSION="${NEXT_VERSION_ARR[0]}.${NEXT_VERSION_MINOR}.0"
#
# echo $NEW_NEXT_VERSION
#
# set -x
# VERSION=${{ env.NEXT_VERSION }} yq eval '.on.workflow_dispatch.inputs.version.default = env(VERSION)' -i .github/workflows/gradle-release.yml
# NEXT_VERSION=$NEW_NEXT_VERSION yq eval '.on.workflow_dispatch.inputs.nextVersion.default = env(NEXT_VERSION)' -i .github/workflows/gradle-release.yml
# set +x
#
# cat .github/workflows/gradle-release.yml
#
# git config --global user.name "GitHub Action"
# git config --global user.email "<>"
# git add .github/workflows/gradle-release.yml
# git commit -m "Update workflow default versions"
# git push
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ out/

.java-version
.DS_Store

# HiveMQ
hivemq-4.*.0
39 changes: 28 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
import net.researchgate.release.ReleaseExtension
import org.gradle.crypto.checksum.Checksum

plugins {
alias(libs.plugins.hivemq.extension)
alias(libs.plugins.defaults)
alias(libs.plugins.license)
alias(libs.plugins.checksum)
alias(libs.plugins.release)
}

group = "com.hivemq.extensions.sparkplug.aware"
description = "HiveMQ Sparkplug Aware Extension"

hivemqExtension {
name = "Sparkplug Aware Extension"
author = "HiveMQ"
priority = 1000
startPriority = 1000
sdkVersion = libs.versions.hivemq.extensionSdk
name.set("Sparkplug Aware Extension")
author.set("HiveMQ")
priority.set(1000)
startPriority.set(1000)
sdkVersion.set(libs.versions.hivemq.extensionSdk)

resources {
from("LICENSE")
}
}

configure<ReleaseExtension> {
ignoredSnapshotDependencies.set(listOf("net.researchgate:gradle-release"))
revertOnFail.set(true)
buildTasks.set(listOf("clean", "hivemqExtensionZip", "checksum"))
}

tasks.prepareHivemqHome {
hivemqHomeDirectory.set(file("hivemq-${libs.versions.hivemq.extensionSdk.get()}"))
}

task<Checksum>("checksum") {
dependsOn("hivemqExtensionZip")
checksumAlgorithm.set(Checksum.Algorithm.SHA256)
inputFiles.setFrom(
files(
tasks.hivemqExtensionZip.get().outputs.files
)
)
outputDirectory.set(file("${layout.buildDirectory.get()}/hivemq-extension"))
}

repositories {
mavenCentral()
}
Expand All @@ -37,12 +60,6 @@ dependencies {
implementation(libs.commonsLang)
}

tasks.register<Checksum>("checksum") {
checksumAlgorithm.set(Checksum.Algorithm.SHA256)
inputFiles.from(tasks.hivemqExtensionZip)
outputDirectory = layout.buildDirectory.dir("hivemq-extension")
}

@Suppress("UnstableApiUsage")
testing {
suites {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=4.24.0
version=4.28.0
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[versions]
commonsLang = "3.8.1"
guava = "31.1-jre"
hivemq-extensionSdk = "4.24.0"
hivemq-extensionSdk = "4.28.0"
jackson = "2.13.2"
jacksonv1 = "1.9.13"
jackson-asl = "1.9.13"
jetbrains-annotations = "24.0.1"
junit-jupiter = "5.10.0"
mockito = "5.6.0"
Expand All @@ -15,7 +15,7 @@ commonsLang = { module = "org.apache.commons:commons-lang3", version.ref = "comm
guava = { module = "com.google.guava:guava", version.ref = "guava" }
jackson = { module = "com.fasterxml.jackson.core:jackson-core", version.ref = "jackson" }
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "jackson" }
jackson-mapper-asl = { module = "org.codehaus.jackson:jackson-mapper-asl", version.ref = "jacksonv1" }
jackson-mapper-asl = { module = "org.codehaus.jackson:jackson-mapper-asl", version.ref = "jackson-asl" }
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
protobuf = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
Expand All @@ -26,3 +26,4 @@ hivemq-extension = { id = "com.hivemq.extension", version = "3.1.0" }
defaults = { id = "io.github.sgtsilvio.gradle.defaults", version = "0.2.0" }
license = { id = "com.github.hierynomus.license", version = "0.16.1" }
checksum = { id = "org.gradle.crypto.checksum", version = "1.4.0"}
release = { id = "net.researchgate.release", version = "3.0.2" }
1 change: 1 addition & 0 deletions src/hivemq-extension/conf/sparkplug.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ sparkplug.systopic=$sparkplug/certificates/
sparkplug.compression=false
sparkplug.json.log=false
sparkplug.systopic.msgExpiry=4294967296
sparkplug.metrics2topic=true
Loading

0 comments on commit 18204c8

Please sign in to comment.