Skip to content

Commit

Permalink
Merge branch 'master' into jdk17
Browse files Browse the repository at this point in the history
# Conflicts:
#	buildSrc/src/main/kotlin/Versions.kt
#	devops-boot-sample/build.gradle.kts
  • Loading branch information
stubenhuang committed Aug 27, 2024
2 parents bd43daf + 57f2194 commit 58bcd6d
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 101 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 @@ -32,3 +33,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.1.0-SNAPSHOT"
val Version = File("version.txt").readText().trim()
}

object Versions {
Expand All @@ -12,4 +14,5 @@ object Versions {
const val DependencyManagement = "1.1.6"
const val GradleNexusPublish = "1.3.0"
const val KtLint = "0.50.0"
const val DevopsReleasePlugin = "0.0.9"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import request from '@/utils/request'

function encodeBase64(data) {
data.source = btoa(data.source)
return data
}

function decodeBase64(res) {
for (const item of res.data.records) {
item.source = atob(item.source)
}
return res
}

export const list = (data) => request({
url: '/job/list',
method: 'get',
params: data
})
}).then(res => decodeBase64(res))

export const create = (data) => request({
url: '/job/create',
method: 'post',
data: data
data: encodeBase64(data)
})

export const update = (id, data) => request({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ export default (safe) => {
},
{
label: '调度类型',
prop: 'scheduleType',
prop: 'scheduleType1', // 这里字段名不能跟下面的scheduleType重复,不然下面框的控制会失效
dicUrl: '/dict/ScheduleType',
props: {
value: 'scheduleType'
},
display: false
},
{
Expand Down Expand Up @@ -146,6 +149,7 @@ export default (safe) => {
label: 'Cron表达式',
display: true,
type: 'input',
placeholder: '请输入Cron表达式',
value: '',
rules: [{
required: true,
Expand All @@ -164,7 +168,8 @@ export default (safe) => {
},
{
label: '调度配置',
prop: 'scheduleConf'
prop: 'scheduleConf',
display: false
}
]
},
Expand All @@ -178,6 +183,45 @@ export default (safe) => {
type: 'select',
value: 1,
dicUrl: '/dict/JobMode',
control: (val, form) => {
if (val === 1) {
return {
image: {
display: false
},
jobHandler: {
display: true
},
source: {
display: false
},
}
} else if (val === 2) {
return {
image: {
display: false
},
jobHandler: {
display: false
},
source: {
display: true
},
}
} else if (val === 3) {
return {
image: {
display: true
},
jobHandler: {
display: false
},
source: {
display: true
},
}
}
},
rules: [{
required: true,
message: '请选择运行模式',
Expand All @@ -188,12 +232,32 @@ export default (safe) => {
label: 'jobHandler',
prop: 'jobHandler',
type: 'input',
display: false,
rules: [{
required: true,
message: '请输入job handler',
trigger: 'blur'
}]
},
{
label: '镜像',
prop: 'image',
type: 'input',
display: false,
rules: [{
message: '请输入镜像',
trigger: 'blur'
}]
},
{
label: '资源',
prop: 'source',
type: 'textarea',
display: false,
placeholder: '请输入资源',
maxlength: 10240,
showWordLimit: true,
span: 24
},
{
label: '任务参数',
prop: 'jobParam',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# devops-release-gradle-plugin

## 功能介绍
`devops-release-gradle-plugin`是一个用于自动化发布的一个插件,帮助我们管理项目版本,简化发布流程,自动
完成以下内容:
`devops-release-gradle-plugin`是一个用于自动化发布的一个插件,帮助我们管理项目版本,简化发布流程,自动完成以下内容:

- 检查是否有未提交的内容
- 去掉-SNAPSHOT,生成发布版本号
Expand All @@ -25,7 +24,7 @@

```groovy
plugins {
id("devops-release-gradle-plugin") version ${version}
id("com.tencent.devops.release") version ${version}
}
version = file("version.txt").readText().trim()
Expand All @@ -39,8 +38,9 @@ gradle release

## 配置插件

默认是根据version.txt文件,自动生成发布版本,并根据SemVer,增加MINOR,生成下一个开发版本,标签则是在发布版本
前增加v。可以使用gradle preview,预览发布插件自动生成的信息。
默认是根据version.txt文件,自动生成发布版本,并根据SemVer,增加MINOR,生成下一个开发版本,标签则是在发布版本前增加v。

可以使用gradle generateReleaseProperties,预览发布插件自动生成的信息。

所以我们只需添加如下配置:

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.1.0-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.1.0-SNAPSHOT

0 comments on commit 58bcd6d

Please sign in to comment.