|
| 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 }} |
0 commit comments