Skip to content

Commit 634261a

Browse files
Refactor generate-tests workflow for clarity and updates
1 parent 397a72f commit 634261a

1 file changed

Lines changed: 11 additions & 23 deletions

File tree

.github/workflows/generate-tests.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
name: 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.
53
on:
64
workflow_dispatch:
75
inputs:
@@ -23,8 +21,6 @@ jobs:
2321
name: Generate Unit Tests with Claude
2422
runs-on: ubuntu-latest
2523

26-
# workflow_dispatch: sempre roda
27-
# workflow_run: só roda se CI passou e não foi aberto pelo bot
2824
if: |
2925
github.event_name == 'workflow_dispatch' ||
3026
(
@@ -33,28 +29,23 @@ jobs:
3329
)
3430
3531
steps:
36-
# ── 1. Normaliza contexto para os dois gatilhos ───────────────────────────
3732
- name: Resolve trigger context
3833
id: ctx
3934
run: |
4035
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
41-
echo "head_sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
42-
echo "pr_number=manual" >> "$GITHUB_OUTPUT"
36+
echo "head_sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
37+
echo "pr_number=manual" >> "$GITHUB_OUTPUT"
4338
else
44-
echo "head_sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT"
45-
echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT"
39+
echo "head_sha=${{ github.event.workflow_run.head_sha }}" >> "$GITHUB_OUTPUT"
40+
echo "pr_number=${{ github.event.workflow_run.pull_requests[0].number }}" >> "$GITHUB_OUTPUT"
4641
fi
4742
48-
# ── 2. Checkout ───────────────────────────────────────────────────────────
4943
- name: Checkout
5044
uses: actions/checkout@v4
5145
with:
52-
repository: CodandoTV/CraftD
5346
ref: ${{ steps.ctx.outputs.head_sha }}
5447
fetch-depth: 0
55-
token: ${{ secrets.GH_PAT }}
5648

57-
# ── 3. Python ─────────────────────────────────────────────────────────────
5849
- name: Set up Python
5950
uses: actions/setup-python@v5
6051
with:
@@ -63,17 +54,16 @@ jobs:
6354
- name: Install Python dependencies
6455
run: pip install anthropic
6556

66-
# ── 4. Escaneia craftd-core buscando arquivos sem cobertura ──────────────
6757
- name: Find uncovered Kotlin files in craftd-core
6858
id: changed
6959
run: |
7060
OVERRIDE="${{ github.event.inputs.override_files }}"
7161
7262
if [ -n "$OVERRIDE" ]; then
7363
UNCOVERED=$(echo "$OVERRIDE" | tr ' ' '\n' | grep -v "^$" || true)
74-
echo "Modo override arquivos informados manualmente:"
64+
echo "Modo override, arquivos informados manualmente:"
7565
else
76-
echo "Scan completo buscando arquivos sem cobertura em craftd-core..."
66+
echo "Scan completo, buscando arquivos sem cobertura em craftd-core..."
7767
UNCOVERED=""
7868
while IFS= read -r SRC; do
7969
TEST=$(echo "$SRC" \
@@ -96,18 +86,18 @@ jobs:
9686
echo "Nenhum arquivo sem cobertura. Nada a fazer."
9787
else
9888
echo "has_changes=true" >> "$GITHUB_OUTPUT"
99-
printf "files<<EOF\n%s\nEOF\n" "$UNCOVERED" >> "$GITHUB_OUTPUT"
89+
printf "files<<EOF\n%s\nEOF\n" "$UNCOVER_OUTPUT"
10090
fi
91+
env:
92+
UNCOVER_OUTPUT: $GITHUB_OUTPUT
10193

102-
# ── 5. Chama Claude API para gerar os testes ─────────────────────────────
10394
- name: Generate unit tests with Claude API
10495
if: steps.changed.outputs.has_changes == 'true'
10596
env:
10697
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
10798
CHANGED_FILES: ${{ steps.changed.outputs.files }}
10899
run: python .github/scripts/generate_tests.py
109100

110-
# ── 6. Verifica se arquivos foram gerados ─────────────────────────────────
111101
- name: Check generated files
112102
if: steps.changed.outputs.has_changes == 'true'
113103
id: check
@@ -127,15 +117,14 @@ jobs:
127117
echo "has_tests=false" >> "$GITHUB_OUTPUT"
128118
fi
129119
130-
# ── 7. Cria branch e commita os testes ────────────────────────────────────
131120
- name: Commit generated tests
132121
if: steps.check.outputs.has_tests == 'true'
133122
id: commit
134123
run: |
135124
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
136125
BRANCH="chore/add-tests-craftd-core-pr-${PR_NUMBER}"
137126
138-
git config user.name "github-actions[bot]"
127+
git config user.name "github-actions[bot]"
139128
git config user.email "github-actions[bot]@users.noreply.github.com"
140129
141130
git checkout -b "$BRANCH"
@@ -145,11 +134,10 @@ jobs:
145134
146135
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
147136
148-
# ── 8. Abre PR com os testes gerados ──────────────────────────────────────
149137
- name: Open Pull Request with generated tests
150138
if: steps.check.outputs.has_tests == 'true'
151139
env:
152-
GH_TOKEN: ${{ secrets.GH_PAT }}
140+
GH_TOKEN: ${{ github.token }}
153141
run: |
154142
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
155143
BRANCH="${{ steps.commit.outputs.branch }}"

0 commit comments

Comments
 (0)