Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 70 additions & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,73 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commitish: main
commitish: main

update_version:
needs: update_release_draft
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- name: Get latest draft release title
run: |
TITLE=$(gh api repos/${{ github.repository }}/releases \
--jq '.[] | select(.draft==true) | .name' | head -n 1)
if [[ -z "$TITLE" ]]; then
echo "No draft release found."
exit 1
fi
VERSION=$(echo "$TITLE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
if [[ -z "$VERSION" ]]; then
echo "No version found in version."
exit 1
fi
echo "Extracted version: $VERSION"
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: main

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: zulu
java-version: 17

# Setup Gradle
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
cache-read-only: true

- name: Update Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
./gradlew replaceDraftVersion -PdraftVersion=$RELEASE_VERSION

- name: Commit New Version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config user.email "[email protected]"
git config user.name "GitHub Action"
git pull
git add src/main/kotlin/org/domaframework/doma/intellij/common/PluginUtil.kt
git add src/main/resources/logback.xml
git add src/main/resources/logback-test.xml
git add gradle.properties
if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes to commit."
exit 0
fi
git commit -am "Update Version With Release Draft - $REPLACE_VERSION"
git push origin main
41 changes: 39 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
# Prepare and publish the plugin to JetBrains Marketplace repository
release:
name: Publish Plugin
runs-on: ubuntu-24.04
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
Expand Down Expand Up @@ -57,4 +57,41 @@ jobs:
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*

- name: Update Version
run: |
./gradlew replaceNewVersion -PnewVersion=${{ github.event.release.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Commit New Version
run: |
git config user.email "[email protected]"
git config user.name "GitHub Action"
git fetch
git checkout main
git add src/main/kotlin/org/domaframework/doma/intellij/common/PluginUtil.kt
git add src/main/resources/logback.xml
git add src/main/resources/logback-test.xml
git add gradle.properties
if [[ -z "$(git status --porcelain)" ]]; then
echo "No changes to commit."
exit 0
fi
git commit -am "Update Version With Release - $REPLACE_VERSION"
git push origin main
create_release_draft:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commitish: main
85 changes: 85 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,88 @@ spotless {
endWithNewline()
}
}

val encoding: String by project

fun replaceVersionInPluginUtil(ver: String) {
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """(const val PLUGIN_VERSION = ")(\d+\.\d+\.\d+)((?:-beta)*)""",
"replace" to "\\1$ver",
"encoding" to encoding,
"flags" to "g",
) {
"fileset"("dir" to ".") {
"include"("name" to "**/PluginUtil.kt")
}
}
}
}

fun replaceVersionGradleProperty(ver: String) {
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """(pluginVersion = )(\d+\.\d+\.\d+)((?:-beta)*)""",
"replace" to "\\1$ver",
"encoding" to encoding,
"flags" to "g",
) {
"fileset"("dir" to ".") {
"include"("name" to "**/gradle.properties")
}
}
}
}

fun replaceVersionInLogSetting(ver: String) {
ant.withGroovyBuilder {
"replaceregexp"(
"match" to """(org.domaframework.doma.intellij.plugin.version:-)(\d+\.\d+\.\d+)((?:-beta)*)(})""",
"replace" to "\\1$ver\\4",
"encoding" to encoding,
"flags" to "g",
) {
"fileset"("dir" to ".") {
"include"("name" to "**/logback.xml")
"include"("name" to "**/logback-test.xml")
}
}
}
}

fun replaceVersion(ver: String) {
checkNotNull(ver)
replaceVersionInPluginUtil(ver)
replaceVersionGradleProperty("$ver-beta")
replaceVersionInLogSetting(ver)

val githubEnv = System.getenv("GITHUB_ENV")
val envFile = File(githubEnv)
envFile.appendText("REPLACE_VERSION=$ver\n")
}

tasks.register("replaceNewVersion") {
doLast {
val releaseVersion = project.properties["newVersion"]?.toString() ?: "0.0.0"
val lastVersions = releaseVersion.substringAfter("v").split(".")
val major = lastVersions[0].toInt()
val minor = lastVersions[1].toInt()
val patch = lastVersions[2].toInt() + 1

val newVersion = "$major.$minor.$patch"
println("Release newVersion: $newVersion")
replaceVersion(newVersion)
}
}

tasks.register("replaceDraftVersion") {
doLast {
val draftVersion =
project.properties["draftVersion"]
.toString()
.substringBefore("-beta")

println("Release DraftVersion: $draftVersion")
replaceVersion(draftVersion)
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ org.gradle.configuration-cache = true
org.gradle.caching = true

updateSinceUntilBuild = false

encoding = UTF-8
Loading