Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add Auto Release #770

Merged
merged 5 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Auto Release

on:
pull_request:
branches: [develop]
types: [opened, synchronize, reopened, closed]
paths:
- package.json
issue_comment:
types: [edited]

jobs:
generator:
runs-on: ubuntu-latest
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.merged == false &&
startsWith(github.head_ref, 'release/')
steps:
- run: echo "The head of this PR starts with 'release/'"
- uses: actions/checkout@v4
- uses: TDesignOteam/tdesign-tag-action@main
id: tag-action
with:
token: ${{ secrets.GITHUB_TOKEN }}
- uses: TDesignOteam/tdesign-changelog-action@main
id: changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag: ${{ steps.tag-action.outputs.version }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
${{ steps.changelog.outputs.changelog }}
comment_add_log:
runs-on: ubuntu-latest
if: >
github.event_name == 'issue_comment'
&& github.event.issue.pull_request
&& github.event.sender.login == github.event.issue.user.login
&& startsWith(github.event.comment.body, '## 🌈 ')
steps:
- id: comment
shell: bash
run: |
result=$(curl ${{github.event.issue.pull_request.url}} -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}")
headrefreg='"ref": "(release/[[:digit:]]{1,2}\.[[:digit:]]{1,2}\.[[:digit:]]{1,2})",'
if [[ $result =~ $headrefreg ]]
then
echo "属于 release pr 的 comment ${BASH_REMATCH[1]}"
else
echo "不属于 release pr 的 comment" && exit 1
fi
echo "::set-output name=branch::${BASH_REMATCH[1]}"
# zsh $match[1]
- uses: actions/checkout@v4
with:
ref: ${{ steps.comment.outputs.branch }}
- name: Commit and push if needed
env:
BODY: ${{ github.event.comment.body }}
run: |
txt=$(cat CHANGELOG.md)
echo "${txt%%##*}$BODY${txt##*---}" > CHANGELOG.md
git add .
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "chore: changelog's changes"
git push
echo "💾 pushed changelog's changes"
merge_tag:
runs-on: ubuntu-latest
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
startsWith(github.head_ref, 'release/')
steps:
- uses: actions/checkout@v4
with:
ref: develop
token: ${{ secrets.PERSONAL_TOKEN }}
- uses: TDesignOteam/tdesign-tag-action@main
id: tag-action
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: tag and push if needed
run: |
echo "${{ steps.tag-action.outputs.version }}"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git tag ${{ steps.tag-action.outputs.version }}
git push origin ${{ steps.tag-action.outputs.version }}
echo "pushed tag ${{ steps.tag-action.outputs.version }}"
24 changes: 24 additions & 0 deletions .github/workflows/tag-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 文件名建议统一为 tag-push.yml
# 应用 publish.yml 的 demo

name: TAG_PUSH

on: create

jobs:
TAG_PUSH:
runs-on: ubuntu-latest
if: github.event.ref_type == 'tag'
steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
token: ${{ secrets.PERSONAL_TOKEN }}
- run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git status
git fetch origin
git merge origin/develop
git push origin main
9 changes: 9 additions & 0 deletions PUBLISH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 版本发布流程

## 发布流程

- 从 `develop` 新建 `release/x.y.z` 分支,并修改 `package.json` 中的版本号,推送分支至远程仓库,并提交一个合入`develop`的 Pull Request 到仓库
- 仓库的 Github Action 会自动整理上个版本至今 commit 对应的 CHANGELOG,并将 CHANGELOG 的 draft 作为一个评论推送到该 Pull Request 上
- 发布人检查 CHANGELOG,并优化内容逻辑结构,确认无误后删除对于评论首行提示,Github Action 会将优化后的内容写入 CHANGELOG.md 内
- 确认无误后,合并分支入`develop`
合入 `develop` 后,仓库会触发 Github Action 合入 `main` 分支,并将版本号作为 `tag` 打在仓库上
Loading