Skip to content

About

通过 GitHub Actions 在 CI 环境中启动一个临时的 SSH 调试会话

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

actions-ssh

通过 GitHub Actions 在 CI 环境中启动一个临时的 SSH 调试会话,方便在 Workflow 运行过程中进入 Runner 排查问题。

✨ 特性

  • 🚀 基于 GitHub Actions
  • 🔐 支持通过 SSH 进入 GitHub Actions Runner
  • 🐛 适合排查 CI/CD 环境中的问题
  • 🖥️ 使用 tmate 提供交互式终端
  • 📦 无需额外部署服务器

🚀 使用方法

1. 手动启动 Workflow

进入 GitHub 仓库:

Actions → Interactive Debug → Run workflow

当前 Workflow 使用 workflow_dispatch 触发,因此需要手动执行。

2. 等待 Runner 启动

Workflow 会启动一个 Ubuntu Runner,并执行以下步骤:

  1. Checkout 当前仓库代码
  2. 安装 Python 3.11
  3. 启动 tmate SSH 调试会话

对应的 Workflow 文件:

.github/workflows/debug-ssh.yml

3. 获取 SSH 连接信息

Workflow 启动后,tmate 会在日志中输出 SSH 连接信息。

在 GitHub Actions 的 Job 日志中找到类似以下内容:

ssh <user>@<host>

复制 SSH 命令到本地终端即可连接到当前 GitHub Actions Runner。

🔧 Workflow

当前 Workflow 配置:

name: Interactive Debug

on:
  workflow_dispatch:

jobs:
  debug:
    runs-on: ubuntu-latest

    steps:
      - name: Check Out Code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Setup Tmate SSH Session
        uses: mxschmitt/action-tmate@v3
        with:
          detached: false

🐛 适用场景

这个项目主要适合用于 CI/CD 问题排查,例如:

  • GitHub Actions 环境与本地环境不一致
  • 某个命令在 CI 中运行失败
  • 检查环境变量、文件系统或网络状态
  • 调试安装依赖的问题
  • 排查构建、测试或部署脚本
  • 需要直接进入 Runner 查看运行环境

⚠️ 安全注意事项

SSH 调试会话可以直接访问当前 GitHub Actions Runner,因此请谨慎使用。

特别注意:

  • 不要在公共仓库中泄露敏感信息
  • 不要把 SSH 连接信息提交到代码仓库
  • 不要在日志中输出 Token、密码或私钥
  • 调试完成后及时结束 Workflow
  • 建议仅在受信任的仓库和场景中使用

📁 项目结构

actions-ssh/
├── .github/
│   └── workflows/
│       └── debug-ssh.yml
├── LICENSE
└── README.md

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.

🙏 Thanks


如果这个项目对你有帮助,欢迎 ⭐ Star。

About

通过 GitHub Actions 在 CI 环境中启动一个临时的 SSH 调试会话

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors