Simplify trainer config #775
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: unittest | |
on: | |
issue_comment: | |
types: [created] | |
permissions: | |
contents: write | |
checks: write | |
pull-requests: write | |
jobs: | |
unittest: | |
# only run on pull request | |
if: ${{ github.event.issue.pull_request && (startsWith(github.event.comment.body, '/unittest')) && github.event.comment.author_association == 'COLLABORATOR' }} | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
path: trinity-${{ github.run_id }} | |
ref: refs/pull/${{ github.event.issue.number }}/head | |
- name: Setup docker compose | |
working-directory: trinity-${{ github.run_id }}/.github/workflows/docker | |
run: | | |
docker compose up -d | |
sleep 15s | |
- name: Check ray status | |
working-directory: trinity-${{ github.run_id }}/.github/workflows/docker | |
run: | | |
MAX_RETRIES=20 | |
RETRY_INTERVAL=5 | |
for i in $(seq 1 $MAX_RETRIES); do | |
docker compose exec trinity-node-1 ray status && docker compose exec trinity-node-2 ray status && break | |
echo "Waiting for ray cluster to be ready... ($i/$MAX_RETRIES)" | |
sleep $RETRY_INTERVAL | |
if [ "$i" -eq "$MAX_RETRIES" ]; then | |
echo "Ray cluster failed to start after $MAX_RETRIES retries." | |
exit 1 | |
fi | |
done | |
- 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: | | |
TYPE="${{ steps.test_type.outputs.type }}" | |
if [ "$TYPE" = "all" ]; then | |
echo "tests_run=true" >> $GITHUB_ENV | |
docker compose exec trinity-node-1 pytest tests -v -s --ctrf report.json | |
elif [ "$TYPE" = "diff" ]; then | |
if [ -s ../../../test_dirs.txt ]; then | |
echo "tests_run=true" >> $GITHUB_ENV | |
TEST_DIRS=$(cat ../../../test_dirs.txt | xargs) | |
docker compose exec trinity-node-1 pytest $TEST_DIRS -v -s --ctrf report.json | |
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 | |
echo "tests_run=true" >> $GITHUB_ENV | |
docker compose exec trinity-node-1 pytest tests/$MODULE -v -s --ctrf report.json | |
else | |
echo "No module specified, skipping tests." | |
echo "tests_run=false" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Upload test results | |
if: env.tests_run == 'true' || failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: pytest-results | |
path: trinity-${{ github.run_id }}/report.json | |
continue-on-error: true | |
- name: Publish Test Report | |
if: env.tests_run == 'true' || failure() | |
uses: ctrf-io/github-test-reporter@v1 | |
with: | |
report-path: trinity-${{ github.run_id }}/report.json | |
summary: true | |
pull-request: false | |
issue: ${{ github.event.issue.number }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
continue-on-error: true | |
- name: Remove docker compose | |
working-directory: trinity-${{ github.run_id }}/.github/workflows/docker | |
if: always() | |
run: | | |
docker compose down --remove-orphans | |
continue-on-error: true | |
- name: Cleanup workspace | |
if: always() | |
run: | | |
rm -rf trinity-${{ github.run_id }} 2>/dev/null | |
continue-on-error: true |