diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e9d5f6e..6b4004f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,6 +6,10 @@ on: pull_request: branches: [main] +permissions: + contents: read + issues: write + jobs: test: name: Run Unity Tests @@ -39,3 +43,60 @@ jobs: with: name: test-results path: test-results/ + + report-failure: + name: Open issue on test failure + needs: test + if: failure() + runs-on: ubuntu-latest + steps: + - name: Create or update tracking issue + uses: actions/github-script@v7 + with: + script: | + const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`; + const isPR = context.eventName === 'pull_request'; + + const subject = isPR + ? `PR #${context.payload.pull_request.number} ("${context.payload.pull_request.title}")` + : `commit ${context.sha.substring(0, 7)} on \`${context.ref.replace('refs/heads/', '')}\``; + + const title = isPR + ? `Unity tests failing: PR #${context.payload.pull_request.number}` + : `Unity tests failing on ${context.ref.replace('refs/heads/', '')}`; + + const body = [ + `The **Automated Tests** workflow failed for ${subject}.`, + '', + `**Workflow run**: ${runUrl}`, + '', + 'Check the Edit Mode / Play Mode test results artifact attached to the run', + 'above for the specific failing test(s). This issue will stay open until a', + 'follow-up run passes — close it manually once resolved.', + ].join('\n'); + + const { data: existing } = await github.rest.issues.listForRepo({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + labels: 'ci-failure', + }); + + const match = existing.find(issue => issue.title === title); + + if (match) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: match.number, + body: `Still failing as of ${runUrl}.`, + }); + } else { + await github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title, + body, + labels: ['ci-failure'], + }); + }