Skip to content

Commit

Permalink
chore(workflow): add auto tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonic853 committed Nov 10, 2022
1 parent ea1d1c2 commit 0359a03
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/AutoWriteVersion/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 读取 package.json
import pkg from "../../../package.json" assert { type: "json" };

// 读取 version.txt
let version = await Deno.readTextFile("../version.txt");
if (version === pkg.version) {
console.log("版本号一致,无需更新");
Deno.exit(0);
}
const oldVersion = version;

// 写入 version.txt
version = pkg.version;
await Deno.writeTextFile("../version.txt", version);

// 替换 replaceList 中的版本号
const replaceList = [
"../../../README.md"
]

for (const file of replaceList) {
let readme = await Deno.readTextFile(file);
readme = readme.replaceAll(oldVersion, version);
await Deno.writeTextFile(file, readme);
}

// 创建 needUpdate.txt
// await Deno.writeTextFile("../needUpdate.txt", version);
1 change: 1 addition & 0 deletions .github/AutoWriteVersion/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.3.0
51 changes: 51 additions & 0 deletions .github/workflows/autotag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 自动标注 Tag
name: Auto Tag

on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:

jobs:
update:
name: Auto Tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Get current version
id: current_version
run: echo "version=$(cat .github/AutoWriteVersion/version.txt)" >> $GITHUB_OUTPUT
- name: Check Version
id: check_version
run: |
cd .github/AutoWriteVersion/src/
deno run --allow-read --allow-write main.ts
- name: Get new version
id: new_version
run: echo "version=$(cat .github/AutoWriteVersion/version.txt)" >> $GITHUB_OUTPUT
- name: Check Version
if: steps.check_version.outputs.version != steps.current_version.outputs.version
run: |
echo "New Version: ${{ steps.new_version.outputs.version }}"
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GH_GPG }}
passphrase: ''
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_tag_gpgsign: true
- name: Commit and Set Tag
run: |
git add .
git commit -m "chore(workflow): update version to ${{ steps.new_version.outputs.version }}"
git tag -a ${{ steps.new_version.outputs.version }} -m "chore(workflow): update version to ${{ steps.new_version.outputs.version }}"
git push --follow-tags
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.sonic853.upm-github-manager",
"displayName": "UPM Github Manager",
"version": "0.3.0",
"version": "0.3.1",
"unity": "2019.4",
"description": "Manage, switch and upgrade Github package and Gitee package versions",
"dependencies": {
Expand Down

0 comments on commit 0359a03

Please sign in to comment.