Skip to content

Commit

Permalink
chore: setup release plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
benny123tw committed Jun 19, 2024
1 parent c88e9cc commit 25ef1d5
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 36 deletions.
34 changes: 34 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!-- ☝️ PR title should follow conventional commits (https://conventionalcommits.org) -->
<!-- Thanks for taking the time to write this Pull Request! ❤️ -->

### ❓ Type of change

<!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. -->

- [ ] 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
- [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
- [ ] 👌 Enhancement (improving an existing functionality like performance)
- [ ] ✨ New feature (a non-breaking change that adds functionality)
- [ ] 🧹 Chore (updates to the build process or auxiliary tools and libraries)
- [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

### 📚 Description, Motivation and Context

<!-- Describe your changes in detail -->
<!-- Why is this change required? What problem does it solve? -->
<!-- If it resolves an open issue, please link to the issue here. For example "Resolves #1337" -->

### 🧪 How Has This Been Tested?

<!-- Please describe in detail how you tested your changes. -->
<!-- Include details of your testing environment, tests ran to see how -->
<!-- your change affects other areas of the code, etc. -->

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.
48 changes: 24 additions & 24 deletions .github/workflows/1.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ on:
- '*'
pull_request:
branches: [ '*' ]
# workflow_dispatch:
# inputs:
# type:
# description: 'Release Library'
# required: true
# default: '...no release'
# type: choice
# options:
# - '...no release'
# - major
# - minor
# - patch
workflow_dispatch:
inputs:
type:
description: 'Release Library'
required: true
default: '...no release'
type: choice
options:
- '...no release'
- major
- minor
- patch

jobs:

Expand All @@ -30,7 +30,7 @@ jobs:
name: Build + unit tests
uses: ./.github/workflows/callable.build.yml
if: | # avoid unnecessary pipeline runs during artifact release process ('gradle release plugin')
!contains(github.event.head_commit.message, '[Gradle Release Plugin] - pre tag commit')
!contains(github.event.head_commit.message, 'chore: release v')
|| github.ref_type == 'tag'
code_analysis:
Expand All @@ -50,16 +50,16 @@ jobs:
# uses: ./.github/workflows/callable.integration-test.yml
# needs: build

# gradle_release:
# name: Create release
# uses: ./.github/workflows/callable.gradle-release.yml
# secrets: inherit
# with:
# type: ${{ inputs.type }}
# needs: build
# if: |
# github.event_name == 'workflow_dispatch'
# && inputs.type != '...no release'
gradle_release:
name: Create release
uses: ./.github/workflows/callable.gradle-release.yml
secrets: inherit
with:
type: ${{ inputs.type }}
needs: build
if: |
github.event_name == 'workflow_dispatch'
&& inputs.type != '...no release'
publish_central_portal:
name: Publish artifact (Maven Central)
Expand All @@ -80,7 +80,7 @@ jobs:
permissions:
contents: write
uses: ./.github/workflows/callable.publish-dokka.yml
needs: build
needs: [build, publish_central_portal]
if: |
(
github.ref == 'refs/heads/main'
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/callable.gradle-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Gradle Release

on:
workflow_call:
inputs:
type:
description: 'Release type'
required: true
type: string

jobs:
release:
name: gradle release
runs-on: ubuntu-latest
steps:
- name: Validate 'Release Type' param
env:
TYPE: ${{ inputs.type }}
run: |
valid_types=(major minor patch)
if [[ ! ${valid_types[*]} =~ "$TYPE" ]]; then
echo "Unknown release type: $TYPE"
exit 1
fi
- name: Checkout project sources ('main' branch)
uses: actions/checkout@v4
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
- uses: gradle/actions/wrapper-validation@v3
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3.3.2
with:
cache-read-only: true

- name: Get current version
run: |
source gradle.properties
echo "current_version=${version}" >> $GITHUB_ENV
- name: Determine version type
env:
TYPE: ${{ inputs.type }}
VERSION: ${{ env.current_version }}
run: |
export major=$(echo "${VERSION}" | cut -d. -f1)
export minor=$(echo "${VERSION}" | cut -d. -f2)
export patch=$(echo "${VERSION}" | cut -d. -f3 | cut -d- -f1)
echo "resolved: ${major}.${minor}.${patch}"
if [[ "$TYPE" == "major" ]]; then
echo "new_version=$((major+1)).0.0" >> $GITHUB_ENV
echo "new_snapshot_version=$((major+1)).0.1-SNAPSHOT" >> $GITHUB_ENV
elif [ "$TYPE" == "minor" ]; then
echo "new_version=${major}.$((minor+1)).0" >> $GITHUB_ENV
echo "new_snapshot_version=${major}.$((minor+1)).1-SNAPSHOT" >> $GITHUB_ENV
else
echo "new_version=${major}.${minor}.${patch}" >> $GITHUB_ENV
echo "new_snapshot_version=${major}.${minor}.$((patch+1))-SNAPSHOT" >> $GITHUB_ENV
fi
- name: Set git config 'user.name' and 'user.email'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Run 'gradle release'
run: |
echo "Type: ${{ inputs.type }}"
echo "Current version: ${{ env.current_version }}"
echo "New version: ${{ env.new_version }}"
echo "./gradlew release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.new_version }}
gradle release -Prelease.useAutomaticVersion=true -Prelease.releaseVersion=${{ env.new_version }}
18 changes: 9 additions & 9 deletions .github/workflows/callable.publish-central-portal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ jobs:
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingInMemoryKey }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signingInMemoryKeyId }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingInMemoryKeyPassword }}
- name: Publish RELEASE to Central Portal
if: github.ref_type == 'tag'
run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.mavenCentralUsername }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.mavenCentralPassword }}
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingInMemoryKey }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signingInMemoryKeyId }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingInMemoryKeyPassword }}
# - name: Publish RELEASE to Central Portal
# if: github.ref_type == 'tag'
# run: ./gradlew publishAndReleaseToMavenCentral --no-configuration-cache
# env:
# ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.mavenCentralUsername }}
# ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.mavenCentralPassword }}
# ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.signingInMemoryKey }}
# ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.signingInMemoryKeyId }}
# ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.signingInMemoryKeyPassword }}
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import com.vanniktech.maven.publish.SonatypeHost
import net.researchgate.release.ReleaseExtension

