Skip to content

chore(main): release 1.0.3 (#24) #18

chore(main): release 1.0.3 (#24)

chore(main): release 1.0.3 (#24) #18

name: Release on Commit
on:
push:
branches:
- main
workflow_dispatch: # 允许手动触发
jobs:
build:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]' && github.actor != 'dependabot[bot]'
steps:
- name: 拉取代码
uses: actions/checkout@v4
- name: 打印 github.actor
run: |
echo "ACTOR=${{ github.actor }}" >> $GITHUB_ENV
echo "Triggered by: $ACTOR"
- name: 安装node
uses: actions/setup-node@v4
with:
node-version: 21
registry-url: "https://registry.npmjs.org"
- name: 安装pnpm
uses: pnpm/action-setup@v2
with:
version: 9.7.1
- name: 安装依赖
run: |
pnpm install
pnpm add node-karin@latest
- name: 放弃 package.json 的本地更改
run: |
git checkout HEAD package.json
- name: 删除 pnpm-lock.yaml
run: rm -rf pnpm-lock.yaml
- name: 编译
run: pnpm build
- name: 获取当前提交哈希
run: echo "COMMIT_HASH=${{ github.sha }}" >> $GITHUB_ENV
id: get_commit_hash
- name: 获取短哈希值
run: echo "SHORT_COMMIT_HASH=$(echo ${{ env.COMMIT_HASH }} | cut -c1-7)" >> $GITHUB_ENV
- name: 创建临时文件夹存储编译后的lib文件夹和resources文件夹
run: |
mkdir ./../temp
- name: 复制编译后的lib文件夹和resources文件夹到临时文件夹
run: |
cp -r ./lib ./../temp/lib
cp -r ./resources ./../temp/resources
- name: 检查并创建空的 build 分支
run: |
git fetch origin
# 检查 build 分支是否存在
if git show-ref --verify --quiet refs/heads/build; then
echo "Build branch exists locally. Switching to it."
git checkout build
else
# 检查远程是否有 build 分支
if git ls-remote --exit-code --heads origin build; then
echo "Build branch exists remotely. Fetching and switching to it."
git checkout build
else
# build 分支不存在,创建一个空的 build 分支
echo "Build branch does not exist. Creating an empty build branch."
git checkout --orphan build # 创建一个没有历史记录的空分支
git reset --hard # 重置所有文件
git clean -fdx # 删除未被 Git 管理的文件和文件夹
echo "Empty build branch created."
git commit --allow-empty -m "Initial empty commit on build branch"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} build # 推送到远程仓库
fi
fi
- name: 切换到 build 分支
run: |
git fetch origin build
git checkout build
- name: 删除build分支上的lib文件夹和resources文件夹
run: |
rm -rf lib
rm -rf resources
- name: 复制编译后的lib文件夹和resources文件夹到 build 分支
run: |
cp -r ./../temp/lib ./
cp -r ./../temp/resources ./
- name: 删除临时文件夹
run: |
rm -rf ./../temp
- name: 从main分支复制文件到build分支
run: |
git checkout main -- package.json CHANGELOG.md README.md config resources LICENSE
- name: 修订版本号
run: npm run commit all
if: success()
- name: 删除依赖文件夹 node_modules
run: |
rm -rf node_modules
- name: 将文件整理到 karin-plugin-kkk 文件夹
run: |
mkdir -p karin-plugin-kkk
find . -path "./.git" -prune -o -type f -print | while read file; do
mkdir -p "karin-plugin-kkk/$(dirname "$file")"
cp "$file" "karin-plugin-kkk/$file"
done
- name: 创建 build.zip
run: zip -r "build-${{ env.SHORT_COMMIT_HASH }}.zip" karin-plugin-kkk
- name: 上传 build.zip
uses: actions/upload-artifact@v4
with:
name: "build-${{ env.SHORT_COMMIT_HASH }}.zip"
path: "build-${{ env.SHORT_COMMIT_HASH }}.zip"
- name: 删除 karin-plugin-kkk 文件夹
run: rm -rf karin-plugin-kkk
- name: 发布到 npm
run: npm run pub-beta
if: success()
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: 创建发行版
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "${{ env.PKG_VERSION }}"
release_name: "${{ env.PKG_VERSION }}"
body: |
### 🎉 构建完成!
- 此版本是基于快照 [`${{ env.SHORT_COMMIT_HASH }}`](https://github.com/${{ github.repository }}/tree/${{ env.COMMIT_HASH }}) 所构建的,[**点击此处查看更改**](https://github.com/${{ github.repository }}/commit/${{ env.COMMIT_HASH }}) By @${{ github.actor }}
### 安装该版本
**以下安装方式任选其一**
---
<details>
<summary>使用Git</summary>
**插件根目录** 下执行
```sh
git pull
```
```sh
git checkout ${{ env.COMMIT_HASH }}
```
若报错缺失依赖,可先运行 `pnpm install` 安装或更新依赖。
</details>
<details>
<summary>使用包管理器</summary>
**Karin 根目录** 下执行
```sh
pnpm add karin-plugin-kkk@${{ env.PKG_VERSION }} -w
```
</details>
<details>
<summary>使用预发行版(不推荐)</summary>
1. 下载名为 [build-${{ env.SHORT_COMMIT_HASH }}.zip](https://github.com/${{ github.repository }}/releases/download/pre-${{ env.SHORT_COMMIT_HASH }}/build-${{ env.SHORT_COMMIT_HASH }}.zip) 的压缩包
2. 在 `karin/plugins/` 目录下解压该压缩包,选择替换所有文件。
3. 完成后相关源码应在 `Karin根目录/plugins/karin-plugin-kkk/` 内<br><br>
若报错缺失依赖,可先运行 `pnpm install` 安装或更新依赖。
</details>
---
**此版本非正式版本,可能存在一些问题,请谨慎使用!**
构建时间:${{ github.event.head_commit.timestamp }}
draft: false
prerelease: true
- name: 上传
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: "./build-${{ env.SHORT_COMMIT_HASH }}.zip"
asset_name: "build-${{ env.SHORT_COMMIT_HASH }}.zip"
asset_content_type: application/zip