Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .claude/skills/publicar-version/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ Las etiquetas (`vX.Y.Z`), las releases y mover la etiqueta móvil `v1` las hace
3. **CHANGELOG.md**: mueve lo de «Sin publicar» a `## [X.Y.Z] - AAAA-MM-DD` con Añadido / Cambiado / Corregido en español y actualiza los enlaces de comparación del final (`[Sin publicar]` → `vX.Y.Z...HEAD` y una línea `[X.Y.Z]`).
4. **Docs**: README (solo lo de usuario), `docs/USO.md`, `docs/DESARROLLO.md`, `AGENTS.md` si cambian reglas, `MEMORY.md` (estado, decisiones con fecha, registro de sesiones) y `PLAN.md`.
5. **Cabecera del README** (solo si cambian los sprites): genera la galería (`go run ./cmd/commitling gallery --out out/site`) y rehaz `docs/img/banner.svg` copiando el grupo `<g class="bob">` de `svg/{seed,sprout,sapling,shrub}-happy.svg` y `svg/ancient-radiant.svg`, cada uno dentro de `<g transform="translate(x y) scale(0.6)">` (la animación va en el grupo interior, nunca en el que lleva `transform`, o la animación CSS lo anula).
6. **Comprueba**: `gofmt -l .`, `go vet ./...`, `GOFLAGS=-p=2 go test ./...`, el subagente `guardian-compatibilidad` y, si tocaste la web, la skill `probar-web`.
7. **Notas para Alberto** en el PR: «tras fusionar: release `vX.Y.Z` con las notas del CHANGELOG y, si es compatible, mover `v1` a ella».
6. **Binario precompilado (opcional)**: si quieres que la Action descargue el binario en vez de compilar, el último commit antes de la etiqueta debe incluir `release/checksums.txt` (`scripts/build-release.sh out/rel --write`, con la versión de Go de `go.mod`). El workflow `release.yml` sube los binarios al publicar la release. Si no lo haces, no pasa nada: la Action compila como siempre. Si vuelves a tocar código después, regenéralo o el CI fallará.
7. **Comprueba**: `gofmt -l .`, `go vet ./...`, `GOFLAGS=-p=2 go test ./...`, el subagente `guardian-compatibilidad` y, si tocaste la web, la skill `probar-web`.
8. **Notas para Alberto** en el PR: «tras fusionar: release `vX.Y.Z` con las notas del CHANGELOG y, si es compatible, mover `v1` a ella».
94 changes: 92 additions & 2 deletions .github/workflows/action-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
action:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

Expand All @@ -38,6 +38,15 @@ jobs:
species: mushroom
out: out/mushroom.svg

- name: Action con la especie cactus (sin red)
id: cactus
uses: ./
with:
user: ""
fixture: testdata/events.json
species: cactus
out: out/cactus.svg

- name: Action con la tarjeta compacta (sin red)
id: compact
uses: ./
Expand Down Expand Up @@ -129,6 +138,7 @@ jobs:
env:
FIXTURE_PATH: ${{ steps.fixture.outputs.path }}
MUSHROOM_PATH: ${{ steps.mushroom.outputs.path }}
CACTUS_PATH: ${{ steps.cactus.outputs.path }}
COMPACT_PATH: ${{ steps.compact.outputs.path }}
BADSIZE_OUTCOME: ${{ steps.badsize.outcome }}
REAL_PATH: ${{ steps.real.outputs.path }}
Expand All @@ -149,7 +159,7 @@ jobs:
test "$NOUSER_OUTCOME" = failure || { echo 'un usuario inexistente debería fallar'; exit 1; }
cmp out/nouser.svg "$FIXTURE_PATH" || { echo 'el SVG previo del usuario inexistente cambió'; exit 1; }
cmp out/keep.svg "$FIXTURE_PATH" || { echo 'el SVG previo cambió'; exit 1; }
for f in "$FIXTURE_PATH" "$MUSHROOM_PATH" "$COMPACT_PATH" "$REAL_PATH"; do
for f in "$FIXTURE_PATH" "$MUSHROOM_PATH" "$CACTUS_PATH" "$COMPACT_PATH" "$REAL_PATH"; do
test -s "$f"
head -c 120 "$f"; echo
grep -q '</svg>' "$f"
Expand All @@ -160,5 +170,85 @@ jobs:
grep -q 'Retoño' "$FIXTURE_PATH"
grep -q 'Seta' "$MUSHROOM_PATH"
if grep -q 'Retoño' "$MUSHROOM_PATH"; then echo 'la especie hongo no se aplicó'; exit 1; fi
grep -q 'Cactus' "$CACTUS_PATH"
if grep -q 'Retoño' "$CACTUS_PATH"; then echo 'la especie cactus no se aplicó'; exit 1; fi
grep -q "@$OWNER" "$REAL_PATH"
grep -q '#2b2724' "$REAL_PATH"

