Skip to content

Commit 9077854

Browse files
committed
Update the development version after release and when creating a release draft
1 parent 0a49f29 commit 9077854

File tree

4 files changed

+196
-3
lines changed

4 files changed

+196
-3
lines changed

.github/workflows/release-drafter.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,73 @@ jobs:
2424
env:
2525
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2626
with:
27-
commitish: main
27+
commitish: main
28+
29+
update_version:
30+
needs: update_release_draft
31+
permissions:
32+
contents: write
33+
pull-requests: write
34+
runs-on: ubuntu-latest
35+
timeout-minutes: 30
36+
37+
steps:
38+
- name: Get latest draft release title
39+
run: |
40+
TITLE=$(gh api repos/${{ github.repository }}/releases \
41+
--jq '.[] | select(.draft==true) | .name' | head -n 1)
42+
if [[ -z "$TITLE" ]]; then
43+
echo "No draft release found."
44+
exit 1
45+
fi
46+
VERSION=$(echo "$TITLE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
47+
if [[ -z "$VERSION" ]]; then
48+
echo "No version found in version."
49+
exit 1
50+
fi
51+
echo "Extracted version: $VERSION"
52+
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Checkout repository
57+
uses: actions/checkout@v4
58+
with:
59+
fetch-depth: 0
60+
ref: main
61+
62+
- name: Setup Java
63+
uses: actions/setup-java@v4
64+
with:
65+
distribution: zulu
66+
java-version: 17
67+
68+
# Setup Gradle
69+
- name: Setup Gradle
70+
uses: gradle/actions/setup-gradle@v4
71+
with:
72+
cache-read-only: true
73+
74+
- name: Update Version
75+
env:
76+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
run: |
78+
./gradlew replaceDraftVersion -PdraftVersion=$RELEASE_VERSION
79+
80+
- name: Commit New Version
81+
env:
82+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
83+
run: |
84+
git config user.email "[email protected]"
85+
git config user.name "GitHub Action"
86+
git pull
87+
git add src/main/kotlin/org/domaframework/doma/intellij/common/PluginUtil.kt
88+
git add src/main/resources/logback.xml
89+
git add src/main/resources/logback-test.xml
90+
git add gradle.properties
91+
if [[ -z "$(git status --porcelain)" ]]; then
92+
echo "No changes to commit."
93+
exit 0
94+
fi
95+
git commit -am "Update Version With Release Draft - $REPLACE_VERSION"
96+
git push origin main

.github/workflows/release.yml

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
# Prepare and publish the plugin to JetBrains Marketplace repository
1313
release:
1414
name: Publish Plugin
15-
runs-on: ubuntu-24.04
15+
runs-on: ubuntu-latest
1616
permissions:
1717
contents: write
1818
pull-requests: write
@@ -57,4 +57,41 @@ jobs:
5757
- name: Upload Release Asset
5858
env:
5959
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60-
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
60+
run: gh release upload ${{ github.event.release.tag_name }} ./build/distributions/*
61+
62+
- name: Update Version
63+
run: |
64+
./gradlew replaceNewVersion -PnewVersion=${{ github.event.release.tag_name }}
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Commit New Version
69+
run: |
70+
git config user.email "[email protected]"
71+
git config user.name "GitHub Action"
72+
git fetch
73+
git checkout main
74+
git add src/main/kotlin/org/domaframework/doma/intellij/common/PluginUtil.kt
75+
git add src/main/resources/logback.xml
76+
git add src/main/resources/logback-test.xml
77+
git add gradle.properties
78+
if [[ -z "$(git status --porcelain)" ]]; then
79+
echo "No changes to commit."
80+
exit 0
81+
fi
82+
git commit -am "Update Version With Release - $REPLACE_VERSION"
83+
git push origin main
84+
85+
create_release_draft:
86+
permissions:
87+
contents: write
88+
pull-requests: write
89+
runs-on: ubuntu-latest
90+
timeout-minutes: 30
91+
92+
steps:
93+
- uses: release-drafter/release-drafter@v6
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
with:
97+
commitish: main

build.gradle.kts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,3 +544,88 @@ spotless {
544544
endWithNewline()
545545
}
546546
}
547+
548+
val encoding: String by project
549+
550+
fun replaceVersionInPluginUtil(ver: String) {
551+
ant.withGroovyBuilder {
552+
"replaceregexp"(
553+
"match" to """(const val PLUGIN_VERSION = ")(\d+\.\d+\.\d+)((?:-beta)*)""",
554+
"replace" to "\\1$ver",
555+
"encoding" to encoding,
556+
"flags" to "g",
557+
) {
558+
"fileset"("dir" to ".") {
559+
"include"("name" to "**/PluginUtil.kt")
560+
}
561+
}
562+
}
563+
}
564+
565+
fun replaceVersionGradleProperty(ver: String) {
566+
ant.withGroovyBuilder {
567+
"replaceregexp"(
568+
"match" to """(pluginVersion = )(\d+\.\d+\.\d+)((?:-beta)*)""",
569+
"replace" to "\\1$ver",
570+
"encoding" to encoding,
571+
"flags" to "g",
572+
) {
573+
"fileset"("dir" to ".") {
574+
"include"("name" to "**/gradle.properties")
575+
}
576+
}
577+
}
578+
}
579+
580+
fun replaceVersionInLogSetting(ver: String) {
581+
ant.withGroovyBuilder {
582+
"replaceregexp"(
583+
"match" to """(org.domaframework.doma.intellij.plugin.version:-)(\d+\.\d+\.\d+)((?:-beta)*)(})""",
584+
"replace" to "\\1$ver\\4",
585+
"encoding" to encoding,
586+
"flags" to "g",
587+
) {
588+
"fileset"("dir" to ".") {
589+
"include"("name" to "**/logback.xml")
590+
"include"("name" to "**/logback-test.xml")
591+
}
592+
}
593+
}
594+
}
595+
596+
fun replaceVersion(ver: String) {
597+
checkNotNull(ver)
598+
replaceVersionInPluginUtil(ver)
599+
replaceVersionGradleProperty("$ver-beta")
600+
replaceVersionInLogSetting(ver)
601+
602+
val githubEnv = System.getenv("GITHUB_ENV")
603+
val envFile = File(githubEnv)
604+
envFile.appendText("REPLACE_VERSION=$ver\n")
605+
}
606+
607+
tasks.register("replaceNewVersion") {
608+
doLast {
609+
val releaseVersion = project.properties["newVersion"]?.toString() ?: "0.0.0"
610+
val lastVersions = releaseVersion.substringAfter("v").split(".")
611+
val major = lastVersions[0].toInt()
612+
val minor = lastVersions[1].toInt()
613+
val patch = lastVersions[2].toInt() + 1
614+
615+
val newVersion = "$major.$minor.$patch"
616+
println("Release newVersion: $newVersion")
617+
replaceVersion(newVersion)
618+
}
619+
}
620+
621+
tasks.register("replaceDraftVersion") {
622+
doLast {
623+
val draftVersion =
624+
project.properties["draftVersion"]
625+
.toString()
626+
.substringBefore("-beta")
627+
628+
println("Release DraftVersion: $draftVersion")
629+
replaceVersion(draftVersion)
630+
}
631+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ org.gradle.configuration-cache = true
2020
org.gradle.caching = true
2121

2222
updateSinceUntilBuild = false
23+
24+
encoding = UTF-8

0 commit comments

Comments
 (0)