Skip to content

Commit bbfcbda

Browse files
authored
Feature/ci cd (#4)
* test: fix utils tests namespace * feat: create CI jobs for testing unity package * fix: main.yml docker version syntax * feat: add missing code in test job * ci: specify python version * ci: ci jobs tweaks * ci: fix package manifest path * ci: several fixes in main.yml * ci: fix docker image and create_unity_project.sh chmod * ci: apt-get not interactive * ci: change from py to sh * fix: unity version outputs * ci: fix job outputs * ci: fix outputs * ci: pass values to GITHUB_ENV * ci: unity version from env * ci: fix GITHUB_ENV path * ci: fix package.json path * ci: share version via outputs * ci: add test workflow to understand outputs issue * ci: possible fix for outputs issue * ci: set artifacts path using substitution * ci: test from package tgz * ci: fix arg passed to python * ci: add debug steps * ci: pass build artifact name * ci: fix outputs path * ci: include package tests in code coverage filter * ci: fix coverage filters
1 parent 12a4e10 commit bbfcbda

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import json
6+
7+
print("Generating Unity manifest...")
8+
9+
packageName = sys.argv[1]
10+
packageFile = sys.argv[2]
11+
12+
os.mkdir("Packages")
13+
14+
manifest = {
15+
"dependencies": {
16+
"com.aaulicino.nsubstitute": "https://github.com/AAulicino/Unity3D-NSubstitute.git",
17+
packageName: f"file:../{packageFile}",
18+
"com.unity.test-framework": "1.1.31",
19+
"com.unity.testtools.codecoverage": "1.1.1",
20+
},
21+
"testables": [packageName],
22+
}
23+
24+
print("Generated Manifest:")
25+
print(json.dumps(manifest, indent=4))
26+
27+
with open("Packages/manifest.json", "w") as file:
28+
json.dump(manifest, file, ensure_ascii=False, indent=4)

.github/workflows/main.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Run Unity Tests
2+
3+
on:
4+
push:
5+
branches: ["main", "develop"]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
env:
10+
UNITY_MANIFEST: Packages/${{ github.event.repository.name }}/package.json
11+
PACKAGE_CONTENTS: ${{ github.event.repository.name }}
12+
SCRIPTS_DIR: .github/scripts
13+
14+
jobs:
15+
build:
16+
name: Build Package
17+
runs-on: ubuntu-latest
18+
outputs:
19+
package-name: ${{ steps.package-name.outputs.PACKAGE_NAME }}
20+
artifact-name: ${{ steps.artifact-name.outputs.ARTIFACT_NAME }}
21+
steps:
22+
- uses: actions/checkout@v3
23+
- run: npm pack
24+
- id: package-name
25+
name: Get Package Name
26+
run: >
27+
echo "::set-output name=PACKAGE_NAME::
28+
$(cat package.json | grep -m 1 -oE '"name":\s*"([^"]*)' | awk -F '"' '{print $4}')"
29+
- id: artifact-name
30+
name: Get Artifact Name
31+
run: echo "::set-output name=ARTIFACT_NAME::$(echo *.tgz)"
32+
- uses: actions/upload-artifact@v3
33+
with:
34+
name: build-artifact
35+
path: ./*.tgz
36+
retention-days: 1
37+
38+
create-unity-project:
39+
name: Create Unity Project
40+
runs-on: ubuntu-latest
41+
needs:
42+
- build
43+
steps:
44+
- uses: actions/checkout@v3
45+
- uses: actions/download-artifact@v3
46+
with:
47+
name: build-artifact
48+
- run: mkdir $PACKAGE_CONTENTS
49+
- uses: actions/setup-python@v4
50+
with:
51+
python-version: "3.8"
52+
- run: $SCRIPTS_DIR/create_unity_manifest.py ${{ needs.build.outputs.package-name }} ${{ needs.build.outputs.artifact-name }}
53+
- uses: actions/upload-artifact@v3
54+
with:
55+
name: unity-project
56+
path: |
57+
Packages
58+
${{ needs.build.outputs.artifact-name }}
59+
retention-days: 1
60+
61+
get-unity-version:
62+
name: Get Unity Version
63+
runs-on: ubuntu-latest
64+
container:
65+
image: unityci/hub:latest
66+
outputs:
67+
unity-version: ${{ steps.get-unity-version.outputs.UNITY_VERSION }}
68+
steps:
69+
- uses: actions/checkout@v3
70+
- id: get-unity-version
71+
run: echo "::set-output name=UNITY_VERSION::$(unity-hub editors --releases | grep $(cat package.json | grep -oE '"unity":\s*"([^"]*)' | awk -F '"' '{print $4}'))"
72+
73+
edit-mode-tests:
74+
name: Edit Mode Tests
75+
runs-on: ubuntu-latest
76+
needs:
77+
- build
78+
- create-unity-project
79+
- get-unity-version
80+
steps:
81+
- uses: actions/download-artifact@v3
82+
with:
83+
name: unity-project
84+
- uses: actions/cache@v3
85+
with:
86+
path: Library/
87+
key: unity-ci-cache
88+
- run: mkdir Assets
89+
- uses: game-ci/unity-test-runner@v2
90+
id: tests
91+
env:
92+
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
93+
with:
94+
githubToken: ${{ secrets.GITHUB_TOKEN }}
95+
testMode: editmode
96+
unityVersion: ${{ needs.get-unity-version.outputs.unity-version }}
97+
coverageOptions: "generateAdditionalMetrics;generateHtmlReport;generateHtmlReportHistory;generateBadgeReport;assemblyFilters:+<project>;pathFilters:+**/PackageCache/${{ needs.build.outputs.package-name }}*/**"
98+
- uses: actions/upload-artifact@v3
99+
if: always()
100+
with:
101+
name: Test results
102+
path: ${{ steps.tests.outputs.artifactsPath }}
103+
- uses: actions/upload-artifact@v3
104+
if: always()
105+
with:
106+
name: Coverage results for edit mode
107+
path: ${{ steps.tests.outputs.coveragePath }}

Tests/Editor/Substitute/Utils/CoroutineExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using UnityEngine;
44

5-
namespace CoroutineSubstitute.UnitTests.Utils
5+
namespace CoroutineSubstitute.Tests.Utils
66
{
77
public class CoroutineExtensionsTests
88
{

Tests/Editor/Substitute/Utils/CoroutineFactoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using NUnit.Framework;
33
using UnityEngine;
44

5-
namespace CoroutineSubstitute.UnitTests.Utils
5+
namespace CoroutineSubstitute.Tests.Utils
66
{
77
public class CoroutineFactoryTests
88
{

0 commit comments

Comments
 (0)