Skip to content

Commit 76a15a3

Browse files
committed
feat(deploy): add release automation and systemd service
The changes include: - Renaming build.yml to build-release.yml and expanding its functionality to create GitHub releases - Adding release job to generate timestamped releases with artifacts - Including systemd service file for production deployment - Setting required permissions for release creation - Streamlining artifact handling across build and release jobs
1 parent 4c8ee5e commit 76a15a3

File tree

2 files changed

+71
-18
lines changed

2 files changed

+71
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
name: Build Project
1+
# 工作流名称
2+
name: Build and Release Project
23

4+
# 触发工作流的事件
35
on:
46
push:
57
branches:
6-
- main
7-
workflow_dispatch:
8+
- main # 仅在 main 分支有 push 时触发
9+
workflow_dispatch: # 允许手动触发
10+
11+
# 为工作流授予创建 Release 的权限
12+
permissions:
13+
contents: write
814

915
jobs:
16+
# 构建任务
1017
build:
1118
name: Build for ${{ matrix.target }}
12-
# 为每个目标选择对应的原生操作系统
1319
runs-on: ${{ matrix.os }}
1420
strategy:
1521
fail-fast: false
1622
matrix:
17-
# 定义目标和操作系统的对应关系
1823
include:
1924
- target: x86_64-unknown-linux-gnu
2025
os: ubuntu-latest
21-
- target: x86_64-pc-windows-msvc # <--- 这里已从 gnu 更改为 msvc
26+
- target: x86_64-pc-windows-msvc
2227
os: windows-latest
2328
- target: x86_64-apple-darwin
2429
os: macos-latest
@@ -32,17 +37,10 @@ jobs:
3237
with:
3338
targets: ${{ matrix.target }}
3439

35-
# --- 特定于操作系统的依赖安装 ---
3640
- name: Install dependencies (Linux)
3741
if: runner.os == 'Linux'
3842
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
3943

40-
# Windows (MSVC) 和 macOS 通常不需要手动安装 OpenSSL,Rust 的 openssl-sys crate 能处理好。
41-
# 如果在 Windows 上遇到问题,可以考虑在 Cargo.toml 中为 openssl 启用 "vendored" 特性。
42-
# - name: Install dependencies (Windows)
43-
# if: runner.os == 'Windows'
44-
# run: choco install ... # 如果有需要
45-
4644
- name: Cache dependencies
4745
uses: actions/cache@v4
4846
with:
@@ -52,22 +50,20 @@ jobs:
5250
~/.cargo/registry/cache/
5351
~/.cargo/git/db/
5452
target/
55-
# Key 需要包含操作系统,以防缓存冲突
5653
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
5754
restore-keys: |
5855
${{ runner.os }}-cargo-
5956
6057
- name: Build binary with cargo
6158
run: cargo build --release --target ${{ matrix.target }} --verbose
6259

63-
- name: Prepare artifact
60+
- name: Prepare artifact name and path
6461
id: prepare_artifact
6562
shell: bash
6663
run: |
67-
BIN_NAME="telembed" # <-- 你的包名
64+
BIN_NAME="telembed"
6865
TARGET="${{ matrix.target }}"
6966
70-
# 根据操作系统设置正确的二进制路径和后缀
7167
if [[ "${{ runner.os }}" == "Windows" ]]; then
7268
BIN_PATH="target/${TARGET}/release/${BIN_NAME}.exe"
7369
ARTIFACT_NAME="${BIN_NAME}-${TARGET}.exe"
@@ -79,8 +75,43 @@ jobs:
7975
echo "artifact_name=${ARTIFACT_NAME}" >> $GITHUB_OUTPUT
8076
echo "bin_path=${BIN_PATH}" >> $GITHUB_OUTPUT
8177
82-
- name: Upload artifact
78+
# 此步骤上传的 artifact 会被自动压缩成 zip,但这只是为了在 job 之间传递
79+
- name: Upload artifact for release job
8380
uses: actions/upload-artifact@v4
8481
with:
8582
name: ${{ steps.prepare_artifact.outputs.artifact_name }}
8683
path: ${{ steps.prepare_artifact.outputs.bin_path }}
84+
85+
# 发布任务
86+
release:
87+
name: Create GitHub Release
88+
needs: build
89+
runs-on: ubuntu-latest
90+
steps:
91+
- name: Generate timestamp tag
92+
id: generate_tag
93+
run: echo "TAG=$(date +'%Y.%m.%d.%H%M%S')" >> $GITHUB_OUTPUT
94+
95+
# 此步骤会下载所有构建产物,并自动解压
96+
- name: Download all build artifacts
97+
uses: actions/download-artifact@v4
98+
with:
99+
path: artifacts/
100+
101+
- name: Display structure of downloaded files
102+
run: ls -R artifacts
103+
104+
# 重要提示:
105+
# 上一步的 download-artifact 会自动解压在 build 任务中生成的压缩包。
106+
# 因此,'artifacts' 目录中现在存放的是原始的、未压缩的二进制文件。
107+
# 下面的步骤会将这些原始二进制文件直接作为附件上传到 Release 中。
108+
- name: Create Release and Upload Assets
109+
uses: softprops/action-gh-release@v2
110+
with:
111+
tag_name: ${{ steps.generate_tag.outputs.TAG }}
112+
name: "Release ${{ steps.generate_tag.outputs.TAG }}"
113+
generate_release_notes: true
114+
# 'files' 通配符会匹配 'artifacts' 目录下的所有文件
115+
# 并将它们作为独立的、未压缩的文件上传
116+
files: |
117+
artifacts/**/*

telembed.service

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[Unit]
2+
Description=Telegram QA Bot
3+
After=network.target
4+
StartLimitIntervalSec=0
5+
6+
[Service]
7+
Type=simple
8+
9+
Restart=always)
10+
RestartSec=5
11+
12+
User=telembed
13+
Group=telembed
14+
15+
WorkingDirectory=/opt/telembed
16+
17+
ExecStart=/usr/local/bin/telembed
18+
19+
Environment="XDG_CONFIG_HOME=/opt"
20+
21+
[Install]
22+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)