[T.10] 团队项目:CI/CD实践
| 项目 | 内容 |
|---|---|
| 这个作业属于哪个课程 | 首页 - 2026年春季软件工程 - 北京航空航天大学 - 班级博客 - 博客园 |
| 这个作业的需求在哪里 | [T.10] 团队项目:CI/CD实践 - 作业 - 2026年春季软件工程 - 班级博客 - 博客园 |
| 我在这个课程的目标是 | 作为团队完成一个完整的软件开发流程,学习软件工程与软件开发相关流程和技术 |
| 这个作业在哪个具体方面帮助我实现目标 | 了解CI/CD的实现和在实际工程中的应用 |
选用方案
本项目现采用 Github Actions 方案实现 CI/CD 流程。考虑原因如下:
- 测试和构建步骤流程存在对 CI/CD 的需求,有助于及时纠错;
- 项目体量中等,可选择的管理方式较为灵活;
- 相较于 Unity 自带的版本控制,团队成员更加普遍熟悉 Github;
- Github Actions 配置简单,已存在较为成熟的 CI/CD 工具。
配置文件
本配置文件将动作分为测试和构建两阶段,其中辅以对可能出现的 Git LFS 的支持:
name: Test and Build
on:
pull_request:
branches:
- main
- master
- release
- develop
paths:
- 'Assets/**'
- 'Packages/**'
- 'ProjectSettings/**'
jobs:
test:
name: Test project
runs-on: ubuntu-latest
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
# Checkout (without LFS)
- name: Checkout repository
uses: actions/checkout@v4
# Git LFS
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
# Cache
- uses: actions/cache@v3
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
# Test
- name: Run tests
uses: game-ci/unity-test-runner@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
allowDirtyBuild: true
build:
name: Build project
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'pull_request'
steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false
# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true
# Checkout (without LFS)
- name: Checkout repository
uses: actions/checkout@v4
# Git LFS
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v3
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
# Cache
- uses: actions/cache@v3
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
# Build
- name: Build project
uses: game-ci/unity-builder@v4
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
with:
targetPlatform: StandaloneWindows64
allowDirtyBuild: true
# Output
- uses: actions/upload-artifact@v4
with:
name: Build
path: build
执行流程说明
当前动作会在向 master/develop 分支发起 pull request 时执行,具体流程如下:
- 测试:清理测试环境空间,同步仓库和 LFS 内容,构建缓存,执行测试和生成报告;
- 如测试成功,进行构建:清理测试环境空间,同步仓库和 LFS 内容,构建缓存,构建可运行工件,上传构建结果。
如此设计出于以下考量:
- 测试为项目最常使用的可自动化步骤;
- 项目涉及频繁的提交和微调过程,全部进行测试会产生时间上的浪费;
- pull request 会对关键分支产生影响,同时标记了一个分支开发的基本完成;
- 游戏项目强调游玩效果,需要对项目实现间的各次构建结果进行对比。
执行结果
当前 CI/CD 方案已集成至项目内,可长时间平稳运行,且多次帮助开发项目的同学查明项目潜在问题。


浙公网安备 33010602011771号