|
| 1 | +name: ClientCore Releases |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - '**' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: clientcore-release-${{ github.ref }} |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +env: |
| 17 | + GRADLE_OPTS: "-Dorg.gradle.daemon=false" |
| 18 | + |
| 19 | +jobs: |
| 20 | + build_release: |
| 21 | + name: Build & Publish Releases |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Checkout Repository |
| 26 | + uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Setup Java JDK 25 |
| 31 | + uses: actions/setup-java@v4 |
| 32 | + with: |
| 33 | + distribution: temurin |
| 34 | + java-version: '25' |
| 35 | + cache: gradle |
| 36 | + |
| 37 | + - name: Build Plugin |
| 38 | + run: | |
| 39 | + chmod +x ./gradlew |
| 40 | + ./gradlew clean build |
| 41 | +
|
| 42 | + - name: Prepare Release Metadata |
| 43 | + id: meta |
| 44 | + shell: bash |
| 45 | + run: | |
| 46 | + set -euo pipefail |
| 47 | +
|
| 48 | + VERSION=$(./gradlew properties -q | awk '/^version:/ { print $2; exit }') |
| 49 | + if [ -z "$VERSION" ]; then |
| 50 | + echo "Gradle project version could not be detected." >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + SHORT_SHA=$(git rev-parse --short HEAD) |
| 55 | + VERSION_TAG="v${VERSION}" |
| 56 | + DEV_TAG="latest-devbuild" |
| 57 | +
|
| 58 | + JAR_FILE=$(find build/libs -maxdepth 1 -type f -name "*.jar" ! -name "*-sources.jar" ! -name "*-javadoc.jar" | sort | head -n 1) |
| 59 | + if [ -z "$JAR_FILE" ] || [ ! -f "$JAR_FILE" ]; then |
| 60 | + echo "No build jar found in build/libs." >&2 |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + mkdir -p dist |
| 65 | + RELEASE_JAR="dist/ClientCore-${VERSION}.jar" |
| 66 | + DEV_JAR="dist/ClientCore-latest-devbuild.jar" |
| 67 | + cp "$JAR_FILE" "$RELEASE_JAR" |
| 68 | + cp "$JAR_FILE" "$DEV_JAR" |
| 69 | +
|
| 70 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 71 | + echo "version_tag=$VERSION_TAG" >> "$GITHUB_OUTPUT" |
| 72 | + echo "dev_tag=$DEV_TAG" >> "$GITHUB_OUTPUT" |
| 73 | + echo "short_sha=$SHORT_SHA" >> "$GITHUB_OUTPUT" |
| 74 | + echo "release_jar=$RELEASE_JAR" >> "$GITHUB_OUTPUT" |
| 75 | + echo "dev_jar=$DEV_JAR" >> "$GITHUB_OUTPUT" |
| 76 | +
|
| 77 | + - name: Generate Changelogs |
| 78 | + id: changelog |
| 79 | + shell: bash |
| 80 | + run: | |
| 81 | + set -euo pipefail |
| 82 | +
|
| 83 | + VERSION_TAG="${{ steps.meta.outputs.version_tag }}" |
| 84 | + VERSION="${{ steps.meta.outputs.version }}" |
| 85 | + SHORT_SHA="${{ steps.meta.outputs.short_sha }}" |
| 86 | +
|
| 87 | + PREVIOUS_VERSION_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+(\.[0-9]+)*([-+][A-Za-z0-9._-]+)?$' | grep -v "^${VERSION_TAG}$" | head -n 1 || true) |
| 88 | + if [ -n "$PREVIOUS_VERSION_TAG" ]; then |
| 89 | + RANGE="${PREVIOUS_VERSION_TAG}..HEAD" |
| 90 | + RANGE_TEXT="since ${PREVIOUS_VERSION_TAG}" |
| 91 | + else |
| 92 | + RANGE="HEAD" |
| 93 | + RANGE_TEXT="from repository history" |
| 94 | + fi |
| 95 | +
|
| 96 | + { |
| 97 | + echo "## ClientCore ${VERSION}" |
| 98 | + echo |
| 99 | + echo "Built from commit \`${GITHUB_SHA}\`." |
| 100 | + echo |
| 101 | + echo "### Changes ${RANGE_TEXT}" |
| 102 | + git log "$RANGE" --pretty=format:'- %s (%h)' --no-merges || true |
| 103 | + } > version_changelog.md |
| 104 | +
|
| 105 | + if ! grep -q '^- ' version_changelog.md; then |
| 106 | + echo "- No commit changelog was available for this build." >> version_changelog.md |
| 107 | + fi |
| 108 | +
|
| 109 | + { |
| 110 | + echo "## Latest ClientCore Dev Build" |
| 111 | + echo |
| 112 | + echo "- Version: \`${VERSION}\`" |
| 113 | + echo "- Commit: \`${GITHUB_SHA}\`" |
| 114 | + echo "- Branch: \`${GITHUB_REF_NAME}\`" |
| 115 | + echo "- Build: [#${GITHUB_RUN_NUMBER}](${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID})" |
| 116 | + echo |
| 117 | + echo "### Recent Changes" |
| 118 | + git log -20 --pretty=format:'- %s (%h)' --no-merges || true |
| 119 | + } > devbuild_changelog.md |
| 120 | +
|
| 121 | + if ! grep -q '^- ' devbuild_changelog.md; then |
| 122 | + echo "- No commit changelog was available for this build." >> devbuild_changelog.md |
| 123 | + fi |
| 124 | +
|
| 125 | + echo "version_body=version_changelog.md" >> "$GITHUB_OUTPUT" |
| 126 | + echo "dev_body=devbuild_changelog.md" >> "$GITHUB_OUTPUT" |
| 127 | +
|
| 128 | + - name: Publish Latest Dev Build Release |
| 129 | + if: github.ref_name == github.event.repository.default_branch |
| 130 | + env: |
| 131 | + GH_TOKEN: ${{ github.token }} |
| 132 | + shell: bash |
| 133 | + run: | |
| 134 | + set -euo pipefail |
| 135 | +
|
| 136 | + DEV_TAG="${{ steps.meta.outputs.dev_tag }}" |
| 137 | + DEV_JAR="${{ steps.meta.outputs.dev_jar }}" |
| 138 | + DEV_BODY="${{ steps.changelog.outputs.dev_body }}" |
| 139 | +
|
| 140 | + git tag -f "$DEV_TAG" "$GITHUB_SHA" |
| 141 | + git push -f origin "refs/tags/${DEV_TAG}" |
| 142 | +
|
| 143 | + if gh release view "$DEV_TAG" >/dev/null 2>&1; then |
| 144 | + gh release edit "$DEV_TAG" \ |
| 145 | + --title "Latest ClientCore Dev Build" \ |
| 146 | + --notes-file "$DEV_BODY" \ |
| 147 | + --prerelease \ |
| 148 | + --latest=false |
| 149 | + else |
| 150 | + gh release create "$DEV_TAG" \ |
| 151 | + --title "Latest ClientCore Dev Build" \ |
| 152 | + --notes-file "$DEV_BODY" \ |
| 153 | + --prerelease \ |
| 154 | + --latest=false |
| 155 | + fi |
| 156 | +
|
| 157 | + gh release upload "$DEV_TAG" "$DEV_JAR" --clobber |
| 158 | +
|
| 159 | + - name: Publish Version Release |
| 160 | + if: github.ref_name == github.event.repository.default_branch |
| 161 | + env: |
| 162 | + GH_TOKEN: ${{ github.token }} |
| 163 | + shell: bash |
| 164 | + run: | |
| 165 | + set -euo pipefail |
| 166 | +
|
| 167 | + VERSION_TAG="${{ steps.meta.outputs.version_tag }}" |
| 168 | + RELEASE_JAR="${{ steps.meta.outputs.release_jar }}" |
| 169 | + VERSION_BODY="${{ steps.changelog.outputs.version_body }}" |
| 170 | +
|
| 171 | + git tag -f "$VERSION_TAG" "$GITHUB_SHA" |
| 172 | + git push -f origin "refs/tags/${VERSION_TAG}" |
| 173 | +
|
| 174 | + if gh release view "$VERSION_TAG" >/dev/null 2>&1; then |
| 175 | + gh release edit "$VERSION_TAG" \ |
| 176 | + --title "ClientCore ${{ steps.meta.outputs.version }}" \ |
| 177 | + --notes-file "$VERSION_BODY" \ |
| 178 | + --latest |
| 179 | + else |
| 180 | + gh release create "$VERSION_TAG" \ |
| 181 | + --title "ClientCore ${{ steps.meta.outputs.version }}" \ |
| 182 | + --notes-file "$VERSION_BODY" \ |
| 183 | + --latest |
| 184 | + fi |
| 185 | +
|
| 186 | + gh release upload "$VERSION_TAG" "$RELEASE_JAR" --clobber |
| 187 | +
|
| 188 | + - name: Upload Workflow Artifact |
| 189 | + uses: actions/upload-artifact@v4 |
| 190 | + with: |
| 191 | + name: ClientCore-${{ steps.meta.outputs.version }}-${{ steps.meta.outputs.short_sha }} |
| 192 | + path: dist/*.jar |
| 193 | + retention-days: 14 |
0 commit comments