{"id":20139404,"url":"https://github.com/mackysoft/unity-githubactions-automatictest-example","last_synced_at":"2025-03-02T23:17:17.233Z","repository":{"id":111399648,"uuid":"356300011","full_name":"mackysoft/Unity-GitHubActions-AutomaticTest-Example","owner":"mackysoft","description":"A example project for automated testing using Unity and GitHub Actions.","archived":false,"fork":false,"pushed_at":"2021-04-12T09:41:52.000Z","size":69,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T10:11:37.549Z","etag":null,"topics":["automation","ci","example","github-actions","test","tutorial","unity"],"latest_commit_sha":null,"homepage":"https://qiita.com/makihiro_dev/items/fda3fa840f5311d2b3d5","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mackysoft.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-09T14:32:14.000Z","updated_at":"2021-04-12T09:41:55.000Z","dependencies_parsed_at":"2023-05-18T15:03:26.771Z","dependency_job_id":null,"html_url":"https://github.com/mackysoft/Unity-GitHubActions-AutomaticTest-Example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-GitHubActions-AutomaticTest-Example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-GitHubActions-AutomaticTest-Example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-GitHubActions-AutomaticTest-Example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mackysoft%2FUnity-GitHubActions-AutomaticTest-Example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mackysoft","download_url":"https://codeload.github.com/mackysoft/Unity-GitHubActions-AutomaticTest-Example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241582556,"owners_count":19985846,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","ci","example","github-actions","test","tutorial","unity"],"created_at":"2024-11-13T21:45:10.920Z","updated_at":"2025-03-02T23:17:17.214Z","avatar_url":"https://github.com/mackysoft.png","language":"C#","readme":"﻿# Unity \u0026 GitHub Actions Automatic Test Example\n\nAn example project for automated testing using Unity and GitHub Actions.\n\n\u003e Qiita: [UnityとGitHubActionを使って自動テストを行う](https://qiita.com/makihiro_dev/private/fda3fa840f5311d2b3d5)\n\n## 🔰 Tutorial\n\n### 1. Prepare Tests Repository\n\nPrepare a repository for the Unity project that contains the tests.\n\n### 2. Acquire ULF\n\nAcquire the ULF file to activate your Unity license.\nUse the following tool to acquire the ULF file.\n\nhttps://github.com/mackysoft/Unity-ManualActivation\n\n### 3. Register ULF to Secrets\n\n1. Select the `Settings \u003e Secrets` menu in the project repository.\n2. Click the `New repository secret` button.\n3. Enter \"UNITY_LICENSE\" in Name and copy and paste the contents of the ULF file in Value.\n4. Click the `Add secret` button.\n\nYou can now treat the contents of the ULF file as an environment variable while keeping its contents private.\n\n### 4. Write a YAML file to run the tests.\n\nCreate a `Test.yaml` file (you can name it anything you want) under the `.github/workflows/` folder, and write the process to run the tests there.\n\n```yaml:Test.yaml\nname: Test\n\non: [push, pull_request]\n\njobs:\n  test:\n    name: ${{ matrix.testMode }} on ${{ matrix.unityVersion }}\n    runs-on: ubuntu-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        projectPath:\n          - .\n        unityVersion:\n          - 2020.3.1f1 # Enter the Unity version of the ULF you registered in Secrets.\n        testMode:\n          - playmode\n          - editmode\n    steps:\n      # Checkout\n      - uses: actions/checkout@v2\n        with:\n          lfs: true\n\n      # Cache\n      - uses: actions/cache@v2\n        with:\n          path: ${{ matrix.projectPath }}/Library\n          key: Library-${{ matrix.projectPath }}\n          restore-keys: |\n            Library-\n\n      # Test\n      - uses: game-ci/unity-test-runner@v2\n        id: tests\n        env:\n          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}\n        with:\n          projectPath: ${{ matrix.projectPath }}\n          unityVersion: ${{ matrix.unityVersion }}\n          testMode: ${{ matrix.testMode }}\n          artifactsPath: ${{ matrix.testMode }}-artifacts\n          checkName: ${{ matrix.testMode }} Test Results\n\n      # Upload Artifact\n      - uses: actions/upload-artifact@v2\n        if: always()\n        with:\n          name: Test results for ${{ matrix.testMode }}\n          path: ${{ steps.tests.outputs.artifactsPath }}\n```\n\n### 5. Run tests on GitHub Actions\n\nIn the case of the above `Test.yaml`, the test will be executed by GitHub Actions every time a Push or Pull Request is made.\n\nIf you see a ✔ mark as shown in the image below, you have succeeded.\n\n![TestResult](https://user-images.githubusercontent.com/13536348/114280859-3f139b00-9a76-11eb-9299-72cdfe1b45ea.jpg)\n\n## Extra: Report results to Slack\n\nA tutorial on how to report the results of a test to Slack.\n\n### 1. Generate and acquire Webhook URL\n\nIn order to send messages from GitHub Actions to Slack, you need an Incoming Webhook URL of Slack.\n\nFollow the instructions on the following page to generate a webhook URL.\n\nhttps://api.slack.com/messaging/webhooks\n\nIf you follow the steps, a URL starting with `https://hooks.slack.com/services/` will be generated in the Webhook URL, and you can use that URL after this.\n\n![WebhookURL](https://user-images.githubusercontent.com/13536348/114370729-bfdbaf80-9bba-11eb-8fbd-9deb2bfd7b7f.jpg)\n\n\n### 2. Register Webhook URL to Secrets\n\nRegister the acquired Webhook URL to `Settings \u003e Secrets` in the project repository.\n\nAdd a new secret, enter `SLACK_HOOK` in Name and enter Webhook URL in Value.\n\n![SLACK_HOOK](https://user-images.githubusercontent.com/13536348/114371707-bb63c680-9bbb-11eb-8fdd-d198ad7946f4.jpg)\n\n\n### 3. Write the Slack reporting process in YAML for testing\n\nAdd the Slack reporting process to the YAML where you wrote the test process.\n\n```yaml:test.yaml\nname: Test\n\non: [push, pull_request]\n\njobs:\n  test:\n    name: ${{ matrix.testMode }} on ${{ matrix.unityVersion }}\n    runs-on: ubuntu-latest\n    strategy:\n      fail-fast: false\n      matrix:\n        projectPath:\n          - .\n        unityVersion:\n          - 2020.3.1f1\n        testMode:\n          - playmode\n          - editmode\n    steps:\n      # Checkout\n      - name: Checkout\n        uses: actions/checkout@v2\n        with:\n          lfs: true\n\n      # Cache\n      - name: Cache\n        uses: actions/cache@v2\n        with:\n          path: ${{ matrix.projectPath }}/Library\n          key: Library-${{ matrix.projectPath }}\n          restore-keys: |\n            Library-\n\n      # Tests\n      - name: Tests\n        uses: game-ci/unity-test-runner@v2\n        id: tests\n        env:\n          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}\n        with:\n          projectPath: ${{ matrix.projectPath }}\n          unityVersion: ${{ matrix.unityVersion }}\n          testMode: ${{ matrix.testMode }}\n          artifactsPath: ${{ matrix.testMode }}-artifacts\n          checkName: ${{ matrix.testMode }} Test Results\n\n      # Upload Artifact\n      - name: Upload Artifact\n        uses: actions/upload-artifact@v2\n        if: always()\n        with:\n          name: Test results for ${{ matrix.testMode }}\n          path: ${{ steps.tests.outputs.artifactsPath }}\n          \n  reportSlack:\n    name: ${{ matrix.testMode }} report\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        testMode:\n          - playmode\n          - editmode\n    needs: test\n    steps:\n    \n      # Download Artifact\n      - name: Download Artifact\n        uses: actions/download-artifact@main\n        with:\n          name: Test results for ${{ matrix.testMode }}\n          path: ${{ matrix.testMode }}-artifacts\n\n      # Clone NUnitXmlReporter\n      - name: Clone NUnitXmlReporter\n        run: git clone https://github.com/pCYSl5EDgo/NUnitXmlReporter.git\n\n      # Setup .NET\n      - name: Setup .NET\n        uses: actions/setup-dotnet@v1.7.2\n        with:\n          dotnet-version: '3.0.100'\n      \n      # Report Result to Slack\n      - name: Report Result to Slack\n        env:\n          SLACK: ${{ secrets.SLACK_HOOK }}\n        run: |\n          cd NUnitXmlReporter\n          dotnet run ../${{ matrix.testMode }}-artifacts/${{ matrix.testMode }}-results.xml ../slackJson --slack-block  $GITHUB_REPOSITORY $GITHUB_SHA || INPUT_RESULT=$?\n          cd ..\n          curl -X POST -H 'ContentX-type:application/json' --data \"$(cat slackJson)\" $SLACK\n          exit $INPUT_RESULT\n```\n\n## 4. Run tests\n\n1. Push or Pull Request to the repository and run the testing workflow.\n2. Wait for the workflow to complete.\n\nIf the test results are reported to Slack as shown below, you have succeeded.\n\n![SlackTestReport](https://user-images.githubusercontent.com/13536348/114363192-1e9d2b00-9bb3-11eb-90d1-b6f83a069f59.jpg)\n\n#  📔 Author Info\n\nHiroya Aramaki is a indie game developer in Japan.\n\n- Blog: [https://mackysoft.net/blog](https://mackysoft.net/blog)\n- Twitter: [https://twitter.com/makihiro_dev](https://twitter.com/makihiro_dev)\n\n\n#  📜 License\n\nThis repository is under the MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackysoft%2Funity-githubactions-automatictest-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmackysoft%2Funity-githubactions-automatictest-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmackysoft%2Funity-githubactions-automatictest-example/lists"}