diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index dc6b0b0..40d2cac 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -2,98 +2,33 @@ name: Create release branch on: workflow_dispatch: - inputs: - next_version: - description: "Next development version (ie 1.1.0),hotfix use '-'" - required: true jobs: - prepare-create: + create-release: runs-on: ubuntu-latest - outputs: - RELEASE_VERSION: ${{ steps.get-version.outputs.RELEASE_VERSION }} - VERSION_FILE: ${{ steps.get-version.outputs.VERSION_FILE }} + env: + RELEASE_VERSION: ${{ github.event.inputs.release_version }} + NEXT_VERSION: ${{ github.event.inputs.next_version }} steps: - - name: check branch + - name: Check branch if: github.ref_name != 'master' && startsWith(github.ref_name,'hotfix-') != true run: | echo "Create release branch can only from master or hotfix-** branch" exit 1 - uses: actions/checkout@v2 - - name: Get version - id: get-version - run: | - version_file=buildSrc/src/main/kotlin/Versions.kt - version=$(awk '/Version =/ {print $5}' $version_file |sed 's/\"//g' |sed 's/-SNAPSHOT//g') - echo "RELEASE_VERSION=$version" >> $GITHUB_OUTPUT - echo "VERSION_FILE=$version_file" >> $GITHUB_OUTPUT - create-release: - runs-on: ubuntu-latest - needs: prepare-create - env: - RELEASE_VERSION: ${{ needs.prepare-create.outputs.RELEASE_VERSION }} - VERSION_FILE: ${{ needs.prepare-create.outputs.VERSION_FILE }} - steps: - - uses: actions/checkout@v2 - name: Setup git configuration run: | git config user.name "bkci-bot" git config user.email "64278246+bkci-bot@users.noreply.github.com" - - name: Create release branch - run: git checkout -b release-${{ env.RELEASE_VERSION }} - - name: Version Bump + - name: Release run: | - sed -i 's/${{ env.RELEASE_VERSION }}-SNAPSHOT/${{ env.RELEASE_VERSION }}/g' ${{ env.VERSION_FILE }} - - name: Commit version file -- release branch - run: | - git add ${{ env.VERSION_FILE }} - git commit --message "Prepare release ${{ env.RELEASE_VERSION }}" + ./gradlew generateReleaseProperties + ./gradlew release - name: Push new release branch - run: git push origin release-${{ env.RELEASE_VERSION }} - create-develop: - runs-on: ubuntu-latest - needs: prepare-create - if: github.event.inputs.next_version != '-' - env: - RELEASE_VERSION: ${{ needs.prepare-create.outputs.RELEASE_VERSION }} - NEXT_VERSION: ${{ github.event.inputs.next_version }} - VERSION_FILE: ${{ needs.prepare-create.outputs.VERSION_FILE }} - steps: - - uses: actions/checkout@v2 - with: - ref: master - - name: Setup git configuration - run: | - git config user.name "bkci-bot" - git config user.email "64278246+bkci-bot@users.noreply.github.com" - - name: Create develop branch - run: git checkout -b develop-${{ env.NEXT_VERSION }} - - name: Version Bump - id: version-bump - run: | - sed -i 's/${{ env.RELEASE_VERSION }}/${{ env.NEXT_VERSION }}/g' ${{ env.VERSION_FILE }} - sample_version_file=devops-boot-sample/build.gradle.kts - sed -i 's/${{ env.RELEASE_VERSION }}/${{ env.NEXT_VERSION }}/g' $sample_version_file - echo "::set-output name=SAMPLE_VERSION_FILE::$sample_version_file" - - name: Commit version file -- develop branch - id: commit-version-file-master - run: | - git add ${{ env.VERSION_FILE }} - git add ${{ steps.version-bump.outputs.SAMPLE_VERSION_FILE }} - git commit --message "Prepare for next development iteration ${{ env.NEXT_VERSION }}" - echo "::set-output name=commit::$(git rev-parse HEAD)" - - name: Push new develop branch - run: git push origin develop-${{ env.NEXT_VERSION }} - - name: Create pull request into master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - ./.github/scripts/create_pr_body.sh \ - ${{ github.actor }} \ - ${{ github.repository }} \ - ${{ github.run_id }} \ - ${{ steps.commit-version-file-master.outputs.commit }} | \ - gh pr create -B master -H develop-${{ env.NEXT_VERSION }} \ - --title 'Update version ${{ env.NEXT_VERSION }}-SNAPSHOT' \ - --reviewer ${{ github.actor }} \ - --body-file - \ No newline at end of file + run: | + version=$(grep "release.version=" release.properties | awk -F "=" '{print $2}') + release_branch=release-$version + echo "version=$version" + echo "branch_name=$release_branch" + git checkout -b $release_branch v$version + git push origin $release_branch \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c8254f..a5f11cb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,14 +35,6 @@ jobs: ${{ env.RELEASE_VERSION }} \ /generated-changelog/changelog.md echo "::set-output name=changelog_path::$CONFIG_DIR/changelog.md" - - name: Setup git configuration - run: | - git config user.name "bkci-bot" - git config user.email "64278246+bkci-bot@users.noreply.github.com" - - name: Create tag - run: git tag v${{ env.RELEASE_VERSION }} -m "Release v${{ env.RELEASE_VERSION }}" - - name: Push git tag - run: git push origin v${{ env.RELEASE_VERSION }} - name: Create Release id: create_release uses: actions/create-release@v1 diff --git a/build.gradle.kts b/build.gradle.kts index fb5cf5e..8e29fe4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,6 +8,7 @@ plugins { kotlin("plugin.spring") version Versions.Kotlin apply false id("io.spring.dependency-management") version Versions.DependencyManagement apply false id("io.github.gradle-nexus.publish-plugin") version Versions.GradleNexusPublish + id("com.tencent.devops.release") version Versions.DevopsReleasePlugin } allprojects { @@ -33,3 +34,8 @@ nexusPublishing { subprojects { apply(plugin = "ktlint") } + +release { + scmUrl.set("scm:git:https://github.com/bkdevops-projects/devops-framework.git") + incrementPolicy.set("PATCH") +} diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index d30c5a4..cbe4ac5 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,6 +1,8 @@ +import java.io.File + object Release { const val Group = "com.tencent.devops" - const val Version = "0.0.10-SNAPSHOT" + val Version = File("version.txt").readText().trim() } object Versions { @@ -12,4 +14,5 @@ object Versions { const val DependencyManagement = "1.0.15.RELEASE" const val GradleNexusPublish = "1.3.0" const val KtLint = "0.41.0" + const val DevopsReleasePlugin = "0.0.9" } diff --git a/devops-boot-project/devops-boot-tools/devops-release-gradle-plugin/README.md b/devops-boot-project/devops-boot-tools/devops-release-gradle-plugin/README.md index a305f00..487d579 100644 --- a/devops-boot-project/devops-boot-tools/devops-release-gradle-plugin/README.md +++ b/devops-boot-project/devops-boot-tools/devops-release-gradle-plugin/README.md @@ -25,7 +25,7 @@ ```groovy plugins { - id("devops-release-gradle-plugin") version ${version} + id("com.tencent.devops.release") version ${version} } version = file("version.txt").readText().trim() diff --git a/devops-boot-sample/build.gradle.kts b/devops-boot-sample/build.gradle.kts index 88da748..5cafa95 100644 --- a/devops-boot-sample/build.gradle.kts +++ b/devops-boot-sample/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("com.tencent.devops.boot") version "0.0.10-SNAPSHOT" + id("com.tencent.devops.boot") version File("../version.txt").readText().trim() } allprojects { diff --git a/docs/contribute.md b/docs/contribute.md index e92b7a3..6691766 100644 --- a/docs/contribute.md +++ b/docs/contribute.md @@ -15,6 +15,13 @@ devops-framework/ └── docs # 项目文档 ``` +### 分支管理 +项目采用主干开发模式,主要包含以下几种分支: + +* master 主干开发分支 +* release-* 已发布的版本分支 +* ... 其他特性分支,如jdk17 + ## How to publish to maven repository? ### 发布命令 @@ -42,7 +49,7 @@ devops-framework/ - `ORG_GRADLE_PROJECT_signingKeyId` gpg签名key id - `ORG_GRADLE_PROJECT_signingPassword` gpg签名密码 -配合github流水线自动发布时, 项目中编写的github流水线[publish.yml](../.github/workflows/publish.yml) +配合github流水线自动发布时, 项目中编写的github流水线[release.yml](../.github/workflows/release.yml) 会自动读取以下`github secrets`并设置为对应的环境变量: - `secrets.SONATYPE_USERNAME` @@ -50,3 +57,15 @@ devops-framework/ - `secrets.SIGNING_KEY` - `secrets.SIGNING_KEY_ID` - `secrets.SIGNING_PASSWORD` + +### 项目发布管理 +项目采用语义化版本管理,同时通过github流水线进行自动化发布。自动化发布过程包括版本升级、创建发布分支、 +创建tag、创建github release、部署jar包等等 + +发布需要人工触发,分为以下两个步骤: +1. 创建发布分支 + + 运行`Create release branch` Action。创建发布分支只允许从master或者hotfix-*创建。 +2. 发布Jar包 + + 运行`Release` Action,选择要发布的发布分支release-*。发布只允许从release-*发布。 diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..b262a37 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.10-SNAPSHOT \ No newline at end of file