# The precompiled binary path of the Action (release/checksums.txt plus a
# release download), tested against a local server that plays the role of
# the release: a binary that matches is used without compiling; a tampered
# one or a missing release fall back to go run with the same SVG.
binario:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false

- name: Binarios reproducibles y release falsa en 127.0.0.1
run: |
set -euo pipefail
scripts/build-release.sh "$RUNNER_TEMP/rel"
version="$(sed -n 's/^var version = "\(.*\)"$/\1/p' cmd/commitling/main.go)"
mkdir -p release "$RUNNER_TEMP/www/v$version"
cp "$RUNNER_TEMP/rel/checksums.txt" release/checksums.txt
cp "$RUNNER_TEMP"/rel/commitling_* "$RUNNER_TEMP/www/v$version/"
nohup python3 -m http.server 8765 --bind 127.0.0.1 --directory "$RUNNER_TEMP/www" > "$RUNNER_TEMP/http.log" 2>&1 &
for _ in $(seq 1 20); do curl -fsS -o /dev/null http://127.0.0.1:8765/ && break; sleep 0.5; done
echo "COMMITLING_RELEASE_URL=http://127.0.0.1:8765" >> "$GITHUB_ENV"
echo "CL_VERSION=$version" >> "$GITHUB_ENV"
go run ./cmd/commitling render --fixture testdata/events.json --species cactus --out out/expected.svg

- name: Action con el binario precompilado
id: prebuilt
uses: ./
with:
user: ""
fixture: testdata/events.json
species: cactus
out: out/prebuilt.svg

- name: Se usó el binario y el SVG es el mismo
run: |
set -euo pipefail
test -x "$RUNNER_TEMP/commitling-bin/commitling_${CL_VERSION}_linux_amd64"
grep -q "GET /v${CL_VERSION}/commitling_${CL_VERSION}_linux_amd64 " "$RUNNER_TEMP/http.log"
cmp out/prebuilt.svg out/expected.svg

- name: Binario manipulado en la release
run: |
set -euo pipefail
rm -rf "$RUNNER_TEMP/commitling-bin"
printf '#!/bin/sh\necho manipulado\n' > "$RUNNER_TEMP/www/v${CL_VERSION}/commitling_${CL_VERSION}_linux_amd64"

- name: Action con el binario manipulado (se descarta)
uses: ./
with:
user: ""
fixture: testdata/events.json
species: cactus
out: out/tampered.svg

- name: Sin release publicada
run: echo "COMMITLING_RELEASE_URL=http://127.0.0.1:8765/no-existe" >> "$GITHUB_ENV"

- name: Action sin release (compila con Go)
uses: ./
with:
user: ""
fixture: testdata/events.json
species: cactus
out: out/norelease.svg

- name: Comprobar las alternativas
run: |
set -euo pipefail
test ! -e "$RUNNER_TEMP/commitling-bin/commitling_${CL_VERSION}_linux_amd64" || { echo 'el binario manipulado no se borró'; exit 1; }
cmp out/tampered.svg out/expected.svg
cmp out/norelease.svg out/expected.svg
27 changes: 22 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:
run:
shell: bash
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: actions/setup-go@v7
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
Expand Down Expand Up @@ -78,6 +78,23 @@ jobs:
- name: versión
run: go run ./cmd/commitling version

# The Action trusts release/checksums.txt: if it is committed, it must
# still be what this tree compiles to (reproducible build), or the
# Action would refuse the release binaries.
- name: binarios de release reproducibles
if: runner.os == 'Linux'
run: |
if [ -f release/checksums.txt ]; then
scripts/build-release.sh out/rel --check
else
scripts/build-release.sh out/rel
echo "Sin release/checksums.txt: la Action compila con go run (los SHA-256 de arriba son los de este commit)."
fi
# The environment cannot change the bytes (build-release.sh resets
# GOFLAGS and GOEXPERIMENT; -tags would be recorded in the binary).
GOFLAGS=-tags=zzz scripts/build-release.sh out/rel-env
diff -u out/rel/checksums.txt out/rel-env/checksums.txt

