更新 SDK 版本到 1.1.2 #37
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Build | |
| on: | |
| push: | |
| branches: | |
| - master | |
| paths: | |
| - 'pom.xml' # 仅当 pom.xml 改动时触发 | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 拉取完整历史记录 | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| # 设置 JDK 1.8 | |
| - name: Set up JDK 1.8 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '8' | |
| server-id: central | |
| server-username: SERVER_USERNAME | |
| server-password: SERVER_PASSWORD | |
| gpg-private-key: ${{ secrets.GPG_SECRET }} | |
| gpg-passphrase: GPG_PASSPHRASE | |
| # 获取当前版本号 | |
| - name: Get current project version | |
| id: version | |
| run: | | |
| VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | |
| echo "PROJECT_VERSION=$VERSION" >> $GITHUB_ENV | |
| echo "📦 Detected version: $VERSION" | |
| # 获取上一个版本 tag(按时间排序) | |
| - name: Get previous tag | |
| id: prev_tag | |
| run: | | |
| PREV_TAG=$(git tag --sort=-creatordate | grep '^v' | head -n 1 || echo "") | |
| echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV | |
| echo "Last version tag: $PREV_TAG" | |
| # 检查版本是否递增(严格语义化版本比较) | |
| - name: Verify version increment | |
| if: env.PREV_TAG != '' | |
| run: | | |
| PREV_VER=${PREV_TAG#v} | |
| NEW_VER=${PROJECT_VERSION} | |
| # 解析 version | |
| parse() { | |
| IFS='.' read -r major minor patch <<< "$1" | |
| echo "$major" "$minor" "$patch" | |
| } | |
| read p_major p_minor p_patch <<< "$(parse "$PREV_VER")" | |
| read n_major n_minor n_patch <<< "$(parse "$NEW_VER")" | |
| echo "🔍 Comparing $PREV_VER → $NEW_VER" | |
| # 判断是否相等 | |
| if (( n_major == p_major && n_minor == p_minor && n_patch == p_patch )); then | |
| echo "⚠️ Version unchanged ($NEW_VER), skipping release." | |
| exit 0 | |
| fi | |
| # 判断是否降级 | |
| if (( n_major < p_major )) \ | |
| || (( n_major == p_major && n_minor < p_minor )) \ | |
| || (( n_major == p_major && n_minor == p_minor && n_patch < p_patch )); then | |
| echo "❌ Version appears to be lower than previous ($PREV_VER → $NEW_VER)." | |
| exit 1 | |
| fi | |
| echo "✅ Version increment confirmed" | |
| # 检查该 tag 是否已存在(避免重复推送) | |
| - name: Check if tag exists | |
| id: check_tag | |
| run: | | |
| if git rev-parse "v${PROJECT_VERSION}" >/dev/null 2>&1; then | |
| echo "exists=true" >> $GITHUB_ENV | |
| echo "⚠️ Tag v${PROJECT_VERSION} already exists. Skipping release." | |
| else | |
| echo "exists=false" >> $GITHUB_ENV | |
| fi | |
| # 创建并推送新 tag | |
| - name: Create and push tag | |
| if: env.exists == 'false' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag "v${PROJECT_VERSION}" | |
| git push origin "v${PROJECT_VERSION}" | |
| echo "🏷️ Created tag v${PROJECT_VERSION}" | |
| # 生成 Release Note(自动汇总 commit) | |
| - name: Generate release notes | |
| id: notes | |
| run: | | |
| if [ -z "${PREV_TAG}" ]; then | |
| NOTES=$(git log --pretty=format:"- %s" -n 20) | |
| else | |
| NOTES=$(git log ${PREV_TAG}..HEAD --pretty=format:"- %s") | |
| fi | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| echo "$NOTES" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| echo "📝 Generated release notes:" | |
| echo "$NOTES" | |
| # 构建项目 | |
| - name: Build with Maven | |
| run: mvn clean package -DskipTests | |
| # 发布到 Apache Maven Central | |
| - name: Publish to Apache Maven Central | |
| run: mvn deploy -Dmaven.test.skip=true | |
| env: | |
| SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }} | |
| SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSWORD }} | |
| # 创建 GitHub Release | |
| - name: Create GitHub Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ env.PROJECT_VERSION }} | |
| release_name: Release v${{ env.PROJECT_VERSION }} | |
| body: ${{ env.RELEASE_NOTES }} | |
| draft: false | |
| prerelease: false | |
| # 上传 JAR 到 Release | |
| - name: Upload JAR to Release | |
| uses: actions/upload-release-asset@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| asset_path: target/sdk-${{ env.PROJECT_VERSION }}.jar | |
| asset_name: sdk-${{ env.PROJECT_VERSION }}.jar | |
| asset_content_type: application/java-archive |