diff --git a/.github/workflows/update-test-counts.yml b/.github/workflows/update-test-counts.yml new file mode 100644 index 00000000..e2b77108 --- /dev/null +++ b/.github/workflows/update-test-counts.yml @@ -0,0 +1,58 @@ +name: Update Test Counts + +on: + push: + branches: [main] + paths: + - 'Tests/**' + - 'Sources/**' + schedule: + - cron: '0 2 * * *' # Daily at 2 AM UTC + workflow_dispatch: + +permissions: + contents: write + +jobs: + update-test-counts: + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Count tests and suites + id: counts + run: | + TESTS=$(grep -r '@Test\b' Tests/ --include='*.swift' 2>/dev/null | wc -l | tr -d ' ') + SUITES=$(grep -r '@Suite\b' Tests/ --include='*.swift' 2>/dev/null | wc -l | tr -d ' ') + + echo "tests=$TESTS" >> "$GITHUB_OUTPUT" + echo "suites=$SUITES" >> "$GITHUB_OUTPUT" + + echo "Found $TESTS tests in $SUITES test suites" + + - name: Update README badges + run: | + TESTS="${{ steps.counts.outputs.tests }}" + SUITES="${{ steps.counts.outputs.suites }}" + + # Update badge: Tests-XXXX%2B_passing + sed -i '' "s/Tests-[0-9]*%2B_passing/Tests-${TESTS}%2B_passing/" README.md + + # Update project structure line: "XXXX tests across YYYY test suites" + sed -i '' "s/[0-9]* tests across [0-9]* test suites/${TESTS} tests across ${SUITES} test suites/" README.md + + # Update developer notes: "All XXXX tests run" + sed -i '' "s/All [0-9]* tests run/All ${TESTS} tests run/" README.md + + - name: Commit if changed + run: | + git diff --quiet README.md && echo "No changes to README" && exit 0 + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add README.md + git commit -m "chore: update test count badge to ${{ steps.counts.outputs.tests }} tests [skip ci]" + git push