Skip to content

Commit 1e4d32d

Browse files
authored
Merge pull request #4 from IAmNickNack/NWS-test-release
2 parents 20465aa + 16fad12 commit 1e4d32d

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

‎.github/scripts/perform-release.sh‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
3+
BUILD_VERSION=$(./gradlew :pi4j-plugin-grpc:properties -q | grep 'version:' | awk '{print $2}')
4+
DIST_ZIP=$(find . -name "pi4j-plugin-grpc-server-${BUILD_VERSION}.zip")
5+
SHADOW_JAR=$(find . -name "pi4j-plugin-grpc-server-${BUILD_VERSION}-all.jar")
6+
7+
# Stop if DIST_ZIP is empty
8+
if [ -z "${DIST_ZIP}" ]; then
9+
echo "ERROR: No distribution zip not found for version ${BUILD_VERSION}"
10+
exit 1
11+
fi
12+
13+
# Set IS_SNAPSHOT to true if BUILD_VERSION ends with `SNAPSHOT`
14+
if [[ "${BUILD_VERSION}" == *SNAPSHOT ]]; then
15+
IS_SNAPSHOT=true
16+
else
17+
IS_SNAPSHOT=false
18+
fi
19+
20+
# Set RELEASE_EXISTS to true if gh release list contains "v${BUILD_VERSION}"
21+
if gh release list | grep -q "v${BUILD_VERSION}"; then
22+
RELEASE_EXISTS=true
23+
else
24+
RELEASE_EXISTS=false
25+
fi
26+
27+
# If this is a non-snapshot release and the release already exists, abort to avoid overwriting it.
28+
if [ "${IS_SNAPSHOT}" = "false" ] && [ "${RELEASE_EXISTS}" = "true" ]; then
29+
echo "ERROR: Release v${BUILD_VERSION} already exists and this is not a snapshot. Aborting to avoid overwrite."
30+
exit 1
31+
fi
32+
33+
# If the release doesn't exist, create it
34+
if [ "${RELEASE_EXISTS}" = "false" ]; then
35+
echo "Creating release: v${BUILD_VERSION}"
36+
37+
if [ "${IS_SNAPSHOT}" = "true" ]; then
38+
echo "Marking release as prerelease (snapshot)"
39+
gh release create "v${BUILD_VERSION}" --title "v${BUILD_VERSION}" --notes "Automated snapshot release for version ${BUILD_VERSION}" --prerelease
40+
RC=$?
41+
else
42+
gh release create "v${BUILD_VERSION}" --title "v${BUILD_VERSION}" --notes "Release for version ${BUILD_VERSION}"
43+
RC=$?
44+
fi
45+
46+
if [ ${RC} -ne 0 ]; then
47+
echo "ERROR: Failed to create release v${BUILD_VERSION}"
48+
exit 1
49+
fi
50+
fi
51+
52+
echo "Uploading ${DIST_ZIP} to v${BUILD_VERSION}"
53+
gh release upload "v${BUILD_VERSION}" "${DIST_ZIP}" "${SHADOW_JAR}" --clobber
54+
RC=$?
55+
if [ ${RC} -ne 0 ]; then
56+
echo "ERROR: Failed to upload asset to existing release v${BUILD_VERSION}"
57+
exit 1
58+
fi
59+
echo "Asset uploaded to existing snapshot release v${BUILD_VERSION}."

‎.github/workflows/ci.yml‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ on:
99
branches:
1010
- main
1111
- develop
12-
1312
workflow_dispatch:
13+
inputs:
14+
manual_release:
15+
description: 'Perform a release'
16+
required: false
17+
default: false
18+
type: boolean
1419

1520
jobs:
1621
build:
@@ -29,4 +34,15 @@ jobs:
2934
uses: gradle/actions/setup-gradle@v5
3035

3136
- name: Build with Gradle
32-
run: ./gradlew build
37+
run: |
38+
./gradlew --configuration-cache build
39+
40+
- name: Do Release
41+
if: github.ref == 'refs/heads/main' || github.event.inputs.manual_release == 'true'
42+
env:
43+
GITHUB_USERNAME: ${{ github.actor }}
44+
GITHUB_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
45+
GH_TOKEN: ${{ secrets.ACTIONS_TOKEN }}
46+
run: |
47+
./gradlew --configuration-cache publish
48+
./.github/scripts/perform-release.sh

‎gradle/wrapper/gradle-wrapper.properties‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https://services.gradle.org/distributions/gradle-9.1.0-bin.zip
3+
distributionUrl=https://services.gradle.org/distributions/gradle-9.2.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

0 commit comments

Comments
 (0)