使用 Github Actions 进行集成

Github Actions 支持持续集成/持续部署 (CI/CD) 的开发方式,可以在每次提交代码时都能触发一次软件工作流。集成了 Incredibuild 的 Github Actions 可以通过将软件工作流分发给可用的软件助手 (helper agents) 来提升工作流速度。

Github Actions 使用 Runners 主机处理提交代码的工作流。可以通过在 Runners 上安装客户端 Incredibuild Initiator Agent 来实现 GitHub Actions 与 Incredibuild 的集成。安装完成后,就可以通过 Incredibuild Helper Agents 分发工作流了。

集成方式会因为使用私域环境 (self-hosted runners)公域环境 (Github hosted runners)而有所不同。

这种集成方式适用于 Incredibuild 的任一种证书。

在 Self-Hosted Runners 环境下使用 Github Actions 进行集成

使用 Incredibuild 进行集成,需要在每一台 self-hosted runner 上安装 Initiator Agent 客户端。

  1. Incredibuild 的设置和先决条件

    1. Github Actions 必须在使用 Windows 系统的 self-hosted runners 上运行。

    2. 需要提前安装好 Incredibuild Coordinator。

    3. 在 Github Self-Hosted Runners 的主机上安装 Incredibuild,然后和 Incredibuild Coordinator 连接。

    4. 使用 Incredibuild 的构建命令准备一个批处理文件。这取决于您要构建什么。欲了解更多细节,请查看 Running Builds

  2. 新增一个 Github Action 工作流

    定义一个工作流,使其在任何时候使用 Github Actions 都会调用 Incredibuild。如果你已经有了一个 Github Action 工作流,下方代码可以作为一个范例对已有工作流进行相应的调整。

    1. 从 GitHub 项目存储库访问 Actions 标签,然后新增一个工作流。

    2. 选择 Manual Workflow ,并点击配置

    3. 用下方代码替换内容:

      复制
      name: IB trigger

      # Controls when the workflow will run
      on:
        # Triggers the workflow on push or pull request events but only for the master branch
        push:
          branches: [ master ]
        pull_request:
          branches: [ master ]

      jobs:
        # This workflow contains a single job called "build"
        build:
          # The type of runner that the job will run on
          runs-on: self-hosted

            # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
            - uses: actions/checkout@v2

            # Runs a single command using the runners shell
            - name: Run Rebuild batch file and distridute the tasks within helpers
              run: powershell <path to batch file you just created>

            # Runs a set of commands using the runners shell
      #      - name: Run a multi-line script
      #        run: |
      #         echo Add other actions to build,
      #         echo test, and deploy your project.
    4. 用正确的路径替换 <path to batch file you just created>。

 

在 Github-Hosted Runners 环境下使用 Github Actions 进行集成

由于 Github-Hosted Runners 是动态创建的,集成过程中需要设置 Github Actions,以便其在连接了 Coordinator 的环境中自动安装 Incredibuild。这需要你在 Github 托管的运行器机器上使用 floating initiator license

  1. Github Actions 必须在使用 Windows 系统的 Github-hosted runners 上运行。

  2. 需要提前安装好 Incredibuild Coordinator。

  3. 确保 Coordinator 环境中的31104端口开放,可接收来自 runner 机器的流量。Incredibuild 初始程序将安装在 runners 主机上,并连接到 Incredibuild Coordinator。

  4. 复制 Incredibuild 安装软件,将其放到 Github Runners 可以访问的位置。

  5. 在 Github Actions 上创建一个手动工作流。如果你已经有了一个 Github Action 工作流,下方代码可以作为一个范例对已有工作流进行相应的调整:

    1. 从 GitHub 项目存储库访问 Actions 标签,然后新增一个工作流。

    2. 选择 Manual Workflow ,并点击配置

    3. 用下方代码替换内容:

      复制
      name: Build on Windows
      on: push
      jobs:
        build:
          runs-on: windows-2019
          steps:
            -  run: |
                choco install wget -y
                cd C:\ 
                wget "<path to original IB install file>/IBSetupConsole.exe" -O "C:\IBSetupConsole.exe" 
                ./IBSetupConsole.exe /Install /Components=Agent /Coordinator=<IP of Coordinator Machine> the /Agent:AgentRole=Initiator /Agent:InitiatorType=Floating /AddToPath=ON /Agent:InstallAddins=OFF
                                            
            - name: Add msbuild to PATH
              uses: microsoft/setup-msbuild@v1.1
                    
            - name: Clone Repository and Rebuild with Incredibuild
              run: |
                  cd C:\
                  git clone <URL to your Github repository>
                  cd C:\<name of your Github project>
                  $env:Path = 'C:\Program Files (x86)\IncrediBuild'
                  BuildConsole.exe '<path to your solution>' /rebuild /cfg="Debug|x64" /usemsbuild ##Replace with your build command
                                                   
            - name: Upload artifacts
              if: always()    
              uses: actions/upload-artifact@v2
              with:
                 name: my-artifact
                 path: |
                   C:\Program Files (x86)\IncrediBuild\History
                   C:\Program Files (x86)\IncrediBuild\Logs
    4. 使用实际连到 GitHub 存储库的 URL 调整代码,给 GitHub 项目命名,然后生成命令(不要使用 BuildConsole.exe...)欲了解如何定义构建命令,详见 Running Builds。如果你想修改 Incredibuild 的安装命令(IBSetupConsole.exe),请参阅 Silent Installation 了解详情。