oss-review-toolkit/ort-ci-github-action

GitHub: oss-review-toolkit/ort-ci-github-action

在 GitHub Actions 中自动化运行 ORT,实现许可证、安全与最佳实践检查并生成 SBOM 与报告。

Stars: 33 | Forks: 12

# GitHub Action 用于 ORT 使用 [ORT][ort] 运行许可、安全、最佳实践检查并生成报告/软件物料清单(SBOMs) 在 [GitHub Actions][gh-action-docs] 中。 ## 用法 参见 [action.yml](action.yml) 注意:以下所有示例均使用 main 分支。 在生产环境中实现 ORT 的 GitHub Action 时,建议使用最新的 [tags][ort-gh-action-tags]。 ### 基础 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main ``` 或者,您也可以使用 ORT 通过 Git、Git-repo、Mercurial 或 Subversion 下载项目源码。 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: vcs-url: 'https://github.com/jshttp/mime-types.git' ``` ### 场景 - [仅运行 ORT 并分析指定的软件包管理器](#Run-ORT-and-analyze-only-specified-package-managers) - [使用标签运行 ORT](#Run-ORT-with-labels) - [运行 ORT 并在策略违规或安全问题时使任务失败](#Run-ORT-and-fail-job-on-policy-violations-or-security-issues) - [在私有仓库上运行 ORT](#Run-ORT-on-private-repositories) - [使用矩阵在多个仓库上运行 ORT](#Run-ORT-on-multiple-repositories-using-a-matrix) - [使用自定义全局配置运行 ORT](#Run-ORT-with-a-custom-global-configuration) - [使用自定义 Docker 镜像运行 ORT](#Run-ORT-with-a-custom-Docker-image) - [使用 PostgreSQL 数据库运行 ORT](#Run-ORT-with-PostgreSQL-database) - [仅运行 ORT 的一部分功能](#Run-only-parts-of-the-GitHub-Action-for-ORT) #### 仅运行 ORT 并分析指定的软件包管理器 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 with: repository: 'jshttp/mime-types' - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: allow-dynamic-versions: 'true' ort-cli-args: '-P ort.analyzer.enabledPackageManagers=NPM,Yarn,Yarn2' ``` #### 使用标签运行 ORT 使用标签来跟踪扫描相关信息或为特定产品、交付或组织执行策略规则。 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 with: repository: 'jshttp/mime-types' - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: allow-dynamic-versions: 'true' ort-cli-analyze-args: > -l project=oss-project -l dist=external -l org=engineering-sdk-xyz-team-germany-berlin ``` ### 运行 ORT 并在策略违规或安全问题时使任务失败 将 `fail-on` 设置为在以下情况时使操作失败: - 评估器报告的策略违规超过 `severeRuleViolationThreshold` 级别。 - 顾问报告的安全问题超过 `severeIssueThreshold` 级别。 默认情况下,`severeRuleViolationThreshold` 和 `severeIssueThreshold` 设置为 `WARNING` 但您可以在 [config.yml][ort-config-yml] 中将其更改为例如 `ERROR`。 #### 在私有仓库上运行 ORT 要在私有 Git 仓库上运行 ORT,我们建议: - 设置具有只读访问权限的账户 - 使用 .netrc 文件、SSH 密钥或 [GitHub 令牌][gh-tokens] 进行身份验证。 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Checkout project uses: actions/checkout@v5 with: repository: 'jshttp/mime-types' - name: Add .netrc run: > default login ${{ secrets.NETRC_LOGIN }} password ${{ secrets.NETRC_PASSWORD }}" > ~/.netrc - name: Add SSH key run: | mkdir -p ~/.ssh echo "${{ secrets.SSH_KEY }}" > ~/.ssh/id_github echo "${{ secrets.SSH_PUBLIC_KEY }}" > ~/.ssh/id_github.pub chmod 600 ~/.ssh/id_github* cat >>~/.ssh/config <> "$GITHUB_ENV" - name: Use HTTPS with personal token always for Git cloning run: | git config --global url."https://oauth2:${{ secrets.PERSONAL_TOKEN_1 }}@github.com/".insteadOf "ssh://git@github.com/" git config --global url."https://oauth2:${{ secrets.PERSONAL_TOKEN_2 }}@git.example.com/".insteadOf "ssh://git@git.example.com/" git config --global url."https://oauth2:${{ secrets.PERSONAL_TOKEN_2 }}@git.example.com/".insteadOf "https://git.example.com/" - name: Checkout project uses: actions/checkout@v5 with: repository: 'example-org/alpha' ref: 'master' github-server-url: 'https://git.example.com' token: ${{ secrets.PERSONAL_TOKEN_2 }} - name: Run GitHub action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: ort-config-repository: 'https://oauth2:${{ secrets.PERSONAL_TOKEN_2 }}@git.example.com/ort-project/ort-config.git' run: > cache-dependencies, metadata-labels, analyzer, advisor, reporter, upload-results ``` #### 使用矩阵在多个仓库上运行 ORT ``` jobs: ort: strategy: fail-fast: false matrix: include: - repository: example-org/alpha sw-name: alpha - repository: example-org/beta sw-name: beta runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 with: repository: ${{ matrix.repository }} - uses: oss-review-toolkit/ort-ci-github-action@main with: sw-name: ${{ matrix.sw-name }} ``` ### 使用自定义全局配置运行 ORT 使用 `ort-config-repository` 指定 ORT 全局配置仓库的位置。 如果未指定 `ort-config-revision`,则会使用配置仓库的最新状态。 或者,您也可以在运行 GitHub Action 之前将 ORT 全局配置文件放置在 `~/.ort/config` 中。 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 with: repository: 'jshttp/mime-types' - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: ort-config-repository: 'https://github.com/oss-review-toolkit/ort-config' ort-config-revision: 'e4ae8f0a2d0415e35d80df0f48dd95c90a992514' ``` ### 使用自定义 Docker 镜像运行 ORT ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: image: 'my-org/ort-images/ort:latest' ``` ### 使用 PostgreSQL 数据库运行 ORT ORT 支持使用 PostgreSQL 数据库缓存扫描数据以加快扫描速度。 使用以下 [GitHub 操作密钥][gh-action-secrets] 指定要使用的数据库: - `POSTGRES_URL`: 'jdbc:postgresql://ort-db.example.com:5432/ort' - `POSTGRES_USERNAME`: 'ort-db-username' - `POSTGRES_PASSWORD`: 'ort-db-password' 接下来,将这些密钥传递给 ORT 的 GitHub Action: ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Use HTTPS instead of SSH for Git cloning run: git config --global url.https://github.com/.insteadOf ssh://git@github.com/ - name: Checkout project uses: actions/checkout@v5 with: repository: 'jshttp/mime-types' ref: '2.1.35' - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: db-url: ${{ secrets.POSTGRES_URL }} db-username: ${{ secrets.POSTGRES_USERNAME }} db-password: ${{ secrets.POSTGRES_PASSWORD }} run: 'cache-dependencies,analyzer,scanner,evaluator,advisor,reporter,upload-results' sw-name: 'Mime Types' sw-version: '2.1.35' ``` ### 仅运行 ORT 的一部分功能 ``` jobs: ort: runs-on: ubuntu-latest steps: - name: Checkout project uses: actions/checkout@v5 - name: Run GitHub Action for ORT uses: oss-review-toolkit/ort-ci-github-action@main with: run: > cache-dependencies, metadata-labels, analyzer, advisor, reporter, upload-results, upload-evaluation-result ``` # 想要帮助或有疑问? 欢迎所有贡献。如果您有兴趣参与贡献,请阅读我们的 [贡献指南][ort-contributing-md],并为了快速解答您的问题,我们建议您 [加入我们的 Slack 社区][ort-slack]。 # 许可证 版权所有 (C) 2020-2025 [The ORT Project Authors](./NOTICE)。 请参阅此项目根目录中的 [LICENSE](./LICENSE) 文件以了解许可详情。 OSS Review Toolkit (ORT) 是一个 [Linux Foundation 项目][lf],也是 [ACT][act] 的一部分。
标签:GitHub Action, OSS审查工具包, SBOM, 二进制发布, 依赖管理, 安全扫描, 开源合规, 开源工具, 开源框架, 开源许可证, 开源软件治理, 持续安全, 持续集成, 时序注入, 最佳实践, 测试用例, 硬件无关, 网络调试, 自动化, 许可证合规, 请求拦截, 跌倒检测, 软件供应链安全, 软件物料清单, 远程方法调用