-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (137 loc) · 6.55 KB
/
Copy pathsummarize-transcripts.yml
File metadata and controls
150 lines (137 loc) · 6.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# Gera lições ISS a partir de .vtt em downloads/ via API Cursor (@cursor/sdk).
# Publica em content/<disciplina>/ e atualiza content/lessons.json (só aulas em falta no catálogo).
# Anexa prompts ISS + contexto downloads/documents (config/documents-context.json).
# Requer secret: CURSOR_API_KEY (Dashboard Cursor → Integrations ou service account).
# Opcional: DISCORD_WEBHOOK_URL — notificação no fim do job (sucesso ou falha).
#
# Ajuste TRANSCRIPT_SUMMARY_MAX_FILES: 0 = todos os .vtt (pode demorar e consumir quota).
# Proteção de branch em main pode bloquear o push — use bypass com PAT ou regra para o bot.
name: Resumir transcrições (Cursor SDK)
on:
workflow_dispatch:
inputs:
max_files:
description: "Máximo de ficheiros .vtt a processar (0 = todos)"
required: false
type: string
default: "5"
force:
description: "1 = regenerar mesmo que a lição em content/ esteja atualizada"
required: false
type: string
default: "0"
schedule:
# Diário às 09:30 (America/Sao_Paulo) — comente se não quiser execução agendada
- cron: "30 9 * * *"
timezone: America/Sao_Paulo
concurrency:
group: summarize-transcripts-${{ github.repository }}
cancel-in-progress: true
permissions:
contents: write
jobs:
summarize:
runs-on: ubuntu-latest
timeout-minutes: 120
steps:
- name: Checkout main
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 1
- name: Configurar Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Instalar conversão Office→PDF e pdftotext
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
libreoffice-impress libreoffice-writer poppler-utils
- name: Substituir .ppt/.pptx por PDF em downloads/documents
run: node .github/scripts/convert-office-documents.mjs
- name: Instalar dependência Cursor SDK
shell: bash
run: |
set -euo pipefail
test -n "${{ secrets.CURSOR_API_KEY }}" || { echo "Secret CURSOR_API_KEY não definido no repositório."; exit 1; }
npm init -y >/dev/null
npm pkg set type=module
npm install @cursor/sdk@latest
- name: Gerar lições ISS em content/ a partir dos .vtt
id: summarize
shell: bash
env:
CURSOR_API_KEY: ${{ secrets.CURSOR_API_KEY }}
CURSOR_MODEL_ID: ${{ vars.CURSOR_MODEL_ID }}
TRANSCRIPT_SUMMARY_MAX_FILES: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.max_files || '5' }}
TRANSCRIPT_SUMMARY_FORCE: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.force || '0' }}
TRANSCRIPT_SUMMARY_MAX_CHARS: "100000"
TRANSCRIPT_SUMMARY_MAX_ATTEMPTS: "3"
DOCUMENT_CONTEXT_MAX_CHARS: "80000"
DOCUMENT_CONTEXT_MAX_FILE_CHARS: "25000"
run: |
set -o pipefail
node .github/scripts/summarize-transcripts.mjs 2>&1 | tee summarize.log
SUMMARY="$(grep -E '^Concluído\. Publicados:' summarize.log | tail -1 || true)"
FAILURES="$(grep -E '^Concluído\. Publicados:.*\| falhas: [1-9]' summarize.log | tail -1 || true)"
if [[ -n "$FAILURES" ]]; then
echo "::warning::Pipeline concluiu com falhas parciais — ver log summarize.log"
fi
if [[ -z "$SUMMARY" ]]; then
SUMMARY="(resumo não encontrado no log — ver Actions)"
fi
echo "pipeline_summary=$SUMMARY" >> "$GITHUB_OUTPUT"
LAST="$(grep -E '^Publicado:' summarize.log | tail -1 | sed 's/^Publicado: //' || true)"
echo "last_published=$LAST" >> "$GITHUB_OUTPUT"
NOTIFY="$(grep -E '^NotifyDiscord:' summarize.log | tail -1 | sed 's/^NotifyDiscord: //' || true)"
IFS=$'\t' read -r DISC_TITLE LESSON_TITLE LESSON_DESC <<< "$NOTIFY"
DISC_TITLE="$(echo "${DISC_TITLE:-}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
LESSON_TITLE="$(echo "${LESSON_TITLE:-}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
LESSON_DESC="$(echo "${LESSON_DESC:-}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
{
echo "last_discipline_title=$DISC_TITLE"
echo "last_lesson_title=$LESSON_TITLE"
echo "last_lesson_description<<EOF"
echo "$LESSON_DESC"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Exportar lições → JSON estruturado
run: node .github/scripts/export-lessons-json.mjs
- name: Commit e push para main
id: commit
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -- 'content/' 'config/' 'jsons/' 'agents/content-summary-agent.md' 'agents/content-summary-style-guide.md'
git add -- 'downloads/documents/**/*.pdf' 2>/dev/null || true
git add -u -- 'downloads/documents/' 2>/dev/null || true
if git diff --staged --quiet; then
echo "Nada para comitar."
echo "committed=false" >> "$GITHUB_OUTPUT"
echo "commit_info=Nada para comitar (content/ já atualizado)." >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "chore: lições ISS automáticas (VTT → content/) [skip ci]"
git push origin HEAD:main
echo "committed=true" >> "$GITHUB_OUTPUT"
echo "commit_info=Commit e push para \`main\` concluídos." >> "$GITHUB_OUTPUT"
- name: Notificar Discord
if: always()
shell: bash
env:
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}
JOB_STATUS: ${{ job.status }}
PIPELINE_SUMMARY: ${{ steps.summarize.outputs.pipeline_summary }}
LAST_PUBLISHED: ${{ steps.summarize.outputs.last_published }}
LAST_DISCIPLINE_TITLE: ${{ steps.summarize.outputs.last_discipline_title }}
LAST_LESSON_TITLE: ${{ steps.summarize.outputs.last_lesson_title }}
LAST_LESSON_DESCRIPTION: ${{ steps.summarize.outputs.last_lesson_description }}
COMMIT_INFO: ${{ steps.commit.outputs.commit_info }}
MAX_FILES: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.max_files || '5' }}
FORCE_FLAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.force || '0' }}
run: bash .github/scripts/discord-notify.sh