Commit d557c63e authored by liziwl's avatar liziwl
Browse files

chore(ci): update actions and document release process

parent 2cca66cd
Loading
Loading
Loading
Loading
+54 −33
Changes for .github/workflows/release.yml: 54 added lines, 33 removed lines.
Original line number Diff line number Diff line
env: {}

# FILE GENERATED WITH: npx ghat fregante/ghatemplates/action-release
# SOURCE: https://github.com/fregante/ghatemplates

@@ -12,6 +10,9 @@ on:
    tags:
      - v*

permissions:
  contents: read

jobs:
  build_latex:
    runs-on: ubuntu-latest
@@ -36,19 +37,16 @@ jobs:
          args: make dist-github

      - name: Archive Release
        uses: thedoctor0/zip-release@master
        with:
          filename: 'sustech-thesis-dev-build.zip'
          exclusions: '*.git* /*node_modules/* .editorconfig'
        run: zip -r sustech-thesis-dev-build.zip . -x '*.git*' '*/node_modules/*' '.editorconfig' 'sustech-thesis-dev-build.zip'

      - name: Upload release artifact
        uses: actions/upload-artifact@v4
        uses: actions/upload-artifact@v7
        with:
          name: 'sustech-thesis-dev-build'
          path: 'sustech-thesis-dev-build.zip'

      - name: Upload Pre-release artifact
        uses: actions/upload-artifact@v4
        uses: actions/upload-artifact@v7
        with:
          name: 'pre-release-artifacts_action_build'
          path: |