plugins {
`java-library`
alias(libs.plugins.publish.maven)
alias(libs.plugins.dokka)
kotlin("jvm") version "2.0.0" apply false

alias(libs.plugins.release)
}

description = "Java library for Vite integration."
Expand Down Expand Up @@ -80,3 +83,15 @@ mavenPublishing {
}
}
}

// See: https://github.com/researchgate/gradle-release
configure<ReleaseExtension> {
ignoredSnapshotDependencies.set(listOf("net.researchgate:gradle-release"))
tagTemplate.set("v${version}")
// Central portal does not support snapshot versions
snapshotSuffix.set("")

preTagCommitMessage.set("chore: release v${version}")
tagCommitMessage.set("chore: release v${version}")
newVersionCommitMessage.set("chore: release v${version}")
}
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# JRE 8
jre8_springframework = "5.3.15"
jre8_springframework_boot = "2.6.3"
jre8_spring_dependency_management = "1.0.11.RELEASE"
jre8_jackson_core = "2.13.0"
jre8_javax_servlet = "4.0.1"
jre8_javax_servlet_jsp = "2.3.3"

# JRE 17
dokka = "1.9.20"
springframework = "6.1.8"
springframework_boot = "3.3.0"
spring_dependency_management = "1.1.5"
Expand All @@ -18,7 +18,7 @@ junit = "5.10.2"
assertj = "3.26.0"
testcontainers = "1.19.8"
publish_maven_plugin = "0.28.0"
dokka = "1.9.20"
release_plugin = "3.0.2"

[libraries]
# JRE 8
Expand All @@ -32,6 +32,7 @@ jre8_jackson_databind = { module = "com.fasterxml.jackson.core:jackson-databind"
jre8_javax_servlet = { module = "javax.servlet:javax.servlet-api", version.ref = "jre8_javax_servlet" }
jre8_javax_servlet_jsp = { module = "javax.servlet.jsp:javax.servlet.jsp-api", version.ref = "jre8_javax_servlet_jsp" }

# JRE 17
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
junit_bom = { module = "org.junit:junit-bom", version.ref = "junit" }
assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" }
Expand All @@ -55,4 +56,4 @@ spring_boot = { id = "org.springframework.boot", version.ref = "springframework_
spring_dependency_management = { id = "io.spring.dependency-management", version.ref = "spring_dependency_management" }
publish_maven = { id = "com.vanniktech.maven.publish", version.ref = "publish_maven_plugin" }
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" }

release = { id = "net.researchgate.release", version.ref = "release_plugin" }

0 comments on commit 25ef1d5

Please sign in to comment.