Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- 'v*'

permissions:
contents: write

env:
CARGO_TERM_COLOR: always

Expand All @@ -18,20 +21,27 @@ jobs:
steps:
- name: Get version from tag
id: get_version
run: echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
shell: bash
run: |
tag="${GITHUB_REF_NAME}"
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "Release tags must use vMAJOR.MINOR.PATCH, for example v1.2.3" >&2
exit 1
fi
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"

- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: SSHWarden ${{ steps.get_version.outputs.version }}
tag_name: ${{ github.ref_name }}
release_name: SSHWarden v${{ steps.get_version.outputs.version }}
draft: false
prerelease: false
body: |
## SSHWarden ${{ steps.get_version.outputs.version }}
## SSHWarden v${{ steps.get_version.outputs.version }}

### 下载

Expand All @@ -52,6 +62,8 @@ jobs:
name: Build Release - ${{ matrix.os }}
needs: create-release
runs-on: ${{ matrix.os }}
env:
SSHWARDEN_VERSION: ${{ needs.create-release.outputs.version }}
strategy:
matrix:
include:
Expand Down Expand Up @@ -85,6 +97,16 @@ jobs:
- name: Build release
run: cargo build --release --verbose

- name: Verify release version
shell: bash
run: |
version_output="$(target/release/${{ matrix.artifact_name }} --version)"
echo "$version_output"
if [[ "$version_output" != *"${SSHWARDEN_VERSION}" ]]; then
echo "Expected release version ${SSHWARDEN_VERSION}" >&2
exit 1
fi

- name: Package release (Windows)
if: matrix.os == 'windows-latest'
shell: bash
Expand Down
96 changes: 37 additions & 59 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,19 @@ cp ../README.md .
创建 `scripts/package-windows.ps1`:

```powershell
# 构建 release
# 读取发布版本:CI 设置 SSHWARDEN_VERSION,本地发布可在 vX.Y.Z tag 上运行
if ($env:SSHWARDEN_VERSION) {
$version = $env:SSHWARDEN_VERSION
} else {
$tag = git describe --tags --exact-match --match "v[0-9]*"
if ($LASTEXITCODE -ne 0) {
throw "Set SSHWARDEN_VERSION or run this script from a vX.Y.Z tag"
}
$version = $tag.Trim() -replace '^v', ''
}

# 构建 release;build.rs 会把版本注入二进制
$env:SSHWARDEN_VERSION = $version
cargo build --release

# 创建发布目录
Expand All @@ -134,7 +146,6 @@ Copy-Item "README.md" -Destination $releaseDir
Copy-Item "LICENSE" -Destination $releaseDir -ErrorAction SilentlyContinue

# 创建 zip
$version = "0.1.0"
$zipName = "sshwarden-$version-windows-x64.zip"
Compress-Archive -Path "$releaseDir\*" -DestinationPath $zipName -Force

Expand All @@ -154,7 +165,15 @@ powershell -ExecutionPolicy Bypass -File scripts/package-windows.ps1
#!/bin/bash
set -e

# 构建 release
# 读取发布版本:CI 设置 SSHWARDEN_VERSION,本地发布可在 vX.Y.Z tag 上运行
VERSION="${SSHWARDEN_VERSION:-}"
if [ -z "$VERSION" ]; then
TAG=$(git describe --tags --exact-match --match 'v[0-9]*')
VERSION="${TAG#v}"
fi
export SSHWARDEN_VERSION="$VERSION"

# 构建 release;build.rs 会把版本注入二进制
cargo build --release

# 创建发布目录
Expand All @@ -171,7 +190,6 @@ cp README.md "$RELEASE_DIR/"
chmod +x "$RELEASE_DIR/sshwarden"

# 创建 tar.gz
VERSION="0.1.0"
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
TAR_NAME="sshwarden-$VERSION-$PLATFORM-$ARCH.tar.gz"
Expand Down Expand Up @@ -250,61 +268,21 @@ cargo build --release --target x86_64-pc-windows-gnu

## 持续集成 (CI)

### GitHub Actions 示例

创建 `.github/workflows/release.yml`:

```yaml
name: Release

on:
push:
tags:
- 'v*'

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Build
run: cargo build --release

