From ab99204d383d07cadc0bb61478714bc7de277bdd Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 3 Dec 2026 00:51:46 +0530 Subject: [PATCH 1/4] modify workflow to raise PR using test generator --- .../create-configlet-sync-issues.yml | 201 ++++++++++++++---- 1 file changed, 161 insertions(+), 40 deletions(-) diff --git a/.github/workflows/create-configlet-sync-issues.yml b/.github/workflows/create-configlet-sync-issues.yml index 07a0ed615..dd5f2e2c4 100644 --- a/.github/workflows/create-configlet-sync-issues.yml +++ b/.github/workflows/create-configlet-sync-issues.yml @@ -2,16 +2,17 @@ name: Create Configlet Sync Issues on: workflow_call: - workflow_dispatch: + workflow_dispatch: permissions: issues: write - contents: read + contents: write + pull-requests: write jobs: create-sync-issues: runs-on: ubuntu-24.04 - timeout-minutes: 15 + timeout-minutes: 30 env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -21,6 +22,12 @@ jobs: - 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 @@ -43,11 +50,11 @@ jobs: id: parse if: steps.sync.outputs.exit_code != '0' shell: bash + env: + SYNC_OUTPUT: ${{ steps.sync.outputs.output }} 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)') + 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" @@ -79,7 +86,7 @@ jobs: elif [[ "$line" =~ ^\[warn\] && ! "$line" =~ missing ]]; then current_slug="" fi - done <<< "$output" + done <<< "$SYNC_OUTPUT" printf "DETAILS_EOF\n" } >> "$GITHUB_OUTPUT" @@ -102,20 +109,36 @@ jobs: printf "parent_number=%s\n" "$issue_data" >> "$GITHUB_OUTPUT" fi - - name: Create or update child issues per exercise + - 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 - child_title="[configlet] ${slug}: missing test cases" + 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="" @@ -127,50 +150,148 @@ jobs: 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 + 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 --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 [Create Configlet Sync Issues](${{ github.server_url }}/${{ github.repository }}/actions/workflows/create-configlet-sync-issues.yml) workflow._ + PR_BODY_EOF + + pr_title="[configlet] ${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"})** - + 👉 **[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_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 - 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" + rm -f "$body_file" fi - rm -f "$body_file" + 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 child issues needed.\n" + run: printf "✅ All exercises are fully synced. No PRs or child issues needed.\n" From 4207e9be8c9b83dfc94b5ec464f5d9e16819f83b Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 3 Dec 2026 02:19:53 +0530 Subject: [PATCH 2/4] fix: pass --tests=include to configlet sync for non-interactive CI runs --- .github/workflows/create-configlet-sync-issues.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/create-configlet-sync-issues.yml b/.github/workflows/create-configlet-sync-issues.yml index dd5f2e2c4..e41ede787 100644 --- a/.github/workflows/create-configlet-sync-issues.yml +++ b/.github/workflows/create-configlet-sync-issues.yml @@ -160,7 +160,7 @@ jobs: log_file=$(mktemp) sync_ok=true - if ! ./bin/configlet sync --tests --update --yes --exercise "$slug" >> "$log_file" 2>&1; then + 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 From 83a8e8abbb495c1373a7e31df8d7b4d6e33d90de Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 3 Dec 2026 16:52:16 +0530 Subject: [PATCH 3/4] use flat sync-tests- branch name to avoid ref conflicts --- .../workflows/create-configlet-sync-issues.yml | 4 ++-- .../exercism/testgenerator/TestGeneratorApp.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/create-configlet-sync-issues.yml b/.github/workflows/create-configlet-sync-issues.yml index e41ede787..bbb1b2819 100644 --- a/.github/workflows/create-configlet-sync-issues.yml +++ b/.github/workflows/create-configlet-sync-issues.yml @@ -136,7 +136,7 @@ jobs: printf "Processing exercise: %s\n" "$slug" printf "========================================\n" - branch_name="sync-tests/${slug}" + branch_name="sync-tests-${slug}" git checkout -f -B "$branch_name" "$base_sha" git clean -fd exercises/practice @@ -207,7 +207,7 @@ jobs: _This PR is managed automatically by the [Create Configlet Sync Issues](${{ github.server_url }}/${{ github.repository }}/actions/workflows/create-configlet-sync-issues.yml) workflow._ PR_BODY_EOF - pr_title="[configlet] ${slug}: sync missing test cases" + pr_title="🤖 ${slug}: sync missing test cases" existing_pr=$(gh pr list \ --repo "$repo" \ --head "$branch_name" \ 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()); } } } From 06aff08cf578ecd6ce6a70c71414593511b564dc Mon Sep 17 00:00:00 2001 From: Jagdish Prajapati Date: Thu, 3 Dec 2026 17:17:11 +0530 Subject: [PATCH 4/4] Rename workflow --- .github/workflows/run-configlet-sync.yml | 4 ++-- .../{create-configlet-sync-issues.yml => sync-tests.yml} | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) rename .github/workflows/{create-configlet-sync-issues.yml => sync-tests.yml} (96%) 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/create-configlet-sync-issues.yml b/.github/workflows/sync-tests.yml similarity index 96% rename from .github/workflows/create-configlet-sync-issues.yml rename to .github/workflows/sync-tests.yml index bbb1b2819..6d8075978 100644 --- a/.github/workflows/create-configlet-sync-issues.yml +++ b/.github/workflows/sync-tests.yml @@ -1,4 +1,4 @@ -name: Create Configlet Sync Issues +name: Sync Tests on: workflow_call: @@ -10,7 +10,7 @@ permissions: pull-requests: write jobs: - create-sync-issues: + sync-tests: runs-on: ubuntu-24.04 timeout-minutes: 30 @@ -204,7 +204,7 @@ jobs: ### Synced test cases ${missing_tests} - _This PR is managed automatically by the [Create Configlet Sync Issues](${{ github.server_url }}/${{ github.repository }}/actions/workflows/create-configlet-sync-issues.yml) workflow._ + _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" @@ -265,7 +265,7 @@ jobs: 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._ + _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