forked from forerunnergames/energy-shot
-
Notifications
You must be signed in to change notification settings - Fork 0
138 lines (126 loc) · 5.48 KB
/
run-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# Run all tests in res://test/unit, when:
# 1) A commit is pushed to any branch.
# 2) A pull request is opened or updated.
# 3) Another workflow calls this one.
name: Run Tests
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
# Don't run again for report uploads during a pull request.
paths-ignore:
- '.github/workflows/*'
workflow_call:
inputs:
github_ref:
required: true
type: string
# Forward 'test_passed' from jobs.run-tests.outputs.output1 to outputs.tests_passed, for use in caller workflows.
# See https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusabla-workflow
outputs:
tests_passed:
description: "Outputs whether or not all tests have passed"
value: ${{ jobs.run-tests.outputs.output1 }}
jobs:
run-tests:
# Required to prevent "HttpError: Resource not accessible by integration" errors.
permissions: write-all
# This job runs on the latest Ubuntu version.
runs-on: ubuntu-latest
# Forward 'test_passed' from steps.check_tests.outputs.tests_passed to jobs.run-tests.outputs.output1.
outputs:
output1: ${{ steps.check_tests.outputs.tests_passed }}
steps:
# Don't re-run this workflow if a successful duplicate run exists.
# Cancel this workflow if it's using an outdated commit.
- name: Skip duplicate actions
id: skip-duplicate
uses: fkirc/skip-duplicate-actions@v5
with:
cancel_others: true
skip_after_successful_duplicate: true
# If github_ref is not set, then use this workflow's HEAD (github.ref).
# Otherwise github_ref is set & we're being called from another workflow,
# so use the provided github_ref value from that workflow.
- name: Determine ref
id: determine_ref
run: |
if [ -z "${{ inputs.github_ref }}" ]; then
echo "ref=${{ github.ref }}" >> $GITHUB_ENV
else
echo "ref=${{ inputs.github_ref }}" >> $GITHUB_ENV
fi
# Reports can only be published for non-fork pull requests.
# See https://github.com/MikeSchulze/gdUnit4-action?tab=readme-ov-file#note-on-forked-repositories
- name: Set publish report flag
id: set_publish_report
run: |
if [ "${{ github.event_name }}" == "pull_request" ] && [ "${{ github.event.pull_request.head.repo.fork }}" == "true" ]; then
echo "PUBLISH_REPORT=false" >> $GITHUB_ENV
else
echo "PUBLISH_REPORT=true" >> $GITHUB_ENV
fi
# Check out the repository so the project files are available.
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use the correct ref, will either be this workflow's HEAD if run directly,
# or another workflow's ref that called this one.
ref: ${{ env.ref }}
# Checkout the entire commit history.
fetch-depth: 0
# Sanitize the ref name to avoid invalid forward slash character in the
# report name during a pull request, when github.ref_name is in the format
# "<pr_number>/merge", where <pr_number> is the pull request number.
- name: Sanitize ref_name
id: sanitize_ref_name
run: |
SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[\/:]/-/g')
echo "SANITIZED_REF_NAME=$SANITIZED_REF_NAME" >> $GITHUB_ENV
# Run the tests in res://test/unit & generate test-results.xml report
# with a unique name that includes the run ID & branch name to clearly
# identify & distinguish between multiple test report files.
- name: Setup GdUnit4 and run tests
# Using '@v1' won't use the latest version, so specify explicit version.
uses: MikeSchulze/[email protected]
with:
godot-version: '4.3'
godot-status: 'stable'
godot-net: false # Don't run only C# tests.
godot-force-mono: true # Run both C# & GDScript tests using the Mono engine.
version: 'master'
paths: 'res://tests'
retries: 3
publish-report: ${{ env.PUBLISH_REPORT }}
# If we're on a fork, the report will be uploaded as an artifact named "artifact_<report_name>"
report-name: 'test-results-${{ github.run_id }}-${{ env.SANITIZED_REF_NAME }}.xml'
# Fail the workflow if the test results file can't be found.
# Save the test result file as env.TEST_RESULTS_FILE for reuse in other steps.
- name: Check if test results file exists
id: check_file_exists
run: |
TEST_RESULTS_FILE=$(find ./reports/ -name 'results.xml')
if [ -z "$TEST_RESULTS_FILE" ]; then
echo "Test results file not found"
exit 1
else
echo "Test results file found at $TEST_RESULTS_FILE"
echo "TEST_RESULTS_FILE=$TEST_RESULTS_FILE" >> $GITHUB_ENV
fi
# Make test result available to other workflows.
# Forward 'test_passed' to steps.check_tests.outputs.tests_passed.
- name: Check test results
id: check_tests
# Search for existence of any '<failure' tag in the test report xml file, & fail if any exist.
run: |
if grep -q '<failure' ${{ env.TEST_RESULTS_FILE }}; then
echo "Tests failed"
echo "tests_passed=false" >> $GITHUB_OUTPUT
exit 1
else
echo "Tests passed"
echo "tests_passed=true" >> $GITHUB_OUTPUT
fi