mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-01-29 06:20:07 +08:00
Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da74d9ff8c | ||
|
|
c8a0e2865a | ||
|
|
627cf8f914 | ||
|
|
e9b4db003e | ||
|
|
45a1728dfb | ||
|
|
f854b54cb0 | ||
|
|
6948da8f6a | ||
|
|
922dcd8b1a | ||
|
|
c8909e4d5e | ||
|
|
060d1856e7 | ||
|
|
6bacc4484e | ||
|
|
892b3b8279 | ||
|
|
00afc45f14 | ||
|
|
868c383d7f | ||
|
|
54d8d414ea | ||
|
|
057deedeb0 | ||
|
|
d64e5a8b19 | ||
|
|
711a3ee644 | ||
|
|
39da97ffa3 | ||
|
|
1473c8f431 | ||
|
|
c210544758 | ||
|
|
f863c717a4 | ||
|
|
5423e61ad7 | ||
|
|
377244a880 | ||
|
|
6f1c3ded0c | ||
|
|
b181c9cdbe | ||
|
|
d5a5335100 | ||
|
|
c937b9ed6c | ||
|
|
56b8c04f36 | ||
|
|
a18b837919 | ||
|
|
033a0990cb | ||
|
|
24fe88806a | ||
|
|
e2f2badc29 | ||
|
|
3ccd77fd44 | ||
|
|
686f633329 | ||
|
|
28154ea36e | ||
|
|
2ca91788af | ||
|
|
2d11601618 | ||
|
|
545600f75b | ||
|
|
d6c937fe37 | ||
|
|
d105f8c891 | ||
|
|
048c75a66e | ||
|
|
a08a398026 | ||
|
|
311b685893 |
21
.editorconfig
Normal file
21
.editorconfig
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 100
|
||||||
|
tab_width = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = off
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{yml,yaml}]
|
||||||
|
max_line_length = off
|
||||||
|
|
||||||
|
[COMMIT_EDITMSG]
|
||||||
|
max_line_length = off
|
||||||
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
**/node_modules/**
|
||||||
|
**/action/**
|
||||||
21
.eslintrc.json
Normal file
21
.eslintrc.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2020,
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"impliedStrict": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extends": ["airbnb", "plugin:unicorn/recommended", "prettier"],
|
||||||
|
"plugins": ["react", "jsx-a11y", "import", "prettier", "flowtype", "unicorn"],
|
||||||
|
"settings": { "react": { "version": "latest" } },
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"import/no-extraneous-dependencies": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
196
.github/workflows/main.yml
vendored
196
.github/workflows/main.yml
vendored
@@ -3,29 +3,95 @@ on:
|
|||||||
pull_request: {}
|
pull_request: {}
|
||||||
push: { branches: [master] }
|
push: { branches: [master] }
|
||||||
|
|
||||||
|
env:
|
||||||
|
UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n <Binding Key=\"2\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n </MachineBindings>\n <MachineID Value=\"Xxo1ZKbdPu/IATrc0mPBYANJFF0=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2019-11-25T18:23:38\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.2.11f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>JHdOBFmBNq2H8BrGFzir/StLoYo=</DigestValue></Reference></SignedInfo><SignatureValue>aENLHd37a51RtP2/g7YU0Pexf5mx0/ENXYGtrPzqwZ8NQt2AsSdxGnl0CUB45/GuNXfJVDt2HWot\ncNYZB2OylVBn1WHQbKZlPmm8gEAMz0MYbr4Isb5i5buryBrZlmbEOjnRI+pEg1CBwlgMo6xdtjjE\n/d7cC293QIUO91kdzRXftYou1dNaUyuPL9ZH65vdB2pDXGRNxgUVD+GnnqZA7b5L2HXqNQclcWAK\n5Yd1BeF3VzR1iLw9G/SmH5oOhnpXSmqbL4qk7LVP2/mgXpFk5kP4X8VC3z47obNhBIGq40dwWyEe\nUYk5/nRAOkZawDT+tcu96e06gPC9Cxk5PdbRbA==</SignatureValue></Signature></root>"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
tests:
|
||||||
|
name: Tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v1.1.2
|
||||||
|
with:
|
||||||
|
node-version: 12.x
|
||||||
|
- run: yarn
|
||||||
|
- run: yarn lint
|
||||||
|
- run: yarn test
|
||||||
|
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
|
||||||
|
- run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; exit 62; }
|
||||||
|
|
||||||
|
testAllModesLikeInTheReadme:
|
||||||
|
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- unity-project-with-correct-tests
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
testMode:
|
||||||
|
- playmode
|
||||||
|
- editmode
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
lfs: true
|
||||||
|
- uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ${{ matrix.projectPath }}/Library
|
||||||
|
key: Library-${{ matrix.projectPath }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-
|
||||||
|
- uses: ./
|
||||||
|
id: tests
|
||||||
|
with:
|
||||||
|
projectPath: ${{ matrix.projectPath }}
|
||||||
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
|
testMode: ${{ matrix.testMode }}
|
||||||
|
artifactsPath: ${{ matrix.testMode }}-artifacts
|
||||||
|
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Test results for ${{ matrix.testMode }}
|
||||||
|
path: ${{ steps.tests.outputs.artifactsPath }}
|
||||||
|
|
||||||
testRunnerInAllModes:
|
testRunnerInAllModes:
|
||||||
name: Test all modes ✨
|
name: Test all modes ✨
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- unity-project-with-correct-tests
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
steps:
|
steps:
|
||||||
# Checkout repository (required to test local actions)
|
# Checkout repository (required to test local actions)
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
lfs: true
|
||||||
|
|
||||||
# Activate license
|
# Enable caching
|
||||||
- name: Activate Unity
|
- uses: actions/cache@v1.1.0
|
||||||
uses: webbertakken/unity-activate@v1
|
with:
|
||||||
env:
|
path: ${{ matrix.projectPath }}/Library
|
||||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-${{ matrix.projectPath }}-
|
||||||
|
Library-
|
||||||
|
|
||||||
# Configure test runner
|
# Configure test runner
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
id: allTests
|
id: allTests
|
||||||
uses: ./
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TEST_MODE: all
|
projectPath: ${{ matrix.projectPath }}
|
||||||
PROJECT_PATH: unity-project-with-correct-tests
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
# Test implicit ARTIFACTS_PATH, by not setting it
|
testMode: all
|
||||||
|
# Test implicit artifactsPath, by not setting it
|
||||||
|
|
||||||
# Upload artifacts
|
# Upload artifacts
|
||||||
- name: Upload test results
|
- name: Upload test results
|
||||||
@@ -37,25 +103,38 @@ jobs:
|
|||||||
testRunnerInEditMode:
|
testRunnerInEditMode:
|
||||||
name: Test edit mode 📝
|
name: Test edit mode 📝
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
projectPath:
|
||||||
|
- unity-project-with-correct-tests
|
||||||
steps:
|
steps:
|
||||||
# Checkout repository (required to test local actions)
|
# Checkout repository (required to test local actions)
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
lfs: true
|
||||||
|
|
||||||
# Activate license
|
# Enable caching
|
||||||
- name: Activate Unity
|
- uses: actions/cache@v1.1.0
|
||||||
uses: webbertakken/unity-activate@v1
|
with:
|
||||||
env:
|
path: ${{ matrix.projectPath }}/Library
|
||||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-${{ matrix.projectPath }}-
|
||||||
|
Library-
|
||||||
|
|
||||||
# Configure test runner
|
# Configure test runner
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
id: editMode
|
id: editMode
|
||||||
uses: ./
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TEST_MODE: editmode
|
projectPath: ${{ matrix.projectPath }}
|
||||||
PROJECT_PATH: unity-project-with-correct-tests
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
ARTIFACTS_PATH: artifacts/editmode
|
testMode: editmode
|
||||||
|
artifactsPath: artifacts/editmode
|
||||||
|
|
||||||
# Upload artifacts
|
# Upload artifacts
|
||||||
- name: Upload test results
|
- name: Upload test results
|
||||||
@@ -67,25 +146,38 @@ jobs:
|
|||||||
testRunnerInPlayMode:
|
testRunnerInPlayMode:
|
||||||
name: Test play mode 📺
|
name: Test play mode 📺
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- unity-project-with-correct-tests
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
steps:
|
steps:
|
||||||
# Checkout repository (required to test local actions)
|
# Checkout repository (required to test local actions)
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
lfs: true
|
||||||
|
|
||||||
# Activate license
|
# Enable caching
|
||||||
- name: Activate Unity
|
- uses: actions/cache@v1.1.0
|
||||||
uses: webbertakken/unity-activate@v1
|
with:
|
||||||
env:
|
path: ${{ matrix.projectPath }}/Library
|
||||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-${{ matrix.projectPath }}-
|
||||||
|
Library-
|
||||||
|
|
||||||
# Configure test runner
|
# Configure test runner
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
id: playMode
|
id: playMode
|
||||||
uses: ./
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TEST_MODE: playmode
|
projectPath: ${{ matrix.projectPath }}
|
||||||
PROJECT_PATH: unity-project-with-correct-tests
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
ARTIFACTS_PATH: artifacts/editmode
|
testMode: playmode
|
||||||
|
artifactsPath: artifacts/playmode
|
||||||
|
|
||||||
# Upload artifacts
|
# Upload artifacts
|
||||||
- name: Upload test results
|
- name: Upload test results
|
||||||
@@ -94,35 +186,49 @@ jobs:
|
|||||||
name: Test results (play mode)
|
name: Test results (play mode)
|
||||||
path: ${{ steps.playMode.outputs.artifactsPath }}
|
path: ${{ steps.playMode.outputs.artifactsPath }}
|
||||||
|
|
||||||
testRunnerInEachModeSeparately:
|
testEachModeSequentially:
|
||||||
name: Test each mode sequentially 👩👩👧👦 # don't try this at home (it's much slower)
|
name: Test each mode sequentially 👩👩👧👦 # don't try this at home (it's much slower)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
projectPath:
|
||||||
|
- unity-project-with-correct-tests
|
||||||
steps:
|
steps:
|
||||||
# Checkout repository (required to test local actions)
|
# Checkout repository (required to test local actions)
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
lfs: true
|
||||||
|
|
||||||
# Activate license
|
# Enable caching
|
||||||
- name: Activate Unity
|
- uses: actions/cache@v1.1.0
|
||||||
uses: webbertakken/unity-activate@v1
|
with:
|
||||||
env:
|
path: ${{ matrix.projectPath }}/Library
|
||||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-${{ matrix.projectPath }}-
|
||||||
|
Library-
|
||||||
|
|
||||||
# Configure first test runner
|
# Configure first test runner
|
||||||
- name: Tests in editmode 📝
|
- name: Tests in editmode 📝
|
||||||
uses: ./
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TEST_MODE: editmode
|
projectPath: ${{ matrix.projectPath }}
|
||||||
PROJECT_PATH: unity-project-with-correct-tests
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
ARTIFACTS_PATH: artifacts/editmode
|
testMode: editmode
|
||||||
|
artifactsPath: artifacts/editmode
|
||||||
|
|
||||||
# Configure second test runner
|
# Configure second test runner
|
||||||
- name: Tests in playmode 📺
|
- name: Tests in playmode 📺
|
||||||
uses: ./
|
uses: ./
|
||||||
env:
|
with:
|
||||||
TEST_MODE: playmode
|
projectPath: ${{ matrix.projectPath }}
|
||||||
PROJECT_PATH: unity-project-with-correct-tests
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
ARTIFACTS_PATH: artifacts/playmode
|
testMode: playmode
|
||||||
|
artifactsPath: artifacts/playmode
|
||||||
|
|
||||||
# Upload combined artifacts
|
# Upload combined artifacts
|
||||||
- name: Upload combined test results
|
- name: Upload combined test results
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.idea
|
.idea
|
||||||
|
node_modules
|
||||||
|
|||||||
2
.prettierignore
Normal file
2
.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
**/node_modules/**
|
||||||
|
**/action/**
|
||||||
6
.prettierrc.json
Normal file
6
.prettierrc.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"printWidth": 100
|
||||||
|
}
|
||||||
3
.yarnrc
Normal file
3
.yarnrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
save-prefix ""
|
||||||
|
--install.audit true
|
||||||
|
--add.audit true
|
||||||
76
CODE_OF_CONDUCT.md
Normal file
76
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
In the interest of fostering an open and welcoming environment, we as
|
||||||
|
contributors and maintainers pledge to making participation in our project and
|
||||||
|
our community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||||
|
level of experience, education, socio-economic status, nationality, personal
|
||||||
|
appearance, race, religion, or sexual identity and orientation.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to creating a positive environment
|
||||||
|
include:
|
||||||
|
|
||||||
|
- Using welcoming and inclusive language
|
||||||
|
- Being respectful of differing viewpoints and experiences
|
||||||
|
- Gracefully accepting constructive criticism
|
||||||
|
- Focusing on what is best for the community
|
||||||
|
- Showing empathy towards other community members
|
||||||
|
|
||||||
|
Examples of unacceptable behavior by participants include:
|
||||||
|
|
||||||
|
- The use of sexualized language or imagery and unwelcome sexual attention or
|
||||||
|
advances
|
||||||
|
- Trolling, insulting/derogatory comments, and personal or political attacks
|
||||||
|
- Public or private harassment
|
||||||
|
- Publishing others' private information, such as a physical or electronic
|
||||||
|
address, without explicit permission
|
||||||
|
- Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Our Responsibilities
|
||||||
|
|
||||||
|
Project maintainers are responsible for clarifying the standards of acceptable
|
||||||
|
behavior and are expected to take appropriate and fair corrective action in
|
||||||
|
response to any instances of unacceptable behavior.
|
||||||
|
|
||||||
|
Project maintainers have the right and responsibility to remove, edit, or
|
||||||
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||||
|
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||||
|
permanently any contributor for other behaviors that they deem inappropriate,
|
||||||
|
threatening, offensive, or harmful.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies both within project spaces and in public spaces
|
||||||
|
when an individual is representing the project or its community. Examples of
|
||||||
|
representing a project or community include using an official project e-mail
|
||||||
|
address, posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event. Representation of a project may be
|
||||||
|
further defined and clarified by project maintainers.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported by contacting the project team at webber@takken.io. All
|
||||||
|
complaints will be reviewed and investigated and will result in a response that
|
||||||
|
is deemed necessary and appropriate to the circumstances. The project team is
|
||||||
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||||
|
Further details of specific enforcement policies may be posted separately.
|
||||||
|
|
||||||
|
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||||
|
faith may face temporary or permanent repercussions as determined by other
|
||||||
|
members of the project's leadership.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||||
|
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see
|
||||||
|
https://www.contributor-covenant.org/faq
|
||||||
39
CONTRIBUTING.md
Normal file
39
CONTRIBUTING.md
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
## How to Contribute
|
||||||
|
|
||||||
|
#### Code of Conduct
|
||||||
|
|
||||||
|
This repository has adopted the Contributor Covenant as it's
|
||||||
|
Code of Conduct. It is expected that participants adhere to it.
|
||||||
|
|
||||||
|
#### Proposing a Change
|
||||||
|
|
||||||
|
If you are unsure about whether or not a change is desired,
|
||||||
|
you can create an issue. This is useful because it creates
|
||||||
|
the possibility for a discussion that's visible to everyone.
|
||||||
|
|
||||||
|
When fixing a bug it is fine to submit a pull request right away.
|
||||||
|
|
||||||
|
#### Sending a Pull Request
|
||||||
|
|
||||||
|
Steps to be performed to submit a pull request:
|
||||||
|
|
||||||
|
1. Fork the repository and create your branch from `master`.
|
||||||
|
2. Run `yarn` in the repository root.
|
||||||
|
3. If you've fixed a bug or added code that should be tested, add tests!
|
||||||
|
4. Fill out the description, link any related issues and submit your pull request.
|
||||||
|
|
||||||
|
#### Pull Request Prerequisites
|
||||||
|
|
||||||
|
You have [Node](https://nodejs.org/) installed at v12.2.0+ and [Yarn](https://yarnpkg.com/) at v1.18.0+.
|
||||||
|
|
||||||
|
Please note that commit hooks will run automatically to perform some tasks;
|
||||||
|
|
||||||
|
- format your code
|
||||||
|
- run tests
|
||||||
|
- build distributable files
|
||||||
|
|
||||||
|
#### License
|
||||||
|
|
||||||
|
By contributing to this repository, you agree that your contributions will be licensed under its MIT license.
|
||||||
272
README.md
272
README.md
@@ -1,81 +1,263 @@
|
|||||||
# Unity - Test runner
|
# Unity - Test runner
|
||||||
[](https://github.com/webbertakken/unity-test-runner/actions?query=branch%3Amaster+workflow%3A%22Actions+%F0%9F%98%8E%22)
|
|
||||||
|
[](https://github.com/webbertakken/unity-test-runner/actions?query=branch%3Amaster+event%3Apush+workflow%3A"Actions%20%F0%9F%98%8E")
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
GitHub Action to
|
GitHub Action to
|
||||||
[run tests](https://github.com/marketplace/actions/unity-test-runner)
|
[run tests](https://github.com/marketplace/actions/unity-test-runner)
|
||||||
for any Unity project.
|
for any Unity project.
|
||||||
|
|
||||||
Part of the
|
Part of the
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
collection.
|
collection.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This is a recommended step to prepare your pipeline for using the
|
This is a recommended step to prepare your pipeline for using the
|
||||||
[Build](https://github.com/webbertakken/unity-actions#build)
|
[Build](https://github.com/webbertakken/unity-actions#build)
|
||||||
action. This action also requires the [activation](https://github.com/marketplace/actions/unity-activate) step.
|
action.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
See the
|
See the
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
collection repository for workflow documentation and reference implementation.
|
collection repository for workflow documentation and reference implementation.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
#### Setup test runner
|
||||||
|
|
||||||
|
By default the test runner will run all your playmode and editmode tests.
|
||||||
|
|
||||||
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
||||||
|
|
||||||
|
##### Personal License
|
||||||
|
|
||||||
|
Personal licenses require a one-time manual activation step (per unity version).
|
||||||
|
|
||||||
|
Make sure you
|
||||||
|
[acquire and activate](https://github.com/marketplace/actions/unity-request-activation-file)
|
||||||
|
your license file and add it as a secret.
|
||||||
|
|
||||||
|
Then, define the test step as follows:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Test project
|
- uses: webbertakken/unity-test-runner@v1.4
|
||||||
on: [push]
|
env:
|
||||||
|
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||||
|
with:
|
||||||
|
projectPath: path/to/your/project
|
||||||
|
unityVersion: 20XX.X.XXXX
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Professional license
|
||||||
|
|
||||||
|
Professional licenses do not need any manual steps.
|
||||||
|
|
||||||
|
Instead, three variables will need to be set.
|
||||||
|
|
||||||
|
- `UNITY_EMAIL` (should contain the email address for your Unity account)
|
||||||
|
- `UNITY_PASSWORD` (the password that you use to login to Unity)
|
||||||
|
- `UNITY_SERIAL` (the serial provided by Unity)
|
||||||
|
|
||||||
|
Define the test step as follows:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: webbertakken/unity-test-runner@v1.4
|
||||||
|
env:
|
||||||
|
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
|
||||||
|
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
|
||||||
|
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
|
||||||
|
with:
|
||||||
|
projectPath: path/to/your/project
|
||||||
|
unityVersion: 20XX.X.XXXX
|
||||||
|
```
|
||||||
|
|
||||||
|
That is all you need to test your project.
|
||||||
|
|
||||||
|
#### Storing test results
|
||||||
|
|
||||||
|
To be able to access the test results,
|
||||||
|
they need to be uploaded as artifacts.
|
||||||
|
To do this it is recommended to use Github Actions official
|
||||||
|
[upload artifact action](https://github.com/marketplace/actions/upload-artifact)
|
||||||
|
after any test action.
|
||||||
|
|
||||||
|
###### Using defaults
|
||||||
|
|
||||||
|
By default, Test Runner outputs it's results to a folder named `artifacts`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Test results
|
||||||
|
path: artifacts
|
||||||
|
```
|
||||||
|
|
||||||
|
Test results can now be downloaded as Artifacts in the Actions tab.
|
||||||
|
|
||||||
|
###### Specifying artifacts folder
|
||||||
|
|
||||||
|
If a different `artifactsPath` was specified in the test runner,
|
||||||
|
you can reference this path using the `id` of the test step.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: webbertakken/unity-test-runner@v1.4
|
||||||
|
id: myTestStep
|
||||||
|
(...)
|
||||||
|
```
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Test results
|
||||||
|
path: ${{ steps.myTestStep.outputs.artifactsPath }}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Caching
|
||||||
|
|
||||||
|
In order to make test runs (and builds) faster,
|
||||||
|
you can cache Library files from previous runs.
|
||||||
|
To do so, simply add Github Actions' official
|
||||||
|
[cache action](https://github.com/marketplace/actions/cache)
|
||||||
|
before any unity steps.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: path/to/your/project/Library
|
||||||
|
key: Library-MyProjectName-TargetPlatform
|
||||||
|
restore-keys: |
|
||||||
|
Library-MyProjectName-
|
||||||
|
Library-
|
||||||
|
```
|
||||||
|
|
||||||
|
This simple addition could speed up your test runs by more than 50%.
|
||||||
|
|
||||||
|
#### Complete example
|
||||||
|
|
||||||
|
A complete workflow that tests all modes separately could look like this:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
name: Build project
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request: {}
|
||||||
|
push: { branches: [master] }
|
||||||
|
|
||||||
|
env:
|
||||||
|
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
testRunnerInAllModes:
|
testAllModes:
|
||||||
name: Test all modes ✨
|
name: Test in ${{ matrix.testMode }} on version ${{ matrix.unityVersion }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- path/to/your/project
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
testMode:
|
||||||
|
- playmode
|
||||||
|
- editmode
|
||||||
steps:
|
steps:
|
||||||
```
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
Configure the test runner as follows:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Configure test runner
|
|
||||||
- name: Run tests
|
|
||||||
id: myTestStep
|
|
||||||
uses: webbertakken/unity-test-runner@v1.1
|
|
||||||
env:
|
|
||||||
# Choose: "all", "playmode", "editmode"
|
|
||||||
TEST_MODE: all
|
|
||||||
|
|
||||||
# Optional: Path to your project, leave blank for "./"
|
|
||||||
PROJECT_PATH: relative/path/to/your/project
|
|
||||||
|
|
||||||
# Optional: Artifacts path, leave blank for "artifacts"
|
|
||||||
ARTIFACTS_PATH: store/artifacts/here
|
|
||||||
```
|
|
||||||
|
|
||||||
You use the id to **upload the artifacts** like so:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Upload artifacts
|
|
||||||
- name: Upload test results
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
with:
|
||||||
name: Test results
|
lfs: true
|
||||||
path: ${{ steps.myTestStep.outputs.artifactsPath }}
|
- uses: actions/cache@v1.1.0
|
||||||
|
with:
|
||||||
|
path: ${{ matrix.projectPath }}/Library
|
||||||
|
key: Library-${{ matrix.projectPath }}
|
||||||
|
restore-keys: |
|
||||||
|
Library-
|
||||||
|
- uses: webbertakken/unity-test-runner@v1.4
|
||||||
|
id: tests
|
||||||
|
with:
|
||||||
|
projectPath: ${{ matrix.projectPath }}
|
||||||
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
|
testMode: ${{ matrix.testMode }}
|
||||||
|
artifactsPath: ${{ matrix.testMode }}-artifacts
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
with:
|
||||||
|
name: Test results for ${{ matrix.testMode }}
|
||||||
|
path: ${{ steps.tests.outputs.artifactsPath }}
|
||||||
```
|
```
|
||||||
|
|
||||||
Commit and push your workflow definition.
|
> **Note:** _Environment variables are set for all jobs in the workflow like this._
|
||||||
|
|
||||||
|
## Configuration options
|
||||||
|
|
||||||
|
Below options can be specified under `with:` for the `unity-test-runner` action.
|
||||||
|
|
||||||
|
#### projectPath
|
||||||
|
|
||||||
|
Specify the path to your Unity project to be tested.
|
||||||
|
The path should be relative to the root of your project.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `<your project root>`_
|
||||||
|
|
||||||
|
#### unityVersion
|
||||||
|
|
||||||
|
Version of Unity to use for testing the project.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `2019.2.1f11`_
|
||||||
|
|
||||||
|
#### testMode
|
||||||
|
|
||||||
|
The type of tests to be run by the test runner.
|
||||||
|
|
||||||
|
Options are: "all", "playmode", "editmode"
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `all`_
|
||||||
|
|
||||||
|
#### artifactsPath
|
||||||
|
|
||||||
|
Path where the test results should be stored.
|
||||||
|
|
||||||
|
In this folder a folder will be created for every test mode.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `artifacts`_
|
||||||
|
|
||||||
|
#### customParameters
|
||||||
|
|
||||||
|
Custom parameters to configure the test runner.
|
||||||
|
|
||||||
|
Parameters must start with a hyphen (`-`) and may be followed by a value (without hyphen).
|
||||||
|
|
||||||
|
Parameters without a value will be considered booleans (with a value of true).
|
||||||
|
|
||||||
|
_**example:**_
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: webbertakken/unity-test-runner@master
|
||||||
|
with:
|
||||||
|
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
|
||||||
|
```
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** ""_
|
||||||
|
|
||||||
## More actions
|
## More actions
|
||||||
|
|
||||||
Visit
|
Visit
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
to find related actions for Unity.
|
to find related actions for Unity.
|
||||||
|
|
||||||
Feel free to contribute.
|
Feel free to contribute.
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
[MIT](./LICENSE)
|
[MIT](./LICENSE)
|
||||||
|
|||||||
12
action.yml
12
action.yml
@@ -1,13 +1,17 @@
|
|||||||
name: 'Unity - Test runner'
|
name: 'Unity - Test runner'
|
||||||
author: Webber Takken <webber@takken.io>
|
author: Webber Takken <webber@takken.io>
|
||||||
description: 'Run tests for any Unity project.'
|
description: 'Run tests for any Unity project.'
|
||||||
inputs: {}
|
inputs:
|
||||||
|
unityVersion:
|
||||||
|
required: false
|
||||||
|
default: '2019.2.11f1'
|
||||||
|
description: 'Version of unity to use for testing the project.'
|
||||||
outputs:
|
outputs:
|
||||||
artifactsPath:
|
artifactsPath:
|
||||||
description: 'Path where the artifacts are stored'
|
description: 'Path where the artifacts are stored'
|
||||||
runs:
|
|
||||||
using: 'docker'
|
|
||||||
image: 'Dockerfile'
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'box'
|
icon: 'box'
|
||||||
color: 'gray-dark'
|
color: 'gray-dark'
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'action/index.js'
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
FROM gableroux/unity3d:2019.2.11f1
|
ARG IMAGE
|
||||||
|
FROM $IMAGE
|
||||||
|
|
||||||
LABEL "com.github.actions.name"="Unity - Test runner"
|
LABEL "com.github.actions.name"="Unity - Test runner"
|
||||||
LABEL "com.github.actions.description"="Run tests for any Unity project."
|
LABEL "com.github.actions.description"="Run tests for any Unity project."
|
||||||
@@ -9,6 +10,8 @@ LABEL "repository"="http://github.com/webbertakken/unity-actions"
|
|||||||
LABEL "homepage"="http://github.com/webbertakken/unity-actions"
|
LABEL "homepage"="http://github.com/webbertakken/unity-actions"
|
||||||
LABEL "maintainer"="Webber Takken <webber@takken.io>"
|
LABEL "maintainer"="Webber Takken <webber@takken.io>"
|
||||||
|
|
||||||
|
ADD steps /steps
|
||||||
|
RUN chmod -R +x /steps
|
||||||
ADD entrypoint.sh /entrypoint.sh
|
ADD entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
15
action/entrypoint.sh
Normal file
15
action/entrypoint.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# Run steps
|
||||||
|
#
|
||||||
|
|
||||||
|
source /steps/activate.sh
|
||||||
|
source /steps/run_tests.sh
|
||||||
|
source /steps/return_license.sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Exit with code from the build step.
|
||||||
|
#
|
||||||
|
|
||||||
|
exit $TEST_RUNNER_EXIT_CODE
|
||||||
1
action/index.js
Normal file
1
action/index.js
Normal file
File diff suppressed because one or more lines are too long
101
action/steps/activate.sh
Normal file
101
action/steps/activate.sh
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ -n "$UNITY_LICENSE" ]]; then
|
||||||
|
#
|
||||||
|
# PERSONAL LICENSE MODE
|
||||||
|
#
|
||||||
|
# This will activate Unity, using a license file
|
||||||
|
#
|
||||||
|
# Note that this is the ONLY WAY for PERSONAL LICENSES in 2020.
|
||||||
|
# * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478
|
||||||
|
#
|
||||||
|
# The license file can be acquired using `webbertakken/request-manual-activation-file` action.
|
||||||
|
echo "Requesting activation (personal license)"
|
||||||
|
|
||||||
|
# Set the license file path
|
||||||
|
FILE_PATH=UnityLicenseFile.ulf
|
||||||
|
|
||||||
|
# Copy license file from Github variables
|
||||||
|
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
|
||||||
|
|
||||||
|
# Activate license
|
||||||
|
ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||||
|
/opt/Unity/Editor/Unity \
|
||||||
|
-batchmode \
|
||||||
|
-nographics \
|
||||||
|
-logFile /dev/stdout \
|
||||||
|
-quit \
|
||||||
|
-manualLicenseFile $FILE_PATH)
|
||||||
|
|
||||||
|
# Store the exit code from the verify command
|
||||||
|
UNITY_EXIT_CODE=$?
|
||||||
|
|
||||||
|
# The exit code for personal activation is always 1;
|
||||||
|
# Determine whether activation was successful.
|
||||||
|
#
|
||||||
|
# Successful output should include the following:
|
||||||
|
#
|
||||||
|
# "LICENSE SYSTEM [2020120 18:51:20] Next license update check is after 2019-11-25T18:23:38"
|
||||||
|
#
|
||||||
|
ACTIVATION_SUCCESSFUL=$(echo $ACTIVATION_OUTPUT | grep 'Next license update check is after' | wc -l)
|
||||||
|
|
||||||
|
# Set exit code to 0 if activation was successful
|
||||||
|
if [[ $ACTIVATION_SUCCESSFUL -eq 1 ]]; then
|
||||||
|
UNITY_EXIT_CODE=0
|
||||||
|
fi;
|
||||||
|
|
||||||
|
# Remove license file
|
||||||
|
rm -f $FILE_PATH
|
||||||
|
|
||||||
|
elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
|
||||||
|
#
|
||||||
|
# PROFESSIONAL (SERIAL) LICENSE MODE
|
||||||
|
#
|
||||||
|
# This will activate unity, using the activating process.
|
||||||
|
#
|
||||||
|
# Note: This is the preferred way for PROFESSIONAL LICENSES.
|
||||||
|
#
|
||||||
|
echo "Requesting activation (professional license)"
|
||||||
|
|
||||||
|
# Activate license
|
||||||
|
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||||
|
/opt/Unity/Editor/Unity \
|
||||||
|
-batchmode \
|
||||||
|
-nographics \
|
||||||
|
-logFile /dev/stdout \
|
||||||
|
-quit \
|
||||||
|
-serial "$UNITY_SERIAL" \
|
||||||
|
-username "$UNITY_EMAIL" \
|
||||||
|
-password "$UNITY_PASSWORD"
|
||||||
|
|
||||||
|
# Store the exit code from the verify command
|
||||||
|
UNITY_EXIT_CODE=$?
|
||||||
|
|
||||||
|
else
|
||||||
|
#
|
||||||
|
# NO LICENSE ACTIVATION STRATEGY MATCHED
|
||||||
|
#
|
||||||
|
# This will exit since no activation strategies could be matched.
|
||||||
|
#
|
||||||
|
echo "License activation strategy could not be determined."
|
||||||
|
echo ""
|
||||||
|
echo "Visit https://github.com/webbertakken/unity-builder#usage for more"
|
||||||
|
echo "details on how to set up one of the possible activation strategies."
|
||||||
|
|
||||||
|
# Immediately exit as no UNITY_EXIT_CODE can be derrived.
|
||||||
|
exit 1;
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
#
|
||||||
|
# Display information about the result
|
||||||
|
#
|
||||||
|
if [ $UNITY_EXIT_CODE -eq 0 ]; then
|
||||||
|
# Activation was a success
|
||||||
|
echo "Activation complete."
|
||||||
|
else
|
||||||
|
# Activation failed so exit with the code from the license verification step
|
||||||
|
echo "Unclassified error occured while trying to activate license."
|
||||||
|
echo "Exit code was: $UNITY_EXIT_CODE"
|
||||||
|
exit $UNITY_EXIT_CODE
|
||||||
|
fi
|
||||||
16
action/steps/return_license.sh
Normal file
16
action/steps/return_license.sh
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
if [[ -n "$UNITY_SERIAL" ]]; then
|
||||||
|
#
|
||||||
|
# PROFESSIONAL (SERIAL) LICENSE MODE
|
||||||
|
#
|
||||||
|
# This will return the license that is currently in use.
|
||||||
|
#
|
||||||
|
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||||
|
/opt/Unity/Editor/Unity \
|
||||||
|
-batchmode \
|
||||||
|
-nographics \
|
||||||
|
-logFile /dev/stdout \
|
||||||
|
-quit \
|
||||||
|
-returnlicense
|
||||||
|
fi
|
||||||
@@ -1,14 +1,24 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Set the license file path
|
#
|
||||||
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
|
# Set and display project path
|
||||||
|
#
|
||||||
|
|
||||||
# Set the artifacts path
|
UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH"
|
||||||
if [ -z "$ARTIFACTS_PATH" ]; then
|
echo "Using project path \"$UNITY_PROJECT_PATH\"."
|
||||||
ARTIFACTS_PATH=artifacts
|
|
||||||
fi
|
#
|
||||||
|
# Set and display the artifacts path
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results."
|
||||||
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH
|
FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH
|
||||||
|
|
||||||
|
#
|
||||||
|
# Display custom parameters
|
||||||
|
#
|
||||||
|
echo "Using custom parameters $CUSTOM_PARAMETERS."
|
||||||
|
|
||||||
# Set the modes for testing
|
# Set the modes for testing
|
||||||
case $TEST_MODE in
|
case $TEST_MODE in
|
||||||
editmode)
|
editmode)
|
||||||
@@ -29,6 +39,12 @@ esac
|
|||||||
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
|
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
|
||||||
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
|
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
|
||||||
|
|
||||||
|
#
|
||||||
|
# Display the unity version
|
||||||
|
#
|
||||||
|
|
||||||
|
echo "Using Unity version \"$UNITY_VERSION\" to test."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Overall info
|
# Overall info
|
||||||
#
|
#
|
||||||
@@ -65,7 +81,8 @@ if [ $EDIT_MODE = true ]; then
|
|||||||
-projectPath "$UNITY_PROJECT_PATH" \
|
-projectPath "$UNITY_PROJECT_PATH" \
|
||||||
-runTests \
|
-runTests \
|
||||||
-testPlatform editmode \
|
-testPlatform editmode \
|
||||||
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml"
|
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
||||||
|
$CUSTOM_PARAMETERS
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
EDIT_MODE_EXIT_CODE=$?
|
EDIT_MODE_EXIT_CODE=$?
|
||||||
@@ -99,7 +116,8 @@ if [ $PLAY_MODE = true ]; then
|
|||||||
-projectPath "$UNITY_PROJECT_PATH" \
|
-projectPath "$UNITY_PROJECT_PATH" \
|
||||||
-runTests \
|
-runTests \
|
||||||
-testPlatform playmode \
|
-testPlatform playmode \
|
||||||
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml"
|
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
||||||
|
$CUSTOM_PARAMETERS
|
||||||
|
|
||||||
# Catch exit code
|
# Catch exit code
|
||||||
PLAY_MODE_EXIT_CODE=$?
|
PLAY_MODE_EXIT_CODE=$?
|
||||||
@@ -147,21 +165,14 @@ if [ $PLAY_MODE = true ]; then
|
|||||||
cat "$FULL_ARTIFACTS_PATH/playmode-results.xml" | grep test-run | grep Passed
|
cat "$FULL_ARTIFACTS_PATH/playmode-results.xml" | grep test-run | grep Passed
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#
|
|
||||||
# Output variables
|
|
||||||
#
|
|
||||||
|
|
||||||
# Set resulting name as output variable
|
|
||||||
echo ::set-output name=artifactsPath::$ARTIFACTS_PATH
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Exit
|
# Exit
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ $EDIT_MODE_EXIT_CODE -gt 0 ]; then
|
if [ $EDIT_MODE_EXIT_CODE -gt 0 ]; then
|
||||||
exit $EDIT_MODE_EXIT_CODE
|
TEST_RUNNER_EXIT_CODE=$EDIT_MODE_EXIT_CODE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $PLAY_MODE_EXIT_CODE -gt 0 ]; then
|
if [ $PLAY_MODE_EXIT_CODE -gt 0 ]; then
|
||||||
exit $PLAY_MODE_EXIT_CODE
|
TEST_RUNNER_EXIT_CODE=$PLAY_MODE_EXIT_CODE
|
||||||
fi
|
fi
|
||||||
15
babel.config.js
Normal file
15
babel.config.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const esModules = ['lodash-es'].join('|');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ignore: [`/node_modules/(?!${esModules})`],
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/preset-env',
|
||||||
|
{
|
||||||
|
targets: {
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
8
jest.config.js
Normal file
8
jest.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const esModules = ['lodash-es'].join('|');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
testEnvironment: 'node',
|
||||||
|
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
|
||||||
|
transform: { '^.+\\.(js|jsx)?$': 'babel-jest' },
|
||||||
|
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
|
||||||
|
};
|
||||||
57
package.json
Normal file
57
package.json
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "unity-test-runner",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Run tests for any Unity project.",
|
||||||
|
"main": "action/index.js",
|
||||||
|
"repository": "git@github.com:webbertakken/unity-test-runner.git",
|
||||||
|
"author": "Webber <webber@takken.io>",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"build": "ncc build src --out action --minify",
|
||||||
|
"lint": "prettier --check \"src/**/*.js\" && eslint src",
|
||||||
|
"test": "jest"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.2.1",
|
||||||
|
"@actions/exec": "1.0.3",
|
||||||
|
"@actions/github": "^2.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/cli": "7.8.4",
|
||||||
|
"@babel/core": "7.8.4",
|
||||||
|
"@babel/preset-env": "7.8.4",
|
||||||
|
"@zeit/ncc": "0.21.0",
|
||||||
|
"babel-eslint": "10.0.3",
|
||||||
|
"eslint": "6.8.0",
|
||||||
|
"eslint-config-airbnb": "18.0.1",
|
||||||
|
"eslint-config-prettier": "6.10.0",
|
||||||
|
"eslint-plugin-flowtype": "4.6.0",
|
||||||
|
"eslint-plugin-import": "2.20.1",
|
||||||
|
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||||
|
"eslint-plugin-prettier": "3.1.2",
|
||||||
|
"eslint-plugin-react": "7.18.3",
|
||||||
|
"eslint-plugin-unicorn": "16.0.0",
|
||||||
|
"husky": "4.2.1",
|
||||||
|
"jest": "25.1.0",
|
||||||
|
"lint-staged": "10.0.7",
|
||||||
|
"lodash-es": "4.17.15",
|
||||||
|
"prettier": "1.19.1"
|
||||||
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "lint-staged && yarn build && git add action/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{js,jsx}": [
|
||||||
|
"prettier --write",
|
||||||
|
"eslint",
|
||||||
|
"git add",
|
||||||
|
"jest --findRelatedTests"
|
||||||
|
],
|
||||||
|
"*.{json,md,yaml,yml}": [
|
||||||
|
"prettier --write",
|
||||||
|
"git add"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/index.js
Normal file
36
src/index.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
|
import { Action, Docker, Input, ImageTag, Output } from './model';
|
||||||
|
|
||||||
|
async function action() {
|
||||||
|
Action.checkCompatibility();
|
||||||
|
|
||||||
|
const { dockerfile, workspace, actionFolder } = Action;
|
||||||
|
const {
|
||||||
|
unityVersion,
|
||||||
|
projectPath,
|
||||||
|
testMode,
|
||||||
|
artifactsPath,
|
||||||
|
customParameters,
|
||||||
|
} = Input.getFromUser();
|
||||||
|
const baseImage = ImageTag.createForBase(unityVersion);
|
||||||
|
|
||||||
|
// Build docker image
|
||||||
|
const actionImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
||||||
|
|
||||||
|
// Run docker image
|
||||||
|
await Docker.run(actionImage, {
|
||||||
|
workspace,
|
||||||
|
unityVersion,
|
||||||
|
projectPath,
|
||||||
|
testMode,
|
||||||
|
artifactsPath,
|
||||||
|
customParameters,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Set output
|
||||||
|
await Output.setArtifactsPath(artifactsPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
action().catch(error => {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
});
|
||||||
48
src/model/action.js
Normal file
48
src/model/action.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
class Action {
|
||||||
|
static get supportedPlatforms() {
|
||||||
|
return ['linux'];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get isRunningLocally() {
|
||||||
|
return process.env.RUNNER_WORKSPACE === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get isRunningFromSource() {
|
||||||
|
return path.basename(__dirname) === 'model';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get name() {
|
||||||
|
return 'unity-test-runner';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get rootFolder() {
|
||||||
|
if (Action.isRunningFromSource) {
|
||||||
|
return path.dirname(path.dirname(path.dirname(__filename)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.dirname(path.dirname(__filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
static get actionFolder() {
|
||||||
|
return `${Action.rootFolder}/action`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get dockerfile() {
|
||||||
|
return `${Action.actionFolder}/Dockerfile`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get workspace() {
|
||||||
|
return process.env.GITHUB_WORKSPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static checkCompatibility() {
|
||||||
|
const currentPlatform = process.platform;
|
||||||
|
if (!Action.supportedPlatforms.includes(currentPlatform)) {
|
||||||
|
throw new Error(`Currently ${currentPlatform}-platform is not supported`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Action;
|
||||||
36
src/model/action.test.js
Normal file
36
src/model/action.test.js
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import fs from 'fs';
|
||||||
|
import Action from './action';
|
||||||
|
|
||||||
|
describe('Action', () => {
|
||||||
|
describe('compatibility check', () => {
|
||||||
|
it('throws for anything other than linux', () => {
|
||||||
|
if (process.platform !== 'linux') {
|
||||||
|
expect(() => Action.checkCompatibility()).toThrow();
|
||||||
|
} else {
|
||||||
|
expect(() => Action.checkCompatibility()).not.toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the root folder of the action', () => {
|
||||||
|
const { rootFolder, name } = Action;
|
||||||
|
|
||||||
|
expect(path.basename(rootFolder)).toStrictEqual(name);
|
||||||
|
expect(fs.existsSync(rootFolder)).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the action folder', () => {
|
||||||
|
const { actionFolder } = Action;
|
||||||
|
|
||||||
|
expect(path.basename(actionFolder)).toStrictEqual('action');
|
||||||
|
expect(fs.existsSync(actionFolder)).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the docker file', () => {
|
||||||
|
const { dockerfile } = Action;
|
||||||
|
|
||||||
|
expect(path.basename(dockerfile)).toStrictEqual('Dockerfile');
|
||||||
|
expect(fs.existsSync(dockerfile)).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
68
src/model/docker.js
Normal file
68
src/model/docker.js
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { exec } from '@actions/exec';
|
||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
class Docker {
|
||||||
|
static async build(buildParameters, silent = false) {
|
||||||
|
const { path, dockerfile, baseImage } = buildParameters;
|
||||||
|
const { version } = baseImage;
|
||||||
|
|
||||||
|
const tag = ImageTag.createForAction(version);
|
||||||
|
const command = `docker build ${path} \
|
||||||
|
--file ${dockerfile} \
|
||||||
|
--build-arg IMAGE=${baseImage} \
|
||||||
|
--tag ${tag}`;
|
||||||
|
|
||||||
|
await exec(command, null, { silent });
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async run(image, parameters, silent = false) {
|
||||||
|
const {
|
||||||
|
unityVersion,
|
||||||
|
workspace,
|
||||||
|
projectPath,
|
||||||
|
testMode,
|
||||||
|
artifactsPath,
|
||||||
|
customParameters,
|
||||||
|
} = parameters;
|
||||||
|
|
||||||
|
const command = `docker run \
|
||||||
|
--workdir /github/workspace \
|
||||||
|
--rm \
|
||||||
|
--env UNITY_LICENSE \
|
||||||
|
--env UNITY_EMAIL \
|
||||||
|
--env UNITY_PASSWORD \
|
||||||
|
--env UNITY_SERIAL \
|
||||||
|
--env UNITY_VERSION="${unityVersion}" \
|
||||||
|
--env PROJECT_PATH="${projectPath}" \
|
||||||
|
--env TEST_MODE="${testMode}" \
|
||||||
|
--env ARTIFACTS_PATH="${artifactsPath}" \
|
||||||
|
--env CUSTOM_PARAMETERS="${customParameters}" \
|
||||||
|
--env HOME=/github/home \
|
||||||
|
--env GITHUB_REF \
|
||||||
|
--env GITHUB_SHA \
|
||||||
|
--env GITHUB_REPOSITORY \
|
||||||
|
--env GITHUB_ACTOR \
|
||||||
|
--env GITHUB_WORKFLOW \
|
||||||
|
--env GITHUB_HEAD_REF \
|
||||||
|
--env GITHUB_BASE_REF \
|
||||||
|
--env GITHUB_EVENT_NAME \
|
||||||
|
--env GITHUB_WORKSPACE=/github/workspace \
|
||||||
|
--env GITHUB_ACTION \
|
||||||
|
--env GITHUB_EVENT_PATH \
|
||||||
|
--env RUNNER_OS \
|
||||||
|
--env RUNNER_TOOL_CACHE \
|
||||||
|
--env RUNNER_TEMP \
|
||||||
|
--env RUNNER_WORKSPACE \
|
||||||
|
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
|
||||||
|
--volume "/home/runner/work/_temp/_github_home":"/github/home" \
|
||||||
|
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
|
||||||
|
--volume "${workspace}":"/github/workspace" \
|
||||||
|
${image}`;
|
||||||
|
|
||||||
|
await exec(command, null, { silent });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Docker;
|
||||||
20
src/model/docker.test.js
Normal file
20
src/model/docker.test.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import Action from './action';
|
||||||
|
import Docker from './docker';
|
||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
describe('Docker', () => {
|
||||||
|
it('builds', async () => {
|
||||||
|
const path = Action.actionFolder;
|
||||||
|
const dockerfile = `${path}/Dockerfile`;
|
||||||
|
const baseImage = new ImageTag({
|
||||||
|
repository: '',
|
||||||
|
name: 'alpine',
|
||||||
|
version: '3',
|
||||||
|
});
|
||||||
|
|
||||||
|
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
||||||
|
|
||||||
|
expect(tag).toBeInstanceOf(ImageTag);
|
||||||
|
expect(tag.toString()).toStrictEqual('unity-action:3');
|
||||||
|
}, 240000);
|
||||||
|
});
|
||||||
41
src/model/image-tag.js
Normal file
41
src/model/image-tag.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { trimStart } from 'lodash-es';
|
||||||
|
|
||||||
|
class ImageTag {
|
||||||
|
static createForBase(version) {
|
||||||
|
const repository = 'gableroux';
|
||||||
|
const name = 'unity3d';
|
||||||
|
return new this({ repository, name, version });
|
||||||
|
}
|
||||||
|
|
||||||
|
static createForAction(version) {
|
||||||
|
const repository = '';
|
||||||
|
const name = 'unity-action';
|
||||||
|
return new this({ repository, name, version });
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor({ repository = '', name, version }) {
|
||||||
|
if (!ImageTag.versionPattern.test(version)) {
|
||||||
|
throw new Error(`Invalid version "${version}".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(this, { repository, name, version });
|
||||||
|
}
|
||||||
|
|
||||||
|
static get versionPattern() {
|
||||||
|
return /^20\d{2}\.\d\.\w{3,4}|3$/;
|
||||||
|
}
|
||||||
|
|
||||||
|
get tag() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
|
||||||
|
get image() {
|
||||||
|
return trimStart(`${this.repository}/${this.name}`, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
return `${this.image}:${this.tag}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ImageTag;
|
||||||
38
src/model/image-tag.test.js
Normal file
38
src/model/image-tag.test.js
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
describe('UnityImageVersion', () => {
|
||||||
|
describe('constructor', () => {
|
||||||
|
const some = {
|
||||||
|
name: 'someName',
|
||||||
|
version: '2020.0.00f0',
|
||||||
|
};
|
||||||
|
|
||||||
|
it('can be called', () => {
|
||||||
|
expect(() => new ImageTag(some)).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts parameters and sets the right properties', () => {
|
||||||
|
const image = new ImageTag(some);
|
||||||
|
|
||||||
|
expect(image.repository).toStrictEqual('');
|
||||||
|
expect(image.name).toStrictEqual(some.name);
|
||||||
|
expect(image.version).toStrictEqual(some.version);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => {
|
||||||
|
expect(() => new ImageTag({ version })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
|
||||||
|
expect(() => new ImageTag({ version })).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toString', () => {
|
||||||
|
it('returns the correct version', () => {
|
||||||
|
const image = ImageTag.createForBase('2099.1.1111');
|
||||||
|
|
||||||
|
expect(image.toString()).toStrictEqual(`gableroux/unity3d:2099.1.1111`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
7
src/model/index.js
Normal file
7
src/model/index.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import Action from './action';
|
||||||
|
import Docker from './docker';
|
||||||
|
import Input from './input';
|
||||||
|
import ImageTag from './image-tag';
|
||||||
|
import Output from './output';
|
||||||
|
|
||||||
|
export { Action, Docker, Input, ImageTag, Output };
|
||||||
7
src/model/index.test.js
Normal file
7
src/model/index.test.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import * as Index from '.';
|
||||||
|
|
||||||
|
describe('Index', () => {
|
||||||
|
test.each(['Action', 'Docker', 'ImageTag', 'Input', 'Output'])('exports %s', exportedModule => {
|
||||||
|
expect(typeof Index[exportedModule]).toStrictEqual('function');
|
||||||
|
});
|
||||||
|
});
|
||||||
51
src/model/input.js
Normal file
51
src/model/input.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { getInput } from '@actions/core';
|
||||||
|
import { includes } from 'lodash-es';
|
||||||
|
|
||||||
|
class Input {
|
||||||
|
static get testModes() {
|
||||||
|
return ['all', 'playmode', 'editmode'];
|
||||||
|
}
|
||||||
|
|
||||||
|
static isValidFolderName(folderName) {
|
||||||
|
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?\w+([-_]?\w+)*\/?)*$/);
|
||||||
|
|
||||||
|
return validFolderName.test(folderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
static getFromUser() {
|
||||||
|
// Input variables specified in workflow using "with" prop.
|
||||||
|
const unityVersion = getInput('unityVersion') || '2019.2.11f1';
|
||||||
|
const testMode = getInput('testMode') || 'all';
|
||||||
|
const rawProjectPath = getInput('projectPath') || '.';
|
||||||
|
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
||||||
|
const customParameters = getInput('customParameters') || '';
|
||||||
|
|
||||||
|
// Validate input
|
||||||
|
if (!includes(this.testModes, testMode)) {
|
||||||
|
throw new Error(`Invalid testMode ${testMode}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isValidFolderName(rawArtifactsPath)) {
|
||||||
|
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.isValidFolderName(rawProjectPath)) {
|
||||||
|
throw new Error(`Invalid projectPath "${rawProjectPath}"`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanitise input
|
||||||
|
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||||
|
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||||
|
|
||||||
|
// Return sanitised input
|
||||||
|
return {
|
||||||
|
unityVersion,
|
||||||
|
projectPath,
|
||||||
|
testMode,
|
||||||
|
artifactsPath,
|
||||||
|
customParameters,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Input;
|
||||||
34
src/model/input.test.js
Normal file
34
src/model/input.test.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import Input from './input';
|
||||||
|
|
||||||
|
describe('Input', () => {
|
||||||
|
describe('getFromUser', () => {
|
||||||
|
it('does not throw', () => {
|
||||||
|
expect(() => Input.getFromUser()).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns an object', () => {
|
||||||
|
expect(typeof Input.getFromUser()).toStrictEqual('object');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isValidFolderName', () => {
|
||||||
|
test.each([
|
||||||
|
'.',
|
||||||
|
'./',
|
||||||
|
'folder',
|
||||||
|
'trailing/',
|
||||||
|
'.hidden',
|
||||||
|
'.hidden/sub',
|
||||||
|
'.hidden/trailing/',
|
||||||
|
'./.hidden-sub',
|
||||||
|
'hyphen-folder',
|
||||||
|
'under_score',
|
||||||
|
])('returns true for %s', folderName => {
|
||||||
|
expect(Input.isValidFolderName(folderName)).toStrictEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(['..', '../'])('returns false for %s', folderName => {
|
||||||
|
expect(Input.isValidFolderName(folderName)).toStrictEqual(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
9
src/model/output.js
Normal file
9
src/model/output.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
class Output {
|
||||||
|
static async setArtifactsPath(artifactsPath) {
|
||||||
|
await core.setOutput('artifactsPath', artifactsPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Output;
|
||||||
9
src/model/output.test.js
Normal file
9
src/model/output.test.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import Output from './output';
|
||||||
|
|
||||||
|
describe('Output', () => {
|
||||||
|
describe('setArtifactsPath', () => {
|
||||||
|
it('does not throw', async () => {
|
||||||
|
await expect(Output.setArtifactsPath()).resolves.not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user