Skip to content

Commit a04b632

Browse files
committed
增加动态版本控制&dockerwithzeabur支持
1 parent 956f289 commit a04b632

6 files changed

Lines changed: 204 additions & 1 deletion

File tree

.github/workflows/deploy-image.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Publish Docker Image
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
paths:
7+
- 'Dockerfile'
8+
- 'github_cve_monitor.py'
9+
- 'requirements.txt'
10+
- '.github/workflows/deploy-image.yml'
11+
workflow_dispatch:
12+
13+
env:
14+
REGISTRY: ghcr.io
15+
IMAGE_NAME: ${{ github.repository }}
16+
17+
jobs:
18+
build-and-push:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- name: Checkout repository
26+
uses: actions/checkout@v4
27+
28+
- name: Downcase Image Name
29+
run: echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
30+
31+
- name: Log in to the Container registry
32+
uses: docker/login-action@v3
33+
with:
34+
registry: ${{ env.REGISTRY }}
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Extract metadata (tags, labels) for Docker
39+
id: meta
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
43+
tags: |
44+
type=raw,value=latest
45+
type=sha
46+
47+
- name: Build and push Docker image
48+
uses: docker/build-push-action@v5
49+
with:
50+
context: .
51+
file: ./Dockerfile
52+
push: true
53+
tags: ${{ steps.meta.outputs.tags }}
54+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/version-bump.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: Version Bump
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths-ignore:
8+
- 'README.md'
9+
- 'CHANGELOG.md'
10+
workflow_dispatch:
11+
12+
jobs:
13+
version-bump:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0
24+
25+
- name: Get current version
26+
id: get_version
27+
shell: bash
28+
run: |
29+
# 从代码中获取当前版本号
30+
current_version=$(grep -oP '__version__ = "[^"]+' github_cve_monitor.py | cut -d'"' -f2)
31+
echo "Current version: $current_version"
32+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
33+
34+
- name: Bump version
35+
id: bump_version
36+
run: |
37+
# 解析当前版本号(格式:V1.1.0)
38+
current_version=${{ steps.get_version.outputs.current_version }}
39+
40+
# 提取版本号的数字部分和后缀
41+
if [[ $current_version =~ ^V([0-9]+)\.([0-9]+)\.([0-9]+)([a-z]?)$ ]]; then
42+
major=${BASH_REMATCH[1]}
43+
minor=${BASH_REMATCH[2]}
44+
patch=${BASH_REMATCH[3]}
45+
suffix=${BASH_REMATCH[4]}
46+
47+
# 自动递增patch版本
48+
new_patch=$((patch + 1))
49+
new_version="V$major.$minor.$new_patch$suffix"
50+
else
51+
# 如果版本号格式不符合预期,使用默认值
52+
new_version="V1.1.1"
53+
fi
54+
55+
echo "New version: $new_version"
56+
echo "new_version=$new_version" >> $GITHUB_OUTPUT
57+
58+
- name: Update version in files
59+
shell: bash
60+
run: |
61+
new_version=${{ steps.bump_version.outputs.new_version }}
62+
current_date=$(date +'%Y-%m-%d')
63+
64+
# 更新主程序中的版本号
65+
sed -i "s/__version__ = .*/__version__ = \"$new_version\"/" github_cve_monitor.py
66+
67+
# 更新README.md中的版本信息
68+
# 假设 README 中有 "当前版本:**V1.1.0**" 和 "版本更新时间:2026-01-05"
69+
sed -i "s/当前版本:\*\*.*\*\*/当前版本:\*\*$new_version\*\*/" README.md || true
70+
sed -i "s/版本更新时间:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/版本更新时间:$current_date/" README.md || true
71+
72+
- name: Check if tag exists
73+
id: check_tag
74+
shell: bash
75+
run: |
76+
if git rev-parse --verify "${{ steps.bump_version.outputs.new_version }}" 2>/dev/null; then
77+
echo "tag_exists=true" >> $GITHUB_OUTPUT
78+
echo "Tag ${{ steps.bump_version.outputs.new_version }} already exists"
79+
else
80+
echo "tag_exists=false" >> $GITHUB_OUTPUT
81+
echo "Tag ${{ steps.bump_version.outputs.new_version }} does not exist"
82+
fi
83+
84+
- name: Commit and push changes without tagging
85+
if: steps.check_tag.outputs.tag_exists == 'true'
86+
uses: stefanzweifel/git-auto-commit-action@v5
87+
with:
88+
commit_message: "Bump version to ${{ steps.bump_version.outputs.new_version }}"
89+
push_options: --force-with-lease
90+
91+
- name: Commit and push changes with tagging
92+
if: steps.check_tag.outputs.tag_exists == 'false'
93+
uses: stefanzweifel/git-auto-commit-action@v5
94+
with:
95+
commit_message: "Bump version to ${{ steps.bump_version.outputs.new_version }}"
96+
tagging_message: "${{ steps.bump_version.outputs.new_version }}"
97+
push_options: --force-with-lease

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# 更新日志
2+
3+
本项目的所有重要变更都将记录在此文件中。
4+
5+
## [V1.1.0] - 2026-01-05
6+
7+
### 新增
8+
- **动态版本控制**:实现了自动化版本递增工作流,并在代码中引入动态版本号。
9+
- **Docker 支持**:新增 `Dockerfile`,支持容器化部署。
10+
- **Zeabur 就绪**:针对 Zeabur 部署进行了优化,支持通过 GHCR 自动推送镜像。
11+
- **自动化部署**:新增 GitHub Actions 工作流,自动构建并推送 Docker 镜像。
12+
13+
### 变更
14+
- **文档完善**:更新了 `README.md`,增加了版本展示、更新时间以及详细的部署指南(含 Docker/Zeabur)。

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 使用 Python 3.9 为基础镜像
2+
FROM python:3.9-slim
3+
4+
# 设置工作目录
5+
WORKDIR /app
6+
7+
# 设置时区为北京时间
8+
ENV TZ=Asia/Shanghai
9+
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
10+
11+
# 复制依赖文件并安装
12+
COPY requirements.txt .
13+
RUN pip install --no-cache-dir -r requirements.txt
14+
15+
# 复制项目代码
16+
COPY . .
17+
18+
# 设置环境变量,确保 Python 输出不缓冲
19+
ENV PYTHONUNBUFFERED=1
20+
21+
# 启动命令
22+
CMD ["python", "github_cve_monitor.py"]

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# github-monitor
22

