Skip to content

Commit e35e288

Browse files
committed
ci(update-version): add new workflow
1 parent 3aa1184 commit e35e288

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

.github/workflows/update-version.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Update Version in README
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: write
10+
jobs:
11+
update-version:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Check out repository code
15+
uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Set up Git config
20+
run: |
21+
git config user.name "github-actions[bot]"
22+
git config user.email "github-actions[bot]@users.noreply.github.com"
23+
24+
- name: Extract version from tag
25+
id: get_version
26+
run: |
27+
# 例如如果 Tag 是 'v0.1.2',会去掉 'v' 前缀,得到 '0.1.2'
28+
VERSION=${GITHUB_REF##*/}
29+
VERSION=${VERSION#v}
30+
echo "version=$VERSION" >> $GITHUB_OUTPUT
31+
32+
- name: Switch to master
33+
run: git switch master
34+
35+
- name: Update version in README
36+
run: |
37+
# 这里演示两处替换:Gradle 和 Maven 片段的版本号。
38+
# 你可以把下面的 '0.0.5' 改成你的旧版本号的正则匹配模式。
39+
# 或者,如果不确定旧版本号,每次可以直接根据周边文字做精确匹配。
40+
41+
# 替换 Gradle 示例中的版本号 executables-all:0.0.5
42+
sed -i "s|\(kotlinx-serialization-bencoding:\)[0-9]\+\.[0-9]\+\.[0-9]\+|\1${{ steps.get_version.outputs.version }}|g" README.md
43+
44+
45+
- name: Commit changes
46+
run: |
47+
if [ -n "$(git status --porcelain)" ]; then
48+
git add README.md
49+
git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
50+
git push
51+
else
52+
echo "No changes to commit."
53+
fi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Add the dependency to your `build.gradle.kts`
1414

1515
```kotlin
1616
dependencies {
17-
implementation("space.iseki.bencoding:kotlinx-serialization-bencoding:0.2.+")
17+
implementation("space.iseki.bencoding:kotlinx-serialization-bencoding:0.2.7")
1818
}
1919
```
2020

0 commit comments

Comments
 (0)