11name : Auto Generate Cover+Test
22
3- # Dispara automaticamente após o CI (Build and Test for PRs) passar,
4- # ou manualmente via Actions > Run workflow para testes pontuais.
3+ # Execução manual apenas — acesse Actions > Auto Generate Cover+Test > Run workflow.
4+ # Deixe override_files vazio para escanear todos os arquivos sem cobertura em craftd-core,
5+ # ou informe arquivos .kt específicos separados por espaço.
56on :
67 workflow_dispatch :
78 inputs :
1011 required : false
1112 default : ' '
1213
13- workflow_run :
14- workflows : ["Build and Test for PRs"]
15- types : [completed]
16-
1714permissions :
1815 contents : write
1916 pull-requests : write
@@ -23,41 +20,15 @@ jobs:
2320 name : Generate Unit Tests with Claude
2421 runs-on : ubuntu-latest
2522
26- # workflow_dispatch: sempre roda
27- # workflow_run: só roda se CI passou e não foi aberto pelo bot
28- if : |
29- github.event_name == 'workflow_dispatch' ||
30- (
31- github.event.workflow_run.conclusion == 'success' &&
32- github.event.workflow_run.actor.login != 'github-actions[bot]'
33- )
34-
3523 steps :
36- # ── 1. Normaliza contexto para os dois gatilhos ───────────────────────────
37- - name : Resolve trigger context
38- id : ctx
39- run : |
40- if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
41- echo "head_sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
42- echo "base_ref=main" >> "$GITHUB_OUTPUT"
43- echo "pr_number=manual" >> "$GITHUB_OUTPUT"
44- echo "is_manual=true" >> "$GITHUB_OUTPUT"
45- else
46- echo "head_sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT"
47- echo "base_ref=${{ github.event.workflow_run.pull_requests[0].base.ref }}" >> "$GITHUB_OUTPUT"
48- echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT"
49- echo "is_manual=false" >> "$GITHUB_OUTPUT"
50- fi
51-
52- # ── 2. Checkout ───────────────────────────────────────────────────────────
24+ # ── 1. Checkout ───────────────────────────────────────────────────────────
5325 - name : Checkout
5426 uses : actions/checkout@v4
5527 with :
56- ref : ${{ steps.ctx.outputs.head_sha }}
5728 fetch-depth : 0
58- token : ${{ secrets.GITHUB_TOKEN }}
29+ token : ${{ secrets.GH_PAT }}
5930
60- # ── 3 . Python ─────────────────────────────────────────────────────────────
31+ # ── 2 . Python ─────────────────────────────────────────────────────────────
6132 - name : Set up Python
6233 uses : actions/setup-python@v5
6334 with :
6637 - name : Install Python dependencies
6738 run : pip install anthropic
6839
69- # ── 4. Escaneia craftd-core buscando arquivos sem cobertura ──────────────
70- # Se override_files for informado no dispatch, usa eles no lugar.
40+ # ── 3. Escaneia craftd-core buscando arquivos sem cobertura ──────────────
7141 - name : Find uncovered Kotlin files in craftd-core
7242 id : changed
7343 run : |
@@ -103,15 +73,15 @@ jobs:
10373 printf "files<<EOF\n%s\nEOF\n" "$UNCOVERED" >> "$GITHUB_OUTPUT"
10474 fi
10575
106- # ── 5 . Chama Claude API para gerar os testes ─────────────────────────────
76+ # ── 4 . Chama Claude API para gerar os testes ─────────────────────────────
10777 - name : Generate unit tests with Claude API
10878 if : steps.changed.outputs.has_changes == 'true'
10979 env :
11080 ANTHROPIC_API_KEY : ${{ secrets.ANTHROPIC_API_KEY }}
11181 CHANGED_FILES : ${{ steps.changed.outputs.files }}
11282 run : python .github/scripts/generate_tests.py
11383
114- # ── 6 . Verifica se arquivos foram gerados ─────────────────────────────────
84+ # ── 5 . Verifica se arquivos foram gerados ─────────────────────────────────
11585 - name : Check generated files
11686 if : steps.changed.outputs.has_changes == 'true'
11787 id : check
@@ -131,13 +101,12 @@ jobs:
131101 echo "has_tests=false" >> "$GITHUB_OUTPUT"
132102 fi
133103
134- # ── 7 . Cria branch e commita os testes ────────────────────────────────────
104+ # ── 6 . Cria branch e commita os testes ────────────────────────────────────
135105 - name : Commit generated tests
136106 if : steps.check.outputs.has_tests == 'true'
137107 id : commit
138108 run : |
139- PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
140- BRANCH="chore/add-tests-craftd-core-pr-${PR_NUMBER}"
109+ BRANCH="chore/add-tests-craftd-core-$(date +%Y%m%d-%H%M%S)"
141110
142111 git config user.name "github-actions[bot]"
143112 git config user.email "github-actions[bot]@users.noreply.github.com"
@@ -149,19 +118,17 @@ jobs:
149118
150119 echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
151120
152- # ── 8 . Abre PR com os testes gerados ──────────────────────────────────────
121+ # ── 7 . Abre PR com os testes gerados ──────────────────────────────────────
153122 - name : Open Pull Request with generated tests
154123 if : steps.check.outputs.has_tests == 'true'
155124 env :
156- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
125+ GH_TOKEN : ${{ secrets.GH_PAT }}
157126 run : |
158- PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
159127 BRANCH="${{ steps.commit.outputs.branch }}"
160- BASE_BRANCH="${{ steps.ctx.outputs.base_ref }}"
161128 COVERED="${{ steps.check.outputs.covered_names }}"
162129
163130 gh pr create \
164- --base "$BASE_BRANCH " \
131+ --base "main " \
165132 --head "$BRANCH" \
166133 --title "[Auto] Add unit tests for craftd-core" \
167134 --body "$(cat <<EOF
@@ -175,16 +142,14 @@ jobs:
175142 \`\`\`
176143
177144 ### Como funciona
178- 1. Um PR tocou arquivos em \`android_kmp/craftd-core\`
179- 2. Após o CI passar, o workflow escaneou todos os arquivos sem cobertura
145+ 1. Workflow executado manualmente via Actions
146+ 2. Escaneou todos os arquivos sem cobertura em \`android_kmp/craftd-core\`
180147 3. Claude gerou testes **JUnit4 + MockK** para cada arquivo
181148 4. Este PR foi criado automaticamente com o resultado
182149
183150 ### Checklist de revisão
184151 - [ ] Testes compilam sem erros (\`./gradlew testDebugUnitTest\`)
185152 - [ ] Testes cobrem os principais caminhos de lógica
186153 - [ ] Edge cases tratados (null, vazio, JSON inválido)
187-
188- > Triggered by PR #${PR_NUMBER}
189154 EOF
190155 )"
0 commit comments