Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions .github/workflows/unittest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
jobs:
unittest:
# only run on pull request
if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/run-unittest') && github.event.comment.author_association == 'COLLABORATOR' }}
if: ${{ github.event.issue.pull_request && (startsWith(github.event.comment.body, '/unittest')) && github.event.comment.author_association == 'COLLABORATOR' }}
runs-on: self-hosted

steps:
Expand All @@ -33,18 +33,70 @@ jobs:
docker compose exec trinity-node-1 ray status
docker compose exec trinity-node-2 ray status

- name: Decide test type
id: test_type
working-directory: trinity-${{ github.run_id }}
run: |
COMMENT="${{ github.event.comment.body }}"
if [[ "$COMMENT" == "/unittest-all"* ]]; then
echo "type=all" >> $GITHUB_OUTPUT
elif [[ "$COMMENT" == "/unittest-diff"* ]]; then
echo "type=diff" >> $GITHUB_OUTPUT
elif [[ "$COMMENT" =~ ^/unittest-module-(.+)$ ]]; then
MODULE=$(echo "$COMMENT" | sed -n 's/\/unittest-module-\(.*\)/\1/p')
echo "type=module" >> $GITHUB_OUTPUT
echo "module=$MODULE" >> $GITHUB_OUTPUT
else
echo "type=all" >> $GITHUB_OUTPUT
fi

- name: Get changed modules (for diff)
if: steps.test_type.outputs.type == 'diff'
id: diff
working-directory: trinity-${{ github.run_id }}
run: |
git fetch origin main
git diff --name-only origin/main...HEAD > changed_files.txt
awk -F/ '/^(trinity)\// {print $2}' changed_files.txt | sort | uniq > changed_modules.txt
awk '{print "tests/"$1}' changed_modules.txt > test_dirs.txt

- name: Run unittest
working-directory: trinity-${{ github.run_id }}/.github/workflows/docker
run: |
docker compose exec trinity-node-1 pytest tests -v -s --ignore=tests/data --ctrf report.json
TYPE="${{ steps.test_type.outputs.type }}"
if [ "$TYPE" = "all" ]; then
docker compose exec trinity-node-1 pytest tests -v -s --ignore=tests/data --ctrf report.json
echo "tests_run=true" >> $GITHUB_ENV
elif [ "$TYPE" = "diff" ]; then
ROOT_DIR=trinity-${{ github.run_id }}
if [ -s "$ROOT_DIR/test_dirs.txt" ]; then
TEST_DIRS=$(cat "$ROOT_DIR/test_dirs.txt" | xargs)
docker compose exec trinity-node-1 pytest $TEST_DIRS -v -s --ignore=tests/data --ctrf report.json
echo "tests_run=true" >> $GITHUB_ENV
else
echo "No changed modules detected, skipping tests."
echo "tests_run=false" >> $GITHUB_ENV
fi
elif [ "$TYPE" = "module" ]; then
MODULE="${{ steps.test_type.outputs.module }}"
if [ -n "$MODULE" ]; then
docker compose exec trinity-node-1 pytest tests/$MODULE -v -s --ignore=tests/data --ctrf report.json
echo "tests_run=true" >> $GITHUB_ENV
else
echo "No module specified, skipping tests."
echo "tests_run=false" >> $GITHUB_ENV
fi
fi

- name: Upload test results
if: env.tests_run == 'true'
uses: actions/upload-artifact@v4
with:
name: pytest-results
path: trinity-${{ github.run_id }}/report.json

- name: Publish Test Report
if: env.tests_run == 'true'
uses: ctrf-io/github-test-reporter@v1
with:
report-path: trinity-${{ github.run_id }}/report.json
Expand All @@ -53,7 +105,6 @@ jobs:
issue: ${{ github.event.issue.number }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: always()

- name: Remove docker compose
working-directory: trinity-${{ github.run_id }}/.github/workflows/docker
Expand Down