- name: Package (Windows)
if: matrix.os == 'windows-latest'
run: |
mkdir release-package
cp target/release/sshwarden.exe release-package/
cp config.toml.example release-package/
cp README.md release-package/
Compress-Archive -Path release-package/* -DestinationPath sshwarden-windows-x64.zip

- name: Package (Unix)
if: matrix.os != 'windows-latest'
run: |
mkdir release-package
cp target/release/sshwarden release-package/
cp config.toml.example release-package/
cp README.md release-package/
tar -czf sshwarden-${{ matrix.os }}.tar.gz -C release-package .

- name: Upload Release
uses: softprops/action-gh-release@v1
with:
files: |
sshwarden-*.zip
sshwarden-*.tar.gz
### GitHub Actions 发布

仓库中的 `.github/workflows/release.yml` 已配置 tag 发布:

- 只响应 `vMAJOR.MINOR.PATCH` 格式的 tag,例如 `v0.2.0`。
- workflow 从 tag 解析版本,并在 release 构建中设置 `SSHWARDEN_VERSION`。
- `build.rs` 会把该版本注入二进制的 `--version` 输出和 Windows 文件版本信息。
- 发布包名使用 `sshwarden-{version}-{platform}-{arch}` 格式。

发布时不要修改 `Cargo.toml` 里的版本;创建并推送 tag 即可触发发布:

```bash
VERSION=0.2.0
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
```

## 故障排除
Expand Down
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ members = [

[package]
name = "sshwarden"
version = "2.2.0"
version = "0.0.0-dev"
edition = "2021"
license = "GPL-3.0"
publish = false
Expand Down Expand Up @@ -46,7 +46,7 @@ windows = { version = "0.61", features = [
winresource = "0.1"

[workspace.package]
version = "2.2.0"
version = "0.0.0-dev"
license = "GPL-3.0"
edition = "2021"
publish = false
Expand Down
43 changes: 22 additions & 21 deletions GITHUB_ACTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
### 2. Release (`.github/workflows/release.yml`)

**触发条件**:
- 推送以 `v` 开头的 tag(例如 `v0.1.0`)
- 推送符合 `vMAJOR.MINOR.PATCH` 的 tag(例如 `v0.2.0`)

**功能**:
- 创建 GitHub Release
Expand Down Expand Up @@ -63,40 +63,35 @@ git push origin main

### 发布新版本

1. **更新版本号**
发布版本只通过 Git tag 声明;不要为了发布去修改 `Cargo.toml`。仓库中的 Cargo 版本保持 `0.0.0-dev` 作为开发占位值,Release workflow 会从 `vX.Y.Z` tag 注入 `SSHWARDEN_VERSION`,构建出的二进制版本和产物名称都会使用 tag 版本。

编辑 `Cargo.toml`:
```toml
[package]
version = "0.2.0" # 更新版本号
```

2. **提交更改**
1. **确认 main 已准备好发布**

```bash
git add Cargo.toml
git commit -m "chore: bump version to 0.2.0"
git push origin main
git switch main
git pull --ff-only
cargo test --verbose
```

3. **创建并推送 tag**
2. **创建并推送 tag**

```bash
# 创建 tag
git tag -a v0.2.0 -m "Release version 0.2.0"
VERSION=0.2.0

# 推送 tag
git push origin v0.2.0
git tag -a "v$VERSION" -m "Release v$VERSION"
git push origin "v$VERSION"
```

4. **自动发布**
3. **自动发布**

推送 tag 后,GitHub Actions 会自动:
- 校验 tag 是否符合 `vMAJOR.MINOR.PATCH` 格式
- 将 tag 版本注入 release 构建
- 在三个平台上构建 release 版本
- 创建 GitHub Release
- 上传打包好的二进制文件
- 上传带版本号的二进制压缩包

5. **编辑 Release Notes(可选)**
4. **编辑 Release Notes(可选)**

访问 https://github.com/Hureru/SSHWarden/releases,编辑自动创建的 release,添加更新日志。

Expand Down Expand Up @@ -175,7 +170,13 @@ cargo build --release --verbose
git push origin :refs/tags/v0.1.0
```

2. **权限问题**
2. **Tag 格式不符合发布规范**
```
Release tags must use vMAJOR.MINOR.PATCH, for example v1.2.3
```
解决: 使用 `vX.Y.Z` 格式重新创建 tag,例如 `v0.2.0`。

3. **权限问题**
```
Error: Resource not accessible by integration
```
Expand Down
Loading
Loading