# Every workflow that the web generator and `commitling workflow` can
# produce (the web builds the same bytes; a test compares them) must be
# a valid GitHub Actions workflow that uses @v1: actionlint (official
Expand All @@ -92,7 +109,7 @@ jobs:
go build -o "$RUNNER_TEMP/commitling" ./cmd/commitling
mkdir -p out/wf
"$RUNNER_TEMP/commitling" workflow > out/wf/base.yml 2>/dev/null
for sp in moss mushroom; do for th in light dark both; do for sz in full compact; do
for sp in moss mushroom cactus; do for th in light dark both; do for sz in full compact; do
"$RUNNER_TEMP/commitling" workflow --user octocat --species "$sp" --theme "$th" --size "$sz" > "out/wf/$sp-$th-$sz.yml" 2>/dev/null
done; done; done
if grep -L 'uses: BertMarti/commitling@v1$' out/wf/*.yml | grep .; then echo "sin @v1"; exit 1; fi
Expand All @@ -118,12 +135,12 @@ jobs:
GOVULNCHECK_VERSION: "v1.9.0"
STATICCHECK_VERSION: "2026.2.2"
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- uses: actions/setup-go@v7
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:
permissions:
contents: read
steps:
- uses: actions/checkout@v7
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- uses: actions/setup-go@v7
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
"$cl" render --fixture testdata/events.json --theme dark --out "site/live/$LIVE_USER-dark.svg"
fi

- uses: actions/upload-pages-artifact@v5
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
with:
path: site

Expand All @@ -78,4 +78,4 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v5
uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
71 changes: 71 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Release

# Uploads the precompiled binaries to a release when it is published. It only
# runs then (nothing here creates releases or moves tags). The binaries are
# rebuilt from the tag with scripts/build-release.sh and must match the
# release/checksums.txt committed in that tag: that file is what the Action
# trusts. Without it, nothing is uploaded and the Action keeps compiling with
# go run.
on:
release:
types: [published]

permissions: {}

concurrency:
group: release-${{ github.event.release.tag_name }}
cancel-in-progress: false

jobs:
binaries:
name: binarios
runs-on: ubuntu-latest
permissions:
contents: write
env:
TAG: ${{ github.event.release.tag_name }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.release.tag_name }}
persist-credentials: false

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: go.mod
cache: false

- name: Comprobar la versión y release/checksums.txt
id: check
run: |
set -euo pipefail
version="$(sed -n 's/^var version = "\(.*\)"$/\1/p' cmd/commitling/main.go)"
if [ "$TAG" != "v$version" ]; then
echo "::error::La etiqueta $TAG no coincide con la versión de la CLI (v$version)."
exit 1
fi
if [ ! -f release/checksums.txt ]; then
echo "::warning::$TAG no tiene release/checksums.txt: no se suben binarios y la Action seguirá compilando con go run."
echo "upload=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "upload=true" >> "$GITHUB_OUTPUT"

- name: Compilar y verificar los binarios
if: steps.check.outputs.upload == 'true'
run: scripts/build-release.sh "$RUNNER_TEMP/dist" --check

- name: Subir los binarios a la release
if: steps.check.outputs.upload == 'true'
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
gh release upload "$TAG" "$RUNNER_TEMP"/dist/commitling_* "$RUNNER_TEMP/dist/checksums.txt" --clobber
{
echo "### Binarios de $TAG"
echo '```'
cat "$RUNNER_TEMP/dist/checksums.txt"
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
9 changes: 8 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Una mascota pixel-art **original** que vive en el README de tu perfil de GitHub.
- **Lo que entra en el wasm no puede importar `encoding/json`, `fmt`, `reflect`, `regexp`, `net/http`, `os` ni plantillas** (`TestWasmPackagesAvoidHeavyImports` lee los imports de `events`, `generate`, `render`, `stats`, `creature` y `cmd/wasm`; el CI falla si el wasm pasa de 3 MB). Texto: `strconv` y concatenación; errores: `errors.New`; eventos: `internal/events/scan.go` (lector a mano que sigue a `encoding/json`; `scan_test.go` lo compara con él, y ahí sí se puede importar `encoding/json`). `Event.Payload` es `[]byte`. CLI, galería y cliente HTTP (`internal/github`, `gallery`, `og`) pueden usar lo que quieran: no entran en el wasm.
- Medir antes de optimizar: `go tool nm` no lee wasm; el desglose por paquete sale de leer las secciones de código y de nombres de un wasm sin recortar (ver `docs/specs/v0.7.md`). Pesos (Go 1.27, `-trimpath -ldflags="-s -w"`): 4.624.571 B (1.261.906 gzip) en v0.6.0 y 2.569.892 B (735.538 gzip) en v0.7.0; el resto es el `runtime` de Go.
- Cualquier reescritura que toque `render` o `generate` se comprueba con las huellas (`testdata/golden/full-sha256.txt`: 96 tarjetas de v0.5.0 y `favicon.svg`) y comparando la galería entera y la CLI con las de `main` (`diff -r`).
- Generador y límite de la API: `generator.js` valida el login con la regla de `events.ValidLogin` (un test compara la regexp de JS con la función de Go), cachea los eventos 10 min en `sessionStorage` (`commitling:events:<login en minúsculas>`; todo con `try/catch`; no hay más almacenamiento, ni `localStorage` ni cookies) y, con un 403 o 429, enseña `generate.FetchError` (hora local de `X-RateLimit-Reset`) y el botón «Ver demo» (`#gen-demo-alt`).
- Generador y límite de la API: `generator.js` valida el login con la regla de `events.ValidLogin` (un test compara la regexp de JS con la función de Go), cachea los eventos 10 min en `sessionStorage` (`commitling:events:<login en minúsculas>`; todo con `try/catch`; sin cookies; el único `localStorage` es `commitling:theme` de `theme.js`) y, con un 403 o 429, enseña `generate.FetchError` (hora local de `X-RateLimit-Reset`) y el botón «Ver demo» (`#gen-demo-alt`).
- Tests de comportamiento del generador en Node: `node internal/gallery/testdata/generator.test.js <generator.js>` (DOM, `fetch`, `sessionStorage` y wasm simulados, sin dependencias); lo lanza `TestGeneratorBehaviourInNode`, que en el CI falla si no hay `node` y en otros sitios se salta.
- El lector de CSS de los tests (`css_test.go`) ignora comentarios y cadenas y entiende `@media` y `@supports`; sigue siendo un lector mínimo, no un analizador completo.

Expand All @@ -68,6 +68,13 @@ Una mascota pixel-art **original** que vive en el README de tu perfil de GitHub.
- Cabecera del README: `docs/img/banner.svg` se generó con los `<g class="bob">` de los SVG reales de la galería (fases contento y árbol radiante) a escala 0,6; si cambian los sprites, regénerala igual (receta en `.claude/skills/publicar-version/SKILL.md`).
- En la Raspberry Pi de Alberto (4 núcleos, compartida): `GOFLAGS=-p=2` y nunca dos builds a la vez.

## Fase 3 (25-26/10/2026)
- **Tercera especie `cactus`** (`internal/creature/cactus.go`). La receta de `CONTRIBUTING.md` está al día (también OG, `install.js`, CI y tests). Las especies existentes no pueden cambiar ni un byte: compara la galería con la de `main` (`diff -r`).
- **Selector de tema** (`internal/gallery/theme.js`, en `<head>` sin `defer` para no parpadear): `data-theme` en `<html>`, cambia el `media` de los `<source>` y de `theme-color` (original en `data-media`). `localStorage` `commitling:theme` con lista cerrada (`light`, `dark`); «Sistema» borra la clave. CSS: oscuro en `@media (prefers-color-scheme:dark){:root:not([data-theme=light])…}` y `:root[data-theme=dark]`. Test en Node: `node internal/gallery/testdata/theme.test.js internal/gallery/theme.js`.
- **Trusted Types**: la CSP lleva `require-trusted-types-for 'script'; trusted-types commitling`. La única política es la de `generator.js` (`scriptURL`), que solo acepta `wasm_exec.js`. Nada de `innerHTML`/`eval`/`script.src` con cadenas: si hace falta un sumidero nuevo, pasa por esa política y por `TestPageHasStrictCSP`.
- **Acciones por SHA** con `# vX.Y.Z` (`TestThirdPartyActionsArePinnedBySHA`); dependabot actualiza ambos. Los workflows que genera la web para las personas usuarias siguen con `actions/checkout@v7` (legibles; son suyos).
- **Binario precompilado** (inactivo): paso `bin` de `action.yml`, `scripts/build-release.sh`, `.github/workflows/release.yml`, job `binario` de `action-test.yml`. Solo se activa con `release/checksums.txt` en el árbol de la etiqueta (ver `docs/DESARROLLO.md`). Si ese archivo existe, todo cambio de código exige regenerarlo (`--write`) o el CI falla.

## Reglas de contenido
- El personaje es **diseño propio**. Prohibido imitar criaturas de videojuegos, anime o marcas.
- Las reglas de fase y ánimo están documentadas en el README y son deterministas (mismos datos, mismo SVG).
Expand Down
Loading
Loading