Skip to content

Update main.yml

Update main.yml #80

Workflow file for this run

name: Unity CI
on: [ push, pull_request ]
permissions:
contents: write
pages: write
id-token: write
checks: write
packages: write
actions: write
attestations: write
deployments: write
statuses: write
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
# 1. Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
# 2. Cache:缓存 team_project/Library
- uses: actions/cache@v3
id: cache-library-test
with:
path: team_project/Library
key: Library-test-${{ hashFiles('team_project/Assets/**', 'team_project/Packages/**', 'team_project/ProjectSettings/**') }}
restore-keys: |
Library-test-
# 3. Run PlayMode & EditMode tests
- name: Run PlayMode 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:
projectPath: team_project
githubToken: ${{ secrets.GITHUB_TOKEN }}
coverageOptions: |
generateHtmlReport;
generateSummaryBadge;
generateAdditionalMetrics;
assemblyFilters:+CommonScripts*,+ItemSystem*,+LandingScripts*,+PlayMode*
- name: Upload Code Coverage Report
uses: actions/upload-artifact@v4
with:
name: CodeCoverage-Report
path: CodeCoverage/Report
build:
name: Build Windows
runs-on: ubuntu-latest
steps:
# 1. Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
# 2. Cache:缓存 team_project/Library
- uses: actions/cache@v3
id: cache-library-build
with:
path: team_project/Library
key: Library-build-${{ hashFiles('team_project/Assets/**', 'team_project/Packages/**', 'team_project/ProjectSettings/**') }}
restore-keys: |
Library-build-
# 3. Build project(Windows 平台)
- 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:
projectPath: team_project
targetPlatform: StandaloneWindows64
# 4. Upload artifact:指向 Windows 的构建输出目录
- name: Upload Build-Windows
uses: actions/upload-artifact@v4
with:
name: Build-Windows
path: build/StandaloneWindows64
build_webgl:
name: Build WebGL
runs-on: ubuntu-latest
steps:
# 1. Checkout
- name: Checkout repository
uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
# 2. Cache:缓存 team_project/Library
- uses: actions/cache@v3
id: cache-library-build
with:
path: team_project/Library
key: Library-build-${{ hashFiles('team_project/Assets/**', 'team_project/Packages/**', 'team_project/ProjectSettings/**') }}
restore-keys: |
Library-build-
# 3. Build project(WebGL 平台)
- 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:
projectPath: team_project
targetPlatform: WebGL
# 4. Upload artifact:指向 WebGL 的构建输出目录
- name: Upload Build-WebGL
uses: actions/upload-artifact@v4
with:
name: Build-WebGL
path: build/WebGL
- name: Deploy
uses: actions/deploy-pages@v4
with:
artifact_name: Build-WebGL # 与上传名称匹配
docs:
name: Generate and Deploy Documentation
runs-on: ubuntu-latest
# needs: [test, build] # 确保测试和构建先完成
steps:
- name: Checkout repository
uses: actions/checkout@v4 # 使用最新版本
with:
lfs: true
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 9.x
- name: Install DocFX
run: |
dotnet tool update -g docfx --version 2.61.0
- name: Build Documentation
working-directory: team_project # 进入项目目录
run: |
docfx metadata Documentation/docfx.json
docfx build Documentation/docfx.json
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: team_project/_site
name: gh-pages # 自定义名称