From 70afbe62110b9ffd2a1bb09b29a6951955c69ce8 Mon Sep 17 00:00:00 2001 From: ghostflyby Date: Tue, 30 Sep 2025 14:08:38 +0800 Subject: [PATCH 1/2] ci: add Maven publishing support and auto release --- .github/workflows/build.yml | 76 ++++++++++++++++++++++++++------- .github/workflows/publish.yml | 79 +++++++++++++++++++++++++++++++++++ CHANGELOG.md | 63 +++++++++++++++++++++------- build.gradle.kts | 34 ++++++++++++++- 4 files changed, 219 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 52e7a53..dc5fb39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,30 +1,74 @@ -name: Java CI +name: Build and Test on: push: branches: [ main ] - pull_request: {} + pull_request: { } jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v5 + - uses: actions/checkout@v5 - - uses: actions/setup-java@v5 - with: - java-version: 17 - distribution: zulu + - uses: actions/setup-java@v5 + with: + java-version: 17 + distribution: zulu - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} - - name: Build with Gradle - run: ./gradlew -Pversion="" build + - name: Build with Gradle + run: ./gradlew -Pversion="" build - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: Jars - path: build/libs/ + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: Jars + path: build/libs/ + + releaseDraft: + name: Release draft + if: github.event_name != 'pull_request' + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v5 + with: + fetch-depth: 0 + - uses: actions/setup-java@v5 + with: + java-version: 17 + distribution: zulu + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: true + cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} + + - name: Remove Old Release Drafts + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api repos/{owner}/{repo}/releases \ + --jq '.[] | select(.draft == true) | .id' \ + | xargs -I '{}' gh api -X DELETE repos/{owner}/{repo}/releases/{} + + - name: Create Release Draft + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION=$(./gradlew properties --property version --quiet --console=plain | tail -n 1 | cut -f2- -d ' ') + RELEASE_NOTE="./build/tmp/release_note.txt" + ./gradlew getChangelog --unreleased --no-header --quiet --console=plain --output-file=$RELEASE_NOTE + + gh release create $VERSION \ + --draft \ + --title $VERSION + --notes-file $RELEASE_NOTE \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..8bde446 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,79 @@ +name: Publish +on: + release: + types: [prereleased, released] + +jobs: + + release: + name: Publish release + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + + - uses: actions/checkout@v4 + with: + ref: ${{ github.event.release.tag_name }} + + - uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 17 + + - uses: gradle/actions/setup-gradle@v4 + with: + cache-read-only: true + cache-encryption-key: ${{ secrets.GRADLE_CACHE_ENCRYPTION_KEY }} + + - name: Publish to Maven Central + env: + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USER }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.MAVEN_GPG_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.MAVEN_GPG_SERCRET_PASSWORD }} + run: ./gradlew publishToMavenCentral --continue --info + + - name: Patch Changelog + if: ${{ github.event.release.body != '' }} + env: + CHANGELOG: ${{ github.event.release.body }} + run: | + RELEASE_NOTE="./build/tmp/release_note.txt" + mkdir -p "$(dirname "$RELEASE_NOTE")" + echo "$CHANGELOG" > $RELEASE_NOTE + + ./gradlew patchChangelog --release-note-file=$RELEASE_NOTE + + - name: Upload Release Assets + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.event.release.tag_name }} ./build/libs/*.jar + + - name: Create Pull Request + if: ${{ steps.properties.outputs.changelog != '' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + VERSION="${{ github.event.release.tag_name }}" + BRANCH="changelog-update-$VERSION" + LABEL="release changelog" + + git config user.email "action@github.com" + git config user.name "GitHub Action" + + git checkout -b $BRANCH + git commit -am "Changelog update - $VERSION [skip ci]" + git push --set-upstream origin $BRANCH + + gh label create "$LABEL" \ + --description "Pull requests with release changelog update" \ + --force \ + || true + + gh pr create \ + --title "Changelog update - \`$VERSION\`" \ + --body "Current pull request contains patched \`CHANGELOG.md\` file for the \`$VERSION\` version." \ + --label "$LABEL" \ + --head $BRANCH \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bece18..1397b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,28 +1,59 @@ -# Changelog +# PinIn Changelog -### 1.2.0 +## [Unreleased] -Changed match rules: +### Added -> Tone is no longer acceptable when missing vowel, e.g. "测试文本" no longer matches "c4shi", but still matches "ce4shi". Pinyin sequence (音序) can be used as abbreviation in Quanpin (全拼), e.g. "测试文本" matches "cswb" now without any fuzzy option, while in previous versions it only matches "cshwb". +- Support for matching characters in the Unicode Supplementary Planes. -Added switch for accelerator, disabled by default: +## [1.4.0] -> When calling immediate matching functions continuously with different `s1` but same `s2`, for, say, 100 times, they are considered stable calls. If the scenario uses mainly stable calls and most of `s1` contains Chinese characters, using accelerator provides significant speed up. Otherwise, the overhead will slow down the matching process. Accelerate mode is disabled by default for consistency in different scenarios. +### Changed -Fixed several spelling issues in Daqian (大千) keyboard -Changed some APIs +- Simplified format API for easier usage. -### 1.3.0 +## [1.3.1] -Added support for customized dictionary loading -Improved `CachedSearcher` math model for massive data -Fixed incorrect spelling in Phonetic keyboard starting with `v` +### Fixed -### 1.3.1 +- `DictLoader` accessibility issue. -Fixed `DictLoader` accessibility issue +## [1.3.0] -### 1.4.0 +### Added -Changed format API for simplified usage +- Support for customized dictionary loading. + +### Changed + +- Improved `CachedSearcher` math model for massive data. + +### Fixed + +- Incorrect spelling in Phonetic keyboard starting with `v`. + +## [1.2.0] + +### Changed + +- Match rules: + - Tone is no longer acceptable when missing vowel. + e.g. 「测试文本」 no longer matches `c4shi`, but still matches `ce4shi`. + - Pinyin sequence (音序) can be used as abbreviation in Quanpin (全拼). + e.g. 「测试文本」 now matches `cswb` without fuzzy option, + while in previous versions it only matched `cshwb`. +- Some APIs updated. + +### Added + +- Accelerator switch (disabled by default): + - When calling immediate matching functions continuously with different `s1` but same `s2` (e.g., 100 times), they + are considered stable calls. + - If most `s1` contains Chinese characters and the scenario is mainly stable calls, accelerator provides significant + speed up. + - Otherwise, the overhead slows down the process. + - Disabled by default to keep consistent performance across scenarios. + +### Fixed + +- Several spelling issues in Daqian (大千) keyboard. \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 1d12445..1535e2d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,9 +2,11 @@ plugins { java id("me.champeau.jmh") version "0.7.3" id("com.gradleup.shadow") version "9.2.0" + id("com.vanniktech.maven.publish") version "0.34.0" + id("org.jetbrains.changelog") version "2.4.0" } -group = "me.towdium.pinin" +group = "dev.ghostflyby" version = "1.6.0" repositories { @@ -25,6 +27,10 @@ tasks.test { testLogging.showStandardStreams = true } +tasks.jmhJar { + destinationDirectory = layout.buildDirectory.dir("jmhlibs") +} + tasks.withType { options.encoding = "UTF-8" options.release = 8 @@ -43,3 +49,29 @@ java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } + +mavenPublishing { + publishToMavenCentral(automaticRelease = true) + signAllPublications() + pom { + name = "PinIn" + description = "Library for solving Chinese pinyin matching problems" + url = "https://github.com/ghostflyby/PinIn" + licenses { + license { + name = "MIT License" + url = "https://spdx.org/licenses/MIT.html" + } + } + developers { + developer { + id = "ghostflyby" + email = "ghostflyby+maven@outlook.com" + } + } + scm { + url = "https://github.com/ghostflyby/PinIn.git" + tag = "v$version" + } + } +} From fabd5624c6e636fe4224281ecf81d357f171f884 Mon Sep 17 00:00:00 2001 From: ghostflyby Date: Tue, 30 Sep 2025 14:35:13 +0800 Subject: [PATCH 2/2] ci: fix release command to include notes file --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc5fb39..eb8d13b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,5 +70,5 @@ jobs: gh release create $VERSION \ --draft \ - --title $VERSION + --title $VERSION \ --notes-file $RELEASE_NOTE \ No newline at end of file