diff --git a/.github/workflows/create-configlet-sync-issues.yml b/.github/workflows/create-configlet-sync-issues.yml deleted file mode 100644 index 07a0ed615..000000000 --- a/.github/workflows/create-configlet-sync-issues.yml +++ /dev/null @@ -1,176 +0,0 @@ -name: Create Configlet Sync Issues - -on: - workflow_call: - workflow_dispatch: - -permissions: - issues: write - contents: read - -jobs: - create-sync-issues: - runs-on: ubuntu-24.04 - timeout-minutes: 15 - - env: - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PARENT_ISSUE_TITLE: "🚨 configlet sync --test found unsynced tests" - - steps: - - name: Checkout repository - uses: actions/checkout@v7.0.1 - - - name: Fetch configlet - run: ./bin/fetch-configlet - - - name: Run configlet sync --tests and capture output - id: sync - shell: bash {0} - run: | - raw_output="$(./bin/configlet sync --tests 2>&1)" - exit_code=$? - printf "exit_code=%d\n" "$exit_code" >> "$GITHUB_OUTPUT" - { - printf "output<> "$GITHUB_OUTPUT" - printf "configlet exit code: %d\n" "$exit_code" - printf "%s\n" "$raw_output" - - - name: Parse exercises with missing tests - id: parse - if: steps.sync.outputs.exit_code != '0' - shell: bash - run: | - output='${{ steps.sync.outputs.output }}' - - # Extract exercise slugs from lines like: [warn] dot-dsl: missing 19 test cases - mapfile -t exercises < <(printf "%s\n" "$output" | grep -oP '(?<=\[warn\] )[a-z][a-z0-9-]+(?=: missing \d+ test case)') - - if [[ ${#exercises[@]} -eq 0 ]]; then - printf "No exercises with missing tests found in output.\n" - printf "exercises_json=[]\n" >> "$GITHUB_OUTPUT" - exit 0 - fi - - printf "Found %d exercise(s) with missing tests:\n" "${#exercises[@]}" - printf " - %s\n" "${exercises[@]}" - - # Build JSON array of slugs - json="[" - for i in "${!exercises[@]}"; do - [[ $i -gt 0 ]] && json+="," - json+="\"${exercises[$i]}\"" - done - json+="]" - printf "exercises_json=%s\n" "$json" >> "$GITHUB_OUTPUT" - - # Build per-exercise details: slug test_name uuid (one row per test) - { - printf "details<> "$GITHUB_OUTPUT" - - - name: Find parent tracking issue - id: find_parent - if: steps.sync.outputs.exit_code != '0' && steps.parse.outputs.exercises_json != '[]' - shell: bash - run: | - issue_data=$(gh issue list \ - --repo "${{ github.repository }}" \ - --search "is:issue is:open in:title \"${PARENT_ISSUE_TITLE}\"" \ - --json number \ - --jq '.[0].number // empty') - - if [[ -z "$issue_data" ]]; then - printf "::warning::Parent issue not found. Run 'Run Configlet Sync' first.\n" - printf "parent_number=\n" >> "$GITHUB_OUTPUT" - else - printf "Found parent issue #%s\n" "$issue_data" - printf "parent_number=%s\n" "$issue_data" >> "$GITHUB_OUTPUT" - fi - - - name: Create or update child issues per exercise - if: steps.sync.outputs.exit_code != '0' && steps.parse.outputs.exercises_json != '[]' - shell: bash - env: - EXERCISES_JSON: ${{ steps.parse.outputs.exercises_json }} - DETAILS: ${{ steps.parse.outputs.details }} - PARENT_NUMBER: ${{ steps.find_parent.outputs.parent_number }} - run: | - repo="${{ github.repository }}" - - mapfile -t exercises < <(printf "%s\n" "$EXERCISES_JSON" | jq -r '.[]') - - for slug in "${exercises[@]}"; do - child_title="[configlet] ${slug}: missing test cases" - - # Collect missing tests for this exercise - missing_tests="" - while IFS=$'\t' read -r es_slug test_name uuid; do - [[ "$es_slug" == "$slug" ]] || continue - missing_tests+="- \`${uuid}\` ${test_name}"$'\n' - done <<< "$DETAILS" - - parent_ref="" - [[ -n "$PARENT_NUMBER" ]] && parent_ref="Part of #${PARENT_NUMBER}." - - # Write body to a temp file to avoid quoting / indentation issues - body_file=$(mktemp) - cat > "$body_file" << ISSUE_BODY_EOF - ## Missing test cases for \`${slug}\` - - ${parent_ref} - - The following test cases from [problem-specifications](https://github.com/exercism/problem-specifications/tree/main/exercises/${slug}) are not yet implemented in this track: - - ${missing_tests} - ### How to help - - For detailed instructions on how to fetch configlet and update the tests, please see the **"How to do this task"** section in the main tracking issue: - 👉 **[Read the instructions here](${{ github.server_url }}/${{ github.repository }}/issues/${PARENT_NUMBER:-"none"})** - - _This issue is managed automatically by the [Create Configlet Sync Issues](${{ github.server_url }}/${{ github.repository }}/actions/workflows/create-configlet-sync-issues.yml) workflow._ - ISSUE_BODY_EOF - - # Check for an existing open child issue - existing=$(gh issue list \ - --repo "$repo" \ - --search "is:issue is:open in:title \"${child_title}\"" \ - --json number \ - --jq '.[0].number // empty') - - if [[ -z "$existing" ]]; then - printf "Creating child issue for: %s\n" "$slug" - issue_url=$(gh issue create \ - --repo "$repo" \ - --title "$child_title" \ - --body-file "$body_file" \ - --label "x:knowledge/elementary,x:module/practice-exercise") - new_number=$(basename "$issue_url") - printf "Created #%s for %s\n" "$new_number" "$slug" - else - printf "Updating existing child issue #%s for: %s\n" "$existing" "$slug" - gh issue edit "$existing" \ - --repo "$repo" \ - --body-file "$body_file" - fi - - rm -f "$body_file" - done - - - name: All tests synced — nothing to do - if: steps.sync.outputs.exit_code == '0' - run: printf "✅ All exercises are fully synced. No child issues needed.\n" diff --git a/.github/workflows/run-configlet-sync.yml b/.github/workflows/run-configlet-sync.yml index 832564a3a..d303c23ba 100644 --- a/.github/workflows/run-configlet-sync.yml +++ b/.github/workflows/run-configlet-sync.yml @@ -9,7 +9,7 @@ jobs: call-gha-workflow: uses: exercism/github-actions/.github/workflows/configlet-sync.yml@main - create-sync-issues: + sync-tests: needs: call-gha-workflow - uses: ./.github/workflows/create-configlet-sync-issues.yml + uses: ./.github/workflows/sync-tests.yml secrets: inherit diff --git a/.github/workflows/sync-tests.yml b/.github/workflows/sync-tests.yml new file mode 100644 index 000000000..6d8075978 --- /dev/null +++ b/.github/workflows/sync-tests.yml @@ -0,0 +1,297 @@ +name: Sync Tests + +on: + workflow_call: + workflow_dispatch: + +permissions: + issues: write + contents: write + pull-requests: write + +jobs: + sync-tests: + runs-on: ubuntu-24.04 + timeout-minutes: 30 + + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PARENT_ISSUE_TITLE: "🚨 configlet sync --test found unsynced tests" + + steps: + - name: Checkout repository + uses: actions/checkout@v7.0.1 + + - name: Set up JDK 25 + uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad + with: + java-version: 25 + distribution: "temurin" + + - name: Fetch configlet + run: ./bin/fetch-configlet + + - name: Run configlet sync --tests and capture output + id: sync + shell: bash {0} + run: | + raw_output="$(./bin/configlet sync --tests 2>&1)" + exit_code=$? + printf "exit_code=%d\n" "$exit_code" >> "$GITHUB_OUTPUT" + { + printf "output<> "$GITHUB_OUTPUT" + printf "configlet exit code: %d\n" "$exit_code" + printf "%s\n" "$raw_output" + + - name: Parse exercises with missing tests + id: parse + if: steps.sync.outputs.exit_code != '0' + shell: bash + env: + SYNC_OUTPUT: ${{ steps.sync.outputs.output }} + run: | + # Extract exercise slugs from lines like: [warn] dot-dsl: missing 19 test cases + mapfile -t exercises < <(printf "%s\n" "$SYNC_OUTPUT" | grep -oP '(?<=\[warn\] )[a-z][a-z0-9-]+(?=: missing \d+ test case)') + + if [[ ${#exercises[@]} -eq 0 ]]; then + printf "No exercises with missing tests found in output.\n" + printf "exercises_json=[]\n" >> "$GITHUB_OUTPUT" + exit 0 + fi + + printf "Found %d exercise(s) with missing tests:\n" "${#exercises[@]}" + printf " - %s\n" "${exercises[@]}" + + # Build JSON array of slugs + json="[" + for i in "${!exercises[@]}"; do + [[ $i -gt 0 ]] && json+="," + json+="\"${exercises[$i]}\"" + done + json+="]" + printf "exercises_json=%s\n" "$json" >> "$GITHUB_OUTPUT" + + # Build per-exercise details: slug test_name uuid (one row per test) + { + printf "details<> "$GITHUB_OUTPUT" + + - name: Find parent tracking issue + id: find_parent + if: steps.sync.outputs.exit_code != '0' && steps.parse.outputs.exercises_json != '[]' + shell: bash + run: | + issue_data=$(gh issue list \ + --repo "${{ github.repository }}" \ + --search "is:issue is:open in:title \"${PARENT_ISSUE_TITLE}\"" \ + --json number \ + --jq '.[0].number // empty') + + if [[ -z "$issue_data" ]]; then + printf "::warning::Parent issue not found. Run 'Run Configlet Sync' first.\n" + printf "parent_number=\n" >> "$GITHUB_OUTPUT" + else + printf "Found parent issue #%s\n" "$issue_data" + printf "parent_number=%s\n" "$issue_data" >> "$GITHUB_OUTPUT" + fi + + - name: Build test-generator + if: steps.sync.outputs.exit_code != '0' && steps.parse.outputs.exercises_json != '[]' + run: ./test-generator/gradlew -p test-generator installDist --quiet + + - name: Sync tests per exercise (PR if passing, issue if failing) + if: steps.sync.outputs.exit_code != '0' && steps.parse.outputs.exercises_json != '[]' + shell: bash + env: + EXERCISES_JSON: ${{ steps.parse.outputs.exercises_json }} + DETAILS: ${{ steps.parse.outputs.details }} + PARENT_NUMBER: ${{ steps.find_parent.outputs.parent_number }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} + run: | + repo="${{ github.repository }}" + base_branch="${DEFAULT_BRANCH:-main}" + base_sha="$(git rev-parse HEAD)" + + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + + mapfile -t exercises < <(printf "%s\n" "$EXERCISES_JSON" | jq -r '.[]') + + for slug in "${exercises[@]}"; do + printf "\n========================================\n" + printf "Processing exercise: %s\n" "$slug" + printf "========================================\n" + + branch_name="sync-tests-${slug}" + git checkout -f -B "$branch_name" "$base_sha" + git clean -fd exercises/practice + + # Collect missing tests for this exercise + missing_tests="" + while IFS=$'\t' read -r es_slug test_name uuid; do + [[ "$es_slug" == "$slug" ]] || continue + missing_tests+="- \`${uuid}\` ${test_name}"$'\n' + done <<< "$DETAILS" + + parent_ref="" + [[ -n "$PARENT_NUMBER" ]] && parent_ref="Part of #${PARENT_NUMBER}." + + child_title="[configlet] ${slug}: missing test cases" + existing_issue=$(gh issue list \ + --repo "$repo" \ + --search "is:issue is:open in:title \"${child_title}\"" \ + --json number \ + --jq '.[0].number // empty') + + log_file=$(mktemp) + sync_ok=true + + if ! ./bin/configlet sync --tests=include --update --yes --exercise "$slug" >> "$log_file" 2>&1; then + sync_ok=false + printf "configlet sync failed for %s\n" "$slug" + elif ! ./bin/generate-tests -e "$slug" >> "$log_file" 2>&1; then + sync_ok=false + printf "generate-tests failed for %s\n" "$slug" + elif ! ./exercises/gradlew -p exercises ":practice:${slug}:check" ":practice:${slug}:compileStarterTestJava" >> "$log_file" 2>&1; then + sync_ok=false + printf "Gradle verification failed for %s\n" "$slug" + fi + + if [[ "$sync_ok" == "true" && -n "$(git status --porcelain "exercises/practice/${slug}")" ]]; then + git add "exercises/practice/${slug}" + git commit -m "🤖 ${slug}: sync missing test cases" + + needs_push=true + if git ls-remote --exit-code --heads origin "$branch_name" >/dev/null 2>&1; then + git fetch origin "$branch_name" --depth=1 + if [[ "$(git rev-parse 'HEAD^{tree}')" == "$(git rev-parse 'FETCH_HEAD^{tree}')" ]]; then + needs_push=false + fi + fi + + if [[ "$needs_push" == "true" ]]; then + git push --force origin "$branch_name" + else + printf "Remote branch %s is already up to date.\n" "$branch_name" + fi + + closes_ref="" + [[ -n "$existing_issue" ]] && closes_ref="Closes #${existing_issue}." + + body_file=$(mktemp) + cat > "$body_file" << PR_BODY_EOF + ## Sync test cases for \`${slug}\` + + ${parent_ref} + ${closes_ref} + + This PR was generated automatically by syncing \`.meta/tests.toml\`, regenerating tests with \`./bin/generate-tests -e ${slug}\`, and verifying \`:practice:${slug}:check\` and \`:practice:${slug}:compileStarterTestJava\`. + + ### Synced test cases + + ${missing_tests} + _This PR is managed automatically by the [Sync Tests](${{ github.server_url }}/${{ github.repository }}/actions/workflows/sync-tests.yml) workflow._ + PR_BODY_EOF + + pr_title="🤖 ${slug}: sync missing test cases" + existing_pr=$(gh pr list \ + --repo "$repo" \ + --head "$branch_name" \ + --state open \ + --json number \ + --jq '.[0].number // empty') + + if [[ -z "$existing_pr" ]]; then + printf "Creating PR for: %s\n" "$slug" + pr_url=$(gh pr create \ + --repo "$repo" \ + --base "$base_branch" \ + --head "$branch_name" \ + --title "$pr_title" \ + --body-file "$body_file" \ + --label "x:module/practice-exercise") + printf "Created PR %s for %s\n" "$pr_url" "$slug" + else + printf "Updating existing PR #%s for: %s\n" "$existing_pr" "$slug" + gh pr edit "$existing_pr" \ + --repo "$repo" \ + --body-file "$body_file" + fi + + rm -f "$body_file" + elif [[ "$sync_ok" == "true" ]]; then + printf "No file changes produced for %s after sync; skipping PR.\n" "$slug" + else + printf "Auto-sync verification failed for %s; creating/updating child issue.\n" "$slug" + failure_tail=$(tail -n 60 "$log_file") + + body_file=$(mktemp) + cat > "$body_file" << ISSUE_BODY_EOF + ## Missing test cases for \`${slug}\` + + ${parent_ref} + + The following test cases from [problem-specifications](https://github.com/exercism/problem-specifications/tree/main/exercises/${slug}) are not yet implemented in this track: + + ${missing_tests} + > [!WARNING] + > Automated test sync/generation failed verification for \`${slug}\` (\`:practice:${slug}:check\` / \`:practice:${slug}:compileStarterTestJava\`), so no automated PR was opened. + +
+ Failure output (last 60 lines) + + \`\`\` + ${failure_tail} + \`\`\` + +
+ + ### How to help + + For detailed instructions on how to fetch configlet and update the tests, please see the **"How to do this task"** section in the main tracking issue: + 👉 **[Read the instructions here](${{ github.server_url }}/${{ github.repository }}/issues/${PARENT_NUMBER:-none})** + + _This issue is managed automatically by the [Sync Tests](${{ github.server_url }}/${{ github.repository }}/actions/workflows/sync-tests.yml) workflow._ + ISSUE_BODY_EOF + + if [[ -z "$existing_issue" ]]; then + printf "Creating child issue for: %s\n" "$slug" + issue_url=$(gh issue create \ + --repo "$repo" \ + --title "$child_title" \ + --body-file "$body_file" \ + --label "x:knowledge/elementary,x:module/practice-exercise") + new_number=$(basename "$issue_url") + printf "Created #%s for %s\n" "$new_number" "$slug" + else + printf "Updating existing child issue #%s for: %s\n" "$existing_issue" "$slug" + gh issue edit "$existing_issue" \ + --repo "$repo" \ + --body-file "$body_file" + fi + + rm -f "$body_file" + fi + + rm -f "$log_file" + git checkout -f "$base_sha" + git clean -fd exercises/practice + done + + - name: All tests synced — nothing to do + if: steps.sync.outputs.exit_code == '0' + run: printf "✅ All exercises are fully synced. No PRs or child issues needed.\n" diff --git a/test-generator/src/main/java/exercism/testgenerator/TestGeneratorApp.java b/test-generator/src/main/java/exercism/testgenerator/TestGeneratorApp.java index 97c391d8e..b024121cb 100644 --- a/test-generator/src/main/java/exercism/testgenerator/TestGeneratorApp.java +++ b/test-generator/src/main/java/exercism/testgenerator/TestGeneratorApp.java @@ -109,7 +109,7 @@ public Integer call() { return 1; } - System.out.printf("🚀 Running Exercism Java Test Generator for %d exercise(s)...%n%n", targets.size()); + System.out.printf("Running Exercism Java Test Generator for %d exercise(s)...%n%n", targets.size()); int defaultTemplateCount = 0; int customTemplateCount = 0; @@ -119,7 +119,7 @@ public Integer call() { for (String slug : targets) { Path exerciseDir = practiceDir.resolve(slug); if (!Files.isDirectory(exerciseDir)) { - System.err.printf("❌ Exercise '%s' not found at %s%n", slug, exerciseDir); + System.err.printf("[FAIL] Exercise '%s' not found at %s%n", slug, exerciseDir); failureCount++; continue; } @@ -128,7 +128,7 @@ public Integer call() { try { if (!audit) { - System.out.printf("🔄 Processing '%s'...", slug); + System.out.printf("Processing '%s'... ", slug); } ExerciseTestGenerator.GenerationResult result = generator.generate(exerciseDir); @@ -137,7 +137,7 @@ public Integer call() { if (audit) { System.out.printf(" [SKIP] %-28s (all test cases excluded in tests.toml)%n", slug); } else { - System.out.printf(" ⚠️ Skipped '%s': all test cases excluded in tests.toml%n", slug); + System.out.printf("[SKIP] all test cases excluded in tests.toml%n"); } continue; } @@ -152,14 +152,14 @@ public Integer call() { String templateType = hasCustomTemplate ? "custom template" : "default template"; System.out.printf(" [OK] %-30s (%2d cases, %s)%n", slug, result.includedCasesCount(), templateType); } else if (dryRun) { - System.out.printf(" [DRY RUN - %d tests included, %d excluded]%n", + System.out.printf("[DRY RUN - %d tests included, %d excluded]%n", result.includedCasesCount(), result.excludedCasesCount()); System.out.println("----------------------------------------"); System.out.println(result.content()); System.out.println("----------------------------------------"); } else { result.writeToFile(); - System.out.printf(" ✅ Generated %s (%d test cases included, %d excluded)%n", + System.out.printf("[OK] Generated %s (%d test cases included, %d excluded)%n", repoRoot.relativize(result.targetTestPath()), result.includedCasesCount(), result.excludedCasesCount()); @@ -169,14 +169,14 @@ public Integer call() { if (audit) { System.out.printf(" [SKIP] %-28s (track-specific, no upstream canonical data)%n", slug); } else { - System.out.printf(" ⚠️ Skipped: %s%n", e.getMessage()); + System.out.printf("[SKIP] %s%n", e.getMessage()); } } catch (Exception e) { failureCount++; if (audit) { System.out.printf(" [FAIL] %-28s : %s%n", slug, e.getMessage()); } else { - System.out.printf(" ❌ Failed: %s%n", e.getMessage()); + System.out.printf("[FAIL] %s%n", e.getMessage()); } } }