diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 0000000..f05c529 --- /dev/null +++ b/.github/workflows/README.md @@ -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)完全兼容。 \ No newline at end of file diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml new file mode 100644 index 0000000..8797393 --- /dev/null +++ b/.github/workflows/auto-release.yml @@ -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 }} \ No newline at end of file diff --git a/package.json b/package.json index 1a97a8b..4383501 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "miao-blog", "private": true, + "version": "1.1.0", "type": "module", "scripts": { "build": "nuxt build && bash ./aftBuild.sh",