Skip to content

Commit e7b426e

Browse files
Merge pull request #95 from CodandoTV/update-workflow-generate-tests.yml
Refactor generate-tests workflow for clarity and updates
2 parents cdf2115 + 634261a commit e7b426e

2 files changed

Lines changed: 345 additions & 22 deletions

File tree

.github/workflows/generate-tests.yml

Lines changed: 11 additions & 22 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,27 +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
5548

56-
# ── 3. Python ─────────────────────────────────────────────────────────────
5749
- name: Set up Python
5850
uses: actions/setup-python@v5
5951
with:
@@ -62,17 +54,16 @@ jobs:
6254
- name: Install Python dependencies
6355
run: pip install anthropic
6456

65-
# ── 4. Escaneia craftd-core buscando arquivos sem cobertura ──────────────
6657
- name: Find uncovered Kotlin files in craftd-core
6758
id: changed
6859
run: |
6960
OVERRIDE="${{ github.event.inputs.override_files }}"
7061
7162
if [ -n "$OVERRIDE" ]; then
7263
UNCOVERED=$(echo "$OVERRIDE" | tr ' ' '\n' | grep -v "^$" || true)
73-
echo "Modo override arquivos informados manualmente:"
64+
echo "Modo override, arquivos informados manualmente:"
7465
else
75-
echo "Scan completo buscando arquivos sem cobertura em craftd-core..."
66+
echo "Scan completo, buscando arquivos sem cobertura em craftd-core..."
7667
UNCOVERED=""
7768
while IFS= read -r SRC; do
7869
TEST=$(echo "$SRC" \
@@ -95,18 +86,18 @@ jobs:
9586
echo "Nenhum arquivo sem cobertura. Nada a fazer."
9687
else
9788
echo "has_changes=true" >> "$GITHUB_OUTPUT"
98-
printf "files<<EOF\n%s\nEOF\n" "$UNCOVERED" >> "$GITHUB_OUTPUT"
89+
printf "files<<EOF\n%s\nEOF\n" "$UNCOVER_OUTPUT"
9990
fi
91+
env:
92+
UNCOVER_OUTPUT: $GITHUB_OUTPUT
10093

101-
# ── 5. Chama Claude API para gerar os testes ─────────────────────────────
10294
- name: Generate unit tests with Claude API
10395
if: steps.changed.outputs.has_changes == 'true'
10496
env:
10597
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
10698
CHANGED_FILES: ${{ steps.changed.outputs.files }}
10799
run: python .github/scripts/generate_tests.py
108100

109-
# ── 6. Verifica se arquivos foram gerados ─────────────────────────────────
110101
- name: Check generated files
111102
if: steps.changed.outputs.has_changes == 'true'
112103
id: check
@@ -126,15 +117,14 @@ jobs:
126117
echo "has_tests=false" >> "$GITHUB_OUTPUT"
127118
fi
128119
129-
# ── 7. Cria branch e commita os testes ────────────────────────────────────
130120
- name: Commit generated tests
131121
if: steps.check.outputs.has_tests == 'true'
132122
id: commit
133123
run: |
134124
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
135125
BRANCH="chore/add-tests-craftd-core-pr-${PR_NUMBER}"
136126
137-
git config user.name "github-actions[bot]"
127+
git config user.name "github-actions[bot]"
138128
git config user.email "github-actions[bot]@users.noreply.github.com"
139129
140130
# Autentica o push com GH_PAT via URL do remote
@@ -147,11 +137,10 @@ jobs:
147137
148138
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
149139
150-
# ── 8. Abre PR com os testes gerados ──────────────────────────────────────
151140
- name: Open Pull Request with generated tests
152141
if: steps.check.outputs.has_tests == 'true'
153142
env:
154-
GH_TOKEN: ${{ secrets.GH_PAT }}
143+
GH_TOKEN: ${{ github.token }}
155144
run: |
156145
PR_NUMBER="${{ steps.ctx.outputs.pr_number }}"
157146
BRANCH="${{ steps.commit.outputs.branch }}"

0 commit comments

Comments
 (0)