All checks were successful
CI/CD Semantic Release / release (push) Successful in 4m7s
129 lines
4.8 KiB
YAML
129 lines
4.8 KiB
YAML
name: CI/CD Semantic Release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout del código
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
persist-credentials: false
|
|
|
|
- name: Preparar entorno Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '18'
|
|
|
|
- name: Instalar Semantic Release y Plugins
|
|
run: npm install -D semantic-release @saithodev/semantic-release-gitea @semantic-release/changelog @semantic-release/git @semantic-release/exec
|
|
|
|
- name: Generar configuración de Release
|
|
env:
|
|
# Inyectamos el token aquí para poder construir la URL de Git
|
|
GITEA_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
|
|
run: |
|
|
# Construimos la URL de Git con el token incrustado
|
|
REPO_URL_WITH_TOKEN="https://gitea_actions:${GITEA_TOKEN}@repo.eldiaservicios.com/${{ github.repository }}.git"
|
|
|
|
cat << EOF > .releaserc.json
|
|
{
|
|
"branches": ["main"],
|
|
"repositoryUrl": "${REPO_URL_WITH_TOKEN}",
|
|
"plugins":[
|
|
"@semantic-release/commit-analyzer",
|
|
"@semantic-release/release-notes-generator",
|
|
"@semantic-release/changelog",
|
|
[
|
|
"@semantic-release/git",
|
|
{
|
|
"assets": ["CHANGELOG.md"],
|
|
"message": "chore(release): \${nextRelease.version} [skip ci]\n\n\${nextRelease.notes}"
|
|
}
|
|
],
|
|
[
|
|
"@saithodev/semantic-release-gitea",
|
|
{
|
|
"giteaUrl": "https://repo.eldiaservicios.com"
|
|
}
|
|
],
|
|
[
|
|
"@semantic-release/exec",
|
|
{
|
|
"successCmd": "echo 'RELEASE_CREATED=true' >> \$GITHUB_ENV && echo 'TAG_NAME=\${nextRelease.gitTag}' >> \$GITHUB_ENV"
|
|
}
|
|
]
|
|
]
|
|
}
|
|
EOF
|
|
|
|
- name: Ejecutar Semantic Release
|
|
env:
|
|
# Este GITEA_TOKEN es para el plugin de Gitea (crear el release)
|
|
GITEA_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
|
|
run: npx semantic-release
|
|
|
|
- name: 🤖 Generar notas con IA Local (Ollama)
|
|
if: env.RELEASE_CREATED == 'true'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.RELEASE_PLEASE_TOKEN }}
|
|
REPO: ${{ github.repository }}
|
|
TAG_NAME: ${{ env.TAG_NAME }}
|
|
run: |
|
|
node -e '
|
|
async function run() {
|
|
const giteaUrl = "https://repo.eldiaservicios.com/api/v1";
|
|
const ollamaUrl = "http://192.168.10.78:11434/api/generate";
|
|
|
|
console.log(`Obteniendo la release ${process.env.TAG_NAME} de Gitea...`);
|
|
const relRes = await fetch(`${giteaUrl}/repos/${process.env.REPO}/releases/tags/${process.env.TAG_NAME}`, {
|
|
headers: { "Authorization": `token ${process.env.GITEA_TOKEN}` }
|
|
});
|
|
const relData = await relRes.json();
|
|
const rawNotes = relData.body;
|
|
|
|
const prompt = `Eres un redactor experto de notas de lanzamiento (release notes).
|
|
Tu misión es transformar una lista técnica de commits en un anuncio acotado, profesional y descriptivo.
|
|
|
|
Instrucciones:
|
|
- Usa Markdown elegante.
|
|
- Usa emojis que tengan sentido.
|
|
- Agrupa por secciones (Ej: 🚀 Novedades, 🛠️ Mejoras Técnicas).
|
|
- El tono debe ser entusiasta pero profesional.
|
|
- Escribe exclusivamente en español.
|
|
|
|
Lista de cambios original:
|
|
${rawNotes}`;
|
|
|
|
console.log("Conectando con Ollama en tu PC para generar notas...");
|
|
const aiRes = await fetch(ollamaUrl, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({
|
|
model: "llama3.1",
|
|
prompt: prompt,
|
|
stream: false
|
|
})
|
|
});
|
|
const aiData = await aiRes.json();
|
|
const aiNotes = aiData.response;
|
|
|
|
console.log("Actualizando la Release en Gitea...");
|
|
await fetch(`${giteaUrl}/repos/${process.env.REPO}/releases/${relData.id}`, {
|
|
method: "PATCH",
|
|
headers: {
|
|
"Authorization": `token ${process.env.GITEA_TOKEN}`,
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify({ body: aiNotes })
|
|
});
|
|
|
|
console.log("¡Release Notes actualizadas por la IA!");
|
|
}
|
|
run().catch(err => { console.error(err); process.exit(1); });
|
|
' |