generated from hivemq/hivemq-hello-world-extension
-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (136 loc) · 5.98 KB
/
gradle-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
java-version: '11'
distribution: 'temurin'
check-latest: true
cache: gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@4c39dd82cd5e1ec7c6fa0173bb41b4b6bb3b86ff # v3.3.2
- 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