Skip to content

Commit

Permalink
Improvements in gradle-cd-pipeline and build (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
shabaz213 authored Jul 25, 2024
1 parent 89014ab commit 9c46fc2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 29 deletions.
54 changes: 35 additions & 19 deletions .github/workflows/gradle-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ name: Gradle CD

on:
push:
tags:
- '*'
branches: [ "master" ]

jobs:

Expand All @@ -22,28 +21,45 @@ jobs:
java-version: '8'
distribution: 'adopt-openj9'

- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Set up Git
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Fetch all tags
run: git fetch --tags

- name: Get short commit SHA
id: getShortHash
run: echo "shortHash=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_OUTPUT
- name: Determine next tag version
id: getNextTag
run: |
# Get version from plugin.xml
pluginXmlVersion=$(grep -oP '<identifier .* version="\K[^"]+' src/main/zip/plugin.xml)
echo "pluginXmlVersion is $pluginXmlVersion"
- name: Get Version
run: ./gradlew writePluginVersionToFile
# Get the latest tag
latestTag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "latestTag is $latestTag"
- name: Get Plugin Version
id: getPluginVersion
run: echo "pluginVersion=$(cat .output.txt).${{ steps.getShortHash.outputs.shortHash }}" >> $GITHUB_OUTPUT
# Determine next tag
if awk "BEGIN {exit !( $latestTag < $pluginXmlVersion )}"; then
nextTag="$pluginXmlVersion.0"
else
nextTag=$(awk "BEGIN {print $latestTag + 0.1}")
fi
- name: Echo Plugin Version
run: echo "${{ steps.getPluginVersion.outputs.pluginVersion }}"
echo "nextTag is $nextTag"
echo "value=$nextTag" >> $GITHUB_OUTPUT
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew

- name: Create dist
run: ./gradlew "-PpluginVersion=${{ steps.getPluginVersion.outputs.pluginVersion }}" distPlugin
run: ./gradlew "-PpluginVersion=${{ steps.getNextTag.outputs.value }}" distPlugin

- name: Create Release
uses: ncipollo/release-action@v1.12.0
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: "${{ github.event.repository.name }} v${{ steps.getPluginVersion.outputs.pluginVersion }}"
artifacts: "build/distributions/*.zip"
tag_name: ${{ steps.getNextTag.outputs.value }}
files: "build/distributions/*.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This plug-in requires version 6.2.2 (or later) of IBM UrbanCode Deploy.

* Use wrapper script `gradlew/gradle.bat` to build the project locally.
* To create distributable with a plugin release version pass property `pluginVersion` while running wrapper script like below
> ./gradlew "-PpluginVersion=7.24072024"
> ./gradlew "-PpluginVersion=6.9"
### Installation
The packaged zip is located in the 'Releases' tab. No special steps are required for installation.
Expand Down
10 changes: 1 addition & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ tasks.register('distPlugin', Zip) {
exclude 'META-INF', 'i18n-scraper.groovy'
}

archiveFileName = pluginVersion ? "${pluginName}-v${pluginVersion}.zip" : "${pluginName}-dev.zip"
archiveFileName = "${pluginName}-${pluginVersion}.zip"
}

tasks.register('gatherI18n', JavaExec) {
Expand All @@ -134,14 +134,6 @@ tasks.register('gatherI18n', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
}

tasks.register('writePluginVersionToFile') {
File pluginXml = new File('./src/main/zip/plugin.xml')
def plugin = new XmlParser().parse(pluginXml)
String[] version = plugin.header.identifier.@version
File file = new File(".output.txt")
file.write version[0]
}

tasks.register('cleanAll') {
dependsOn('clean', 'cleanCopyDeps', 'cleanDistPlugin', 'cleanGatherI18n')
}
Expand Down

0 comments on commit 9c46fc2

Please sign in to comment.