feat: 添加对于github action自动构建的支持
This commit is contained in:
1 parent
9f8dfe3893
commit
72a20a3825
3 files changed
+109
No files matched your search
@@ -0,0 +1,29 @@
|
|||||||
|
# 自动发布GitHub Action
|
||||||
|
|
||||||
|
这个GitHub Action工作流会在每次推送代码到`main`分支时自动创建一个新的发布版本,使用Debian 12环境进行构建。
|
||||||
|
|
||||||
|
## 工作流程
|
||||||
|
|
||||||
|
1. 当代码推送到`main`分支时,工作流自动触发
|
||||||
|
2. 使用Debian 12容器作为构建环境
|
||||||
|
3. 安装必要的系统依赖(git、curl、nodejs等)
|
||||||
|
4. 检出代码并设置Node.js和PNPM环境
|
||||||
|
5. 安装项目依赖并构建项目
|
||||||
|
6. 将构建输出(.output目录)打包为output.tar.gz
|
||||||
|
7. 从package.json中获取版本号
|
||||||
|
8. 计算提交次数并将其添加到版本号中
|
||||||
|
9. 生成更新日志(从上一个标签到当前提交的所有变更)
|
||||||
|
10. 创建GitHub Release,包括:
|
||||||
|
- 版本标签(格式:v版本号.提交次数,例如v0.1.0.42)
|
||||||
|
- 自动生成的更新日志
|
||||||
|
- 构建输出压缩包(output.tar.gz)
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
无需手动操作,只需将代码推送到`main`分支,GitHub Action将自动执行并创建新的发布版本。
|
||||||
|
|
||||||
|
如果需要更改发布版本号,请修改`package.json`文件中的`version`字段。
|
||||||
|
|
||||||
|
## 环境兼容性
|
||||||
|
|
||||||
|
构建过程在Debian 12环境中进行,确保生成的输出文件与目标部署环境(Debian 12)完全兼容。
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
name: Auto Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: debian:12
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Install dependencies for Git and Node.js
|
||||||
|
run: |
|
||||||
|
apt-get update
|
||||||
|
apt-get install -y git curl wget nodejs npm tar gzip
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 'lts/*'
|
||||||
|
|
||||||
|
- name: Setup PNPM
|
||||||
|
uses: pnpm/action-setup@v2
|
||||||
|
with:
|
||||||
|
version: 9
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: pnpm install
|
||||||
|
|
||||||
|
- name: Build project
|
||||||
|
run: pnpm build
|
||||||
|
|
||||||
|
- name: Create output.tar.gz
|
||||||
|
run: tar -czvf output.tar.gz .output/
|
||||||
|
|
||||||
|
- name: Get version from package.json
|
||||||
|
id: package-version
|
||||||
|
run: echo "VERSION=$(node -p "require('./package.json').version || '0.1.0'")" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Get commit count
|
||||||
|
id: commit-count
|
||||||
|
run: echo "COUNT=$(git rev-list --count HEAD)" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create release version
|
||||||
|
id: release-version
|
||||||
|
run: echo "RELEASE_VERSION=v${{ env.VERSION }}.${{ env.COUNT }}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
run: |
|
||||||
|
PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||||
|
if [ -z "$PREVIOUS_TAG" ]; then
|
||||||
|
git log --pretty=format:"* %s (%h)" > CHANGELOG.md
|
||||||
|
else
|
||||||
|
git log ${PREVIOUS_TAG}..HEAD --pretty=format:"* %s (%h)" > CHANGELOG.md
|
||||||
|
fi
|
||||||
|
echo "CHANGELOG_PATH=CHANGELOG.md" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Create GitHub Release
|
||||||
|
uses: softprops/action-gh-release@v1
|
||||||
|
with:
|
||||||
|
tag_name: ${{ env.RELEASE_VERSION }}
|
||||||
|
name: Release ${{ env.RELEASE_VERSION }}
|
||||||
|
body_path: ${{ env.CHANGELOG_PATH }}
|
||||||
|
draft: false
|
||||||
|
prerelease: false
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
files: |
|
||||||
|
output.tar.gz
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "miao-blog",
|
"name": "miao-blog",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"version": "1.1.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "nuxt build && bash ./aftBuild.sh",
|
"build": "nuxt build && bash ./aftBuild.sh",
|
||||||
|
|||||||
Reference in new issue
Block a user