3+
> 实时监控 GitHub 上新增的 CVE、自定义关键词、安全工具更新、大佬仓库监控,并多渠道推送通知。
4+
5+
当前版本:**V1.1.0**
6+
版本更新时间:2026-01-05
7+
8+
39
## 实时监控github上新增的cve、自定义关键词、安全工具更新、大佬仓库监控,并多渠道推送通知
410

511
每日定时检测github是否有新的cve漏洞提交、安全工具更新记录、关键词监控和大佬仓库更新,若有则通过配置的渠道通知用户
@@ -61,7 +67,7 @@ pip install -r requirements.txt
6167
python github_cve_monitor.py
6268
```
6369

64-
### GitHub Actions 部署
70+
### GitHub Actions 部署 (免费)
6571

6672
1. Fork 本仓库
6773
2. 添加 Secrets:
@@ -79,6 +85,15 @@ python github_cve_monitor.py
7985
- `BAIDU_SECRET_KEY`: 百度翻译密钥
8086
3. 启用 GitHub Actions
8187

88+
### Docker / Zeabur 部署 (推荐)
89+
90+
代码推送到 `main` 分支会自动构建镜像到 GHCR。
91+
92+
1. **部署**:在 Zeabur 或 Docker 环境中使用镜像 `ghcr.io/${{ github.repository_owner }}/github_monitor:latest`
93+
2. **环境变量**:参考 GitHub Actions 部署中的 Secrets。
94+
3. **数据持久化 (Zeabur)**
95+
- 挂载路径: `/app/data.db`。挂载此文件以确保数据库在重启后不会丢失。
96+
8297
## 日报功能
8398

8499
- 每日自动生成监控日报

github_cve_monitor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python3
22
# -*- coding:utf-8 -*-
33
# @Author : anonymous520
4+
__version__ = "V1.1.0"
45

56
# 每3分钟检测一次github
67
# 配置优先级: 环境变量 > 配置文件

0 commit comments

Comments
 (0)