Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
628b9e2
feat: 优化系统源配置和rosdep一键安装工具网络选项
tangsangsimida Aug 4, 2025
650d5e3
Merge branch 'fishros:master' into master
tangsangsimida Aug 7, 2025
d1a9315
feat(tools): 支持选择中科大 ROS 镜像源
tangsangsimida Aug 29, 2025
ade9adb
refactor(tools): 优化 ROS 源添加流程
tangsangsimida Aug 29, 2025
49657eb
refactor(tools): 优化 ROS 安装工具的退出处理
tangsangsimida Aug 29, 2025
e220cc8
fix(tools): 修复rosdepc函数中print_warn的错误调用
tangsangsimida Sep 17, 2025
a982a56
refactor(tools): 精简 tool_config_rosdep.py 文件
tangsangsimida Sep 17, 2025
c6e7812
refactor(tools): 精简 tool_config_rosdep.py 中的导入信息
tangsangsimida Sep 17, 2025
b8a6c5d
refactor(install): 优化代码结构和错误处理
tangsangsimida Sep 17, 2025
1ee4dc2
refactor(base.py, tool_config_rosdep.py): 更新字符串格式化方法
tangsangsimida Sep 18, 2025
f473822
fix(tool):移除部分不支持ros1的系统编号
tangsangsimida Sep 18, 2025
7774e36
Merge branch 'fishros:master' into master
tangsangsimida Sep 20, 2025
d30d8d9
feat(test): 添加自动化测试工作流和测试 (#1)
tangsangsimida Oct 10, 2025
f62e0d2
ci(test-install): 更新测试工作流中的Ubuntu版本矩阵
awan-deng Oct 10, 2025
d15f6a7
feat(tests): 移除旧的安装脚本测试相关文件
tangsangsimida Oct 17, 2025
e350fb2
fix(tools): 修复文件创建权限冲突问题并清理临时文件
tangsangsimida Oct 18, 2025
5c79f88
add GitHub ci docker test (#2)
tangsangsimida Oct 18, 2025
556f080
refactor(tests): 统一将f-string格式化替换为str.format方法
tangsangsimida Oct 18, 2025
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
52 changes: 52 additions & 0 deletions .github/workflows/test-install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test Install Script

on:
push:
branches: [ dev, master, github_ci_docker_test ]
pull_request:
branches: [ dev, master, github_ci_docker_test ]

jobs:
test-install:
strategy:
matrix:
ubuntu_version: [18.04, 20.04, 22.04, 24.04]
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Run tests in Docker container
run: |
docker run --rm \
-v ${{ github.workspace }}:${{ github.workspace }} \
-w ${{ github.workspace }} \
ubuntu:${{ matrix.ubuntu_version }} \
bash -c "
set -u &&
export DEBIAN_FRONTEND=noninteractive &&
# Set timezone to avoid tzdata interactive prompt
ln -sf /usr/share/zoneinfo/UTC /etc/localtime &&
apt update &&
apt install -y locales &&
locale-gen en_US.UTF-8 &&
export LANG=en_US.UTF-8 &&
export LC_ALL=en_US.UTF-8 &&
apt update && apt install -y sudo python3 python3-pip python3-venv python3-yaml python3-distro wget &&
python3 -m venv /tmp/test_env &&
source /tmp/test_env/bin/activate &&
pip install --upgrade pip &&
pip install pyyaml distro &&
cd tests &&
PYTHONIOENCODING=utf-8 python3 -u test_runner.py
"
- name: Upload test reports
uses: actions/upload-artifact@v4
if: always()
with:
name: test-reports-ubuntu-${{ matrix.ubuntu_version }}
path: |
tests/test_report.json
tests/test_report.html
if-no-files-found: ignore
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@

*.pyc
tests/test_local
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- 一键安装:ROS(支持ROS和ROS2,树莓派Jetson) [贡献@小鱼](https://github.com/fishros)
- 一键安装:VsCode(支持amd64和arm64) [贡献@小鱼](https://github.com/fishros)
- 一键安装:github桌面版(小鱼常用的github客户端) [贡献@小鱼](https://github.com/fishros)
- 一键安装:nodejs开发环境(通过nodejs可以预览小鱼官网噢 [贡献@小鱼](https://github.com/fishros)
- 一键安装:nodejs开发环境(通过nodejs可以预览小鱼官网噢) [贡献@小鱼](https://github.com/fishros)
- 一键配置:rosdep(小鱼的rosdepc,又快又好用) [贡献@小鱼](https://github.com/fishros)
- 一键配置:ROS环境(快速更新ROS环境设置,自动生成环境选择) [贡献@小鱼](https://github.com/fishros)
- 一键配置:系统源(更换系统源,支持全版本Ubuntu系统) [贡献@小鱼](https://github.com/fishros)
Expand Down
14 changes: 9 additions & 5 deletions install.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def main():


# 使用量统计
CmdTask("wget https://fishros.org.cn/forum/topic/1733 -O /tmp/t1733 -q --timeout 10 && rm -rf /tmp/t1733").run()
CmdTask("wget https://fishros.org.cn/forum/topic/1733 -O /tmp/t1733 -q --no-check-certificate --timeout 10 && rm -rf /tmp/t1733").run()

PrintUtils.print_success(tr.tr("已为您切换语言至当前所在国家语言:")+tr.lang)
if tr.country != 'CN':
Expand Down Expand Up @@ -121,11 +121,15 @@ def main():
else:
download_tools(code,tools,url_prefix)
run_tool_file(tools[code]['tool'].replace("/","."))
config_helper.gen_config_file()

PrintUtils.print_delay(tr.tr("欢迎加入机器人学习交流QQ群:438144612(入群口令:一键安装)"),0.05)
PrintUtils.print_delay(tr.tr("鱼香小铺正式开业,最低499可入手一台能建图会导航的移动机器人,淘宝搜店:鱼香ROS 或打开链接查看:https://item.taobao.com/item.htm?id=696573635888"),0.001)
PrintUtils.print_delay(tr.tr("如在使用过程中遇到问题,请打开:https://fishros.org.cn/forum 进行反馈"),0.001)
# 检查是否在 GitHub Actions 环境中运行或使用了测试配置文件
# 如果是,则跳过生成配置文件和后续的打印操作,因为这些操作需要用户输入
if os.environ.get('GITHUB_ACTIONS') != 'true' and os.environ.get('FISH_INSTALL_CONFIG') is None:
config_helper.gen_config_file()

PrintUtils.print_delay(tr.tr("欢迎加入机器人学习交流QQ群:438144612(入群口令:一键安装)"),0.05)
PrintUtils.print_delay(tr.tr("鱼香小铺正式开业,最低499可入手一台能建图会导航的移动机器人,淘宝搜店:鱼香ROS 或打开链接查看:https://item.taobao.com/item.htm?id=696573635888"),0.001)
PrintUtils.print_delay(tr.tr("如在使用过程中遇到问题,请打开:https://fishros.org.cn/forum 进行反馈"),0.001)

if __name__=='__main__':
run_exc = []
Expand Down
64 changes: 64 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# 自动化测试说明

本目录包含用于自动化测试 `FishROS Install` 项目的脚本和配置文件。

## 文件说明

- `test_runner.py`: 主测试运行器,负责执行所有测试用例并生成报告。
- `fish_install_test.yaml`: 测试配置文件,定义了不同系统版本下的测试用例。
- `generate_report.py`: 用于生成 HTML 格式的测试报告。
- `test_report.json`: 测试运行后生成的 JSON 格式报告。
- `test_report.html`: 测试运行后生成的 HTML 格式报告。

## 运行测试

在项目根目录下执行以下命令来运行测试:

```bash
cd tests
python3 test_runner.py
```

### 指定目标系统版本

可以通过 `--target-os-version` 参数指定要测试的 Ubuntu 版本代号:

```bash
python3 test_runner.py --target-os-version focal
```

## 测试配置文件

`fish_install_test.yaml` 文件定义了测试用例。每个测试用例包含以下信息:

- `name`: 测试用例名称。
- `target_os_version`: 目标系统版本代号 (可选,如果不指定则适用于所有系统)。
- `chooses`: 一个列表,包含在安装过程中需要自动选择的选项。

### 配置文件易错点提醒

1. `chooses` 列表中的 `choose` 值必须与 `install.py` 中 `tools` 字典的键值对应。
2. `target_os_version` 必须是有效的 Ubuntu 版本代号(如 `bionic`, `focal`, `jammy` 等),目前仅支持ubuntu系列。
3. `desc` 字段虽然不是必须的,但建议填写以方便理解。
4. 在添加新的测试用例时,确保 `chooses` 中的选项序列能够完整地执行一个安装流程,避免因选项不当导致测试中断。

## 自动化测试与用户实际安装的区别

自动化测试与用户实际安装在以下方面有所不同:

1. **配置文件**: 自动化测试使用 `FISH_INSTALL_CONFIG` 环境变量指定的配置文件,而用户实际安装时会交互式地选择选项并生成配置文件。
2. **环境变量**: 自动化测试会设置特定的环境变量(如 `FISH_INSTALL_CONFIG`),而用户实际安装时不会。
3. **跳过某些步骤**: 在自动化测试环境中,会跳过一些需要用户交互的步骤,例如生成配置文件的确认提示。
4. **GitHub Actions**: 在 GitHub Actions 中运行时,会进一步跳过一些步骤以适应 CI/CD 环境。

## 工作原理

1. `test_runner.py` 会读取 `fish_install_test.yaml` 文件,加载所有适用于当前系统版本的测试用例。
2. 对于每个测试用例,`test_runner.py` 会创建一个临时的 `fish_install.yaml` 配置文件,其中包含该测试用例的 `chooses` 信息。
3. 然后,`test_runner.py` 会运行 `../install.py` 脚本,并通过环境变量 `FISH_INSTALL_CONFIG` 指定使用临时配置文件。
4. `install.py` 会根据配置文件中的选项自动执行安装过程,无需人工干预。
5. 测试运行结束后,`test_runner.py` 会生成 JSON 和 HTML 格式的测试报告。

## GitHub Actions 集成

本测试套件已集成到 GitHub Actions 中,每次推送代码时都会自动运行。工作流文件位于 `.github/workflows/test-install.yml`。
56 changes: 56 additions & 0 deletions tests/fish_install_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 测试配置文件,用于 GitHub Actions 自动化测试
# 格式:
# - name: "测试用例名称"
# target_os_version: "目标系统版本代号" (可选,如果不指定则适用于所有系统)
# chooses: [{choose: <选项ID>, desc: <选项描述>}]

# 为不同的 Ubuntu 版本定义具体的测试配置
# Ubuntu 18.04 (bionic) - Melodic
- name: "Install_ROS_bionic"
target_os_version: "bionic"
chooses:
- { choose: 1, desc: "一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)" }
- { choose: 2, desc: "不更换系统源再继续安装" }
- { choose: 4, desc: "ROS官方源" }
- { choose: 1, desc: "支持的第一个ros版本" }
- { choose: 2, desc: "基础版(小)" }

# Ubuntu 20.04 (focal) - Noetic 或 Foxy
- name: "Install_ROS_focal_noetic"
target_os_version: "focal"
chooses:
- { choose: 1, desc: "一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)" }
- { choose: 2, desc: "不更换系统源再继续安装" }
- { choose: 4, desc: "ROS官方源" }
- { choose: 1, desc: "支持的第一个ros版本" }
- { choose: 2, desc: "基础版(小)" }

# - name: "Install_ROS_focal_foxy"
# target_os_version: "focal"
# chooses:
# - { choose: 1, desc: "一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)" }
# - { choose: 2, desc: "不更换系统源再继续安装" }
# - { choose: 4, desc: "ROS官方源" }
# - { choose: 1, desc: "支持的第一个ros版本" }
# - { choose: 2, desc: "基础版(小)" }

# Ubuntu 22.04 (jammy) - Humble
- name: "Install_ROS_jammy"
target_os_version: "jammy"
chooses:
- { choose: 1, desc: "一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)" }
- { choose: 2, desc: "不更换系统源再继续安装" }
- { choose: 4, desc: "ROS官方源" }
- { choose: 1, desc: "支持的第一个ros版本" }
- { choose: 2, desc: "基础版(小)" }

# Ubuntu 24.04 (noble) - Jazzy
- name: "Install_ROS_noble"
target_os_version: "noble"
chooses:
- { choose: 1, desc: "一键安装(推荐):ROS(支持ROS/ROS2,树莓派Jetson)" }
- { choose: 2, desc: "不更换系统源再继续安装" }
- { choose: 4, desc: "ROS官方源" }
- { choose: 1, desc: "支持的第一个ros版本" }
- { choose: 2, desc: "基础版(小)" }

146 changes: 146 additions & 0 deletions tests/generate_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import json
import time
import os

def generate_html_report(report, output_file):
"""生成HTML格式的测试报告"""
html_content = """
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>一键安装工具测试报告</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
.header {
background-color: #4CAF50;
color: white;
padding: 20px;
text-align: center;
border-radius: 5px;
margin-bottom: 20px;
}
.summary {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.test-case {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.passed {
border-left: 5px solid #4CAF50;
}
.failed {
border-left: 5px solid #f44336;
}
.test-name {
font-size: 18px;
font-weight: bold;
margin-bottom: 10px;
}
.test-status {
display: inline-block;
padding: 5px 10px;
border-radius: 3px;
color: white;
}
.status-passed {
background-color: #4CAF50;
}
.status-failed {
background-color: #f44336;
}
.output {
background-color: #f8f8f8;
padding: 15px;
border-radius: 5px;
margin-top: 10px;
white-space: pre-wrap;
font-family: monospace;
font-size: 12px;
max-height: 300px;
overflow-y: auto;
}
.footer {
text-align: center;
margin-top: 20px;
color: #666;
font-size: 14px;
}
</style>
</head>
<body>
<div class="header">
<h1>一键安装工具测试报告</h1>
<p>生成时间: """ + time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + """</p>
</div>

<div class="summary">
<h2>测试摘要</h2>
<p>总计: """ + str(report["summary"]["total"]) + """</p>
<p>通过: """ + str(report["summary"]["passed"]) + """</p>
<p>失败: """ + str(report["summary"]["failed"]) + """</p>
</div>

<div class="details">
<h2>详细测试结果</h2>
"""

for test_case in report["details"]:
status_class = "passed" if test_case["success"] else "failed"
status_text = "通过" if test_case["success"] else "失败"
status_style = "status-passed" if test_case["success"] else "status-failed"

html_content += """
<div class="test-case {}">
<div class="test-name">
{}
<span class="test-status {}">{}</span>
</div>
<div class="output-title">输出日志:</div>
<div class="output">{}</div>
</div>
""".format(status_class, test_case["name"], status_style, status_text, test_case["output"])

html_content += """
</div>

<div class="footer">
<p>测试报告由一键安装工具自动生成</p>
</div>
</body>
</html>
"""

with open(output_file, 'w', encoding='utf-8') as f:
f.write(html_content)


if __name__ == "__main__":
# 读取JSON测试报告
report_file = "test_report.json"
if os.path.exists(report_file):
with open(report_file, 'r', encoding='utf-8') as f:
report = json.load(f)

# 生成HTML报告
html_report_file = "test_report.html"
generate_html_report(report, html_report_file)
print("HTML测试报告已生成: {}".format(html_report_file))
else:
print("找不到测试报告文件: {}".format(report_file))
Loading