Skip to content

Commit

Permalink
使用DevOps Release插件,优化发布流程 (#216)
Browse files Browse the repository at this point in the history
* feat: 使用DevOps Release插件,优化发布流程 #215
  • Loading branch information
felixncheng authored Jul 29, 2024
1 parent 5547bf5 commit a446df1
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 92 deletions.
95 changes: 15 additions & 80 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
- 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 "[email protected]"
- 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 -
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
8 changes: 0 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "[email protected]"
- 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
Expand Down
6 changes: 6 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
}
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion devops-boot-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
21 changes: 20 additions & 1 deletion docs/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ devops-framework/
└── docs # 项目文档
```

### 分支管理
项目采用主干开发模式,主要包含以下几种分支:

* master 主干开发分支
* release-* 已发布的版本分支
* ... 其他特性分支,如jdk17

## How to publish to maven repository?

### 发布命令
Expand Down Expand Up @@ -42,11 +49,23 @@ 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`
- `secrets.SONATYPE_PASSWORD`
- `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-*发布。
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.10-SNAPSHOT

0 comments on commit a446df1

Please sign in to comment.