@@ -61,47 +59,70 @@ jobs:
    runs-on: "ubuntu-latest"
    needs: build_latex
    if: github.event_name == 'push'
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v4
      - uses: actions/download-artifact@v8
        name: Download artifact
      - uses: "marvinpinto/action-automatic-releases@latest"
        name: Auto pre-release
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          automatic_release_tag: "dev-latest"
          prerelease: true
          title: "Dev Build(预发布)"
          files: |
            pre-release-artifacts_action_build/sustechthesis.cls
            pre-release-artifacts_action_build/sustechthesis.pdf
            pre-release-artifacts_action_build/public-test/*.pdf
            sustech-thesis-dev-build/sustech-thesis-dev-build.zip

      - name: Publish pre-release
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
        run: |
          if gh release view dev-latest >/dev/null 2>&1; then
            gh release delete dev-latest --cleanup-tag --yes
          else
            gh api --method DELETE "repos/${GITHUB_REPOSITORY}/git/refs/tags/dev-latest" >/dev/null 2>&1 || true
          fi

          gh release create dev-latest \
            pre-release-artifacts_action_build/sustechthesis.cls \
            pre-release-artifacts_action_build/sustechthesis.pdf \
            pre-release-artifacts_action_build/public-test/*.pdf \
            sustech-thesis-dev-build/sustech-thesis-dev-build.zip \
            --target "${GITHUB_SHA}" \
            --title "Dev Build(预发布)" \
            --prerelease \
            --generate-notes

  release-tag:
    name: "Draft release by tag"
    runs-on: "ubuntu-latest"
    needs: build_latex
    if: startsWith(github.ref, 'refs/tags/v')
    permissions:
      contents: write
    steps:
      - uses: actions/download-artifact@v4
      - uses: actions/download-artifact@v8
        name: Download artifact

      - name: Get the version
        id: get_version
        run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
        run: echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"

      - name: Rename artifact
        run: cp sustech-thesis-dev-build/sustech-thesis-dev-build.zip sustech-thesis-dev-build/sustech-thesis-${{ steps.get_version.outputs.VERSION }}.zip
        run: cp sustech-thesis-dev-build/sustech-thesis-dev-build.zip sustech-thesis-dev-build/sustech-thesis-${{ steps.get_version.outputs.version }}.zip

      - uses: "marvinpinto/action-automatic-releases@latest"
        name: Upload release artifacts
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          draft: true
          automatic_release_tag: ${{ steps.get_version.outputs.VERSION }}
          title: ${{ steps.get_version.outputs.VERSION }}
          files: |
      - name: Create draft release
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
          VERSION: ${{ steps.get_version.outputs.version }}
        run: |
          assets=(
            pre-release-artifacts_action_build/sustechthesis.cls
            pre-release-artifacts_action_build/sustechthesis.pdf
            pre-release-artifacts_action_build/public-test/*.pdf
            sustech-thesis-dev-build/sustech-thesis-${{ steps.get_version.outputs.VERSION }}.zip
            "sustech-thesis-dev-build/sustech-thesis-${VERSION}.zip"
          )

          if gh release view "${VERSION}" >/dev/null 2>&1; then
            gh release upload "${VERSION}" "${assets[@]}" --clobber
            gh release edit "${VERSION}" --draft --title "${VERSION}"
          else
            gh release create "${VERSION}" "${assets[@]}" \
              --verify-tag \
              --draft \
              --title "${VERSION}" \
              --generate-notes
+1 −1
Changes for .github/workflows/verify-compile.yml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ jobs:
        run: make doc test

      - name: Publish PDF as actions assets
        uses: actions/upload-artifact@v4
        uses: actions/upload-artifact@v7
        with:
          name: Example-PDFs-texlive-${{ matrix.texlive }}
          path: |
+2 −1
Changes for CHANGELOG.md: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -39,10 +39,11 @@ Changelog 维护应保持最新版本在文件上面的原则,日期格式按
- 重构 README 结构,优化文档组织([#88](https://github.com/SUSTech-CRA/sustech-master-thesis/pull/88))。
- 完善 Windows 批处理脚本 `build.bat` 和 `clean.bat`,补充论文、报告和模板文档的构建与清理入口。
- 更新南科大 ShareLaTeX 的校内、校外访问地址。
- 升级 GitHub Actions,并将 CI 使用的 Python 更新至 3.12。
- 升级 GitHub Actions 和 artifact 组件,将 CI 使用的 Python 更新至 3.12,并使用原生命令替换第三方归档 Action 和依赖旧版 Node.js 的自动发布 Action。

### Added
- 完善 `font`、`cjk-font`、`math-font`、`type`、`degree-type` 等选项的文档,并扩充示例 PDF 和 LuaLaTeX 临时文件的忽略规则([#91](https://github.com/SUSTech-CRA/sustech-master-thesis/pull/91))。
- 添加正式版本发布流程文档 `RELEASE.md`。

### Fixed
- 修复批处理脚本 `build.bat` 和 `clean.bat` 在 PowerShell 中的解析兼容性问题。
+2 −0
Changes for README.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -146,6 +146,8 @@ xetex sustechthesis.ins

每个版本的详细更新日志,请见 [CHANGELOG.md](CHANGELOG.md)。模板使用说明(sustechthesis.pdf)中也包含了这一内容。

维护者发布正式版本时,请遵循 [RELEASE.md](RELEASE.md) 中的流程。

## 问题反馈

在遇到模板问题时,请按以下步骤排查:

RELEASE.md

0 → 100644
+142 −0
Changes for RELEASE.md: 142 added lines, 0 removed lines.
Original line number Diff line number Diff line
# 正式版本发布流程

本文档说明 SUSTechThesis 正式版本的准备、构建和发布流程。原流程记录于 [GitHub Issue #23](https://github.com/SUSTech-CRA/sustech-master-thesis/issues/23),后续以本文档为准。

## 1. 准备版本

确保位于 `master` 分支,且本地代码已经与远端同步:

```shell
git switch master
git pull --ff-only origin master
git status
```

查看当前最新版本:

```shell
git tag --sort=-version:refname
```

运行版本更新脚本。脚本默认从 `sustechthesis.dtx` 读取当前版本并递增补丁版本,同时更新其中三处版本元数据,并在 `CHANGELOG.md` 顶部生成新版本骨架:

```shell
python3 test/update-dist.py --date YYYY/MM/DD
```

Windows 如果没有 `python` 命令,可使用:

```powershell
py -3 test/update-dist.py --date YYYY/MM/DD
```

脚本只负责更新版本元数据和生成 changelog 骨架。必须人工整理 `CHANGELOG.md`:

- 将原有 `Unreleased` 内容归入新版本;
- 删除占位文字和重复的 `Unreleased` 标题;
- 保留一个指向新版本至 `HEAD` 的 `Unreleased` 比较链接;
- 按 `Added`、`Changed`、`Deprecated`、`Removed`、`Fixed`、`Security` 分类;
- 同一个 Pull Request 在同一版本中只保留一条记录;
- 确认版本日期使用 `YYYY-MM-DD` 格式。

版本标题格式如下:

```md
## [Unreleased](https://github.com/SUSTech-CRA/sustech-master-thesis/compare/vX.Y.Z...HEAD)

## [vX.Y.Z](https://github.com/SUSTech-CRA/sustech-master-thesis/compare/vA.B.C...vX.Y.Z) - YYYY-MM-DD
```

最后确认 `sustechthesis.dtx` 中三处版本号和日期一致:

```shell
rg -n "Southern University of Science and Technology Thesis Template|\\def\\version" sustechthesis.dtx
```

## 2. 本地验证

检查 diff 和空白错误:

```shell
git diff --check
git diff --stat
```

使用 TeX Live 执行与 CI 对应的构建和测试:

```shell
make doc test
```

如需同时生成发布归档,可运行:

```shell
make dist-github
```

## 3. 提交并推送

只添加本次发布涉及的文件,检查暂存区后提交:

```shell
git add CHANGELOG.md sustechthesis.dtx
git diff --cached --check
git diff --cached
git commit -m "Bump to vX.Y.Z"
git push origin master
```

等待 `master` 对应的 Verify and sync 工作流通过后再创建 tag。

## 4. 创建版本 tag

```shell
git tag vX.Y.Z
git push origin vX.Y.Z
```

推送 tag 后,Release 工作流会执行以下操作:

1. 构建模板说明书、示例文档和 `sustechthesis.cls`;
2. 生成版本压缩包;
3. 创建对应 tag 的 GitHub Release 草稿并上传构建产物。

## 5. 发布 GitHub Release

在 GitHub Actions 中确认 Release 工作流成功,然后打开生成的 Release 草稿。

将 `CHANGELOG.md` 中当前版本的分类和条目复制到 Release 正文,并在末尾添加相邻版本比较链接:

```md
### Added
- 版本新增内容。

### Changed
- 版本变更内容。

### Fixed
- 版本修复内容。

[`vA.B.C...vX.Y.Z`](https://github.com/SUSTech-CRA/sustech-master-thesis/compare/vA.B.C...vX.Y.Z)
```

发布前确认以下附件齐全:

- `sustechthesis.cls`;
- `sustechthesis.pdf`;
- 中文、英文及报告示例 PDF;
- `sustech-thesis-vX.Y.Z.zip`。

确认版本号、发布日期、正文和附件无误后,将草稿正式发布。

## 6. 删除错误的 tag

如果 tag 尚未正式发布且需要重建,先删除对应的 Release,再删除本地和远端 tag:

```shell
gh release delete vX.Y.Z --yes
git tag -d vX.Y.Z
git push --delete origin vX.Y.Z
```

修正版本内容后,重新执行提交、推送 tag 和检查 Release 草稿的步骤。