
akiunlocks/ruby本镜像基于官方Ruby基础镜像构建,预装了Code Climate test reporter工具,旨在简化Ruby项目的测试覆盖率报告生成流程,帮助开发者快速集成测试报告功能并提交至Code Climate平台。
ruby:3.2-codeclimate)。CODECLIMATE_REPO_TOKEN(可在Code Climate项目设置中获取)。通过Docker Hub拉取镜像(假设镜像名称为ruby-codeclimate-test-reporter,具体以实际镜像仓库为准):
bashdocker pull ruby-codeclimate-test-reporter:latest
如需指定Ruby版本,可通过标签选择,例如:
bashdocker pull ruby-codeclimate-test-reporter:3.2 # Ruby 3.2版本
在项目根目录下运行以下命令,生成并提交测试报告:
bashdocker run --rm \ -v $(pwd):/app \ # 挂载本地项目目录至容器内/app -w /app \ # 设置工作目录为/app -e CODECLIMATE_REPO_TOKEN=your_repo_token \ # 替换为实际的Code Climate仓库令牌 ruby-codeclimate-test-reporter \ sh -c "bundle install && bundle exec rake test && cc-test-reporter format-coverage -t simplecov coverage/coverage.json && cc-test-reporter upload-coverage"
| 环境变量 | 说明 | 是否必需 |
|---|---|---|
CODECLIMATE_REPO_TOKEN | Code Climate项目仓库令牌,用于身份验证 | 是 |
CODECLIMATE_DEBUG | 启用调试模式,输出详细日志 | 否 |
COVERALLS_PARALLEL | 并行处理覆盖率报告(多任务CI场景) | 否 |
在.github/workflows/test.yml中添加以下步骤:
yamljobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run tests with Code Climate report uses: docker/run-action@v3 with: image: ruby-codeclimate-test-reporter:3.2 volumes: - ${{ github.workspace }}:/app env: CODECLIMATE_REPO_TOKEN: ${{ secrets.CODECLIMATE_REPO_TOKEN }} command: sh -c "bundle install && bundle exec rake test && cc-test-reporter format-coverage -t simplecov coverage/coverage.json && cc-test-reporter upload-coverage"
创建docker-compose.yml:
yamlversion: '3.8' services: test-report: image: ruby-codeclimate-test-reporter:latest volumes: - .:/app working_dir: /app environment: - CODECLIMATE_REPO_TOKEN=your_repo_token # 替换为实际令牌 command: > sh -c "bundle install && bundle exec rake test && cc-test-reporter format-coverage -t simplecov coverage/coverage.json && cc-test-reporter upload-coverage"
运行命令:
bashdocker-compose run test-report
coverage/coverage.json)。CODECLIMATE_REPO_TOKEN为敏感信息,建议通过环境变量或CI/CD密钥管理工具传递,避免硬编码。
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务