111 lines
3.9 KiB
Bash
Executable File
111 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# publicar-dist.sh — publica en el repositorio de distribución
|
|
# (pi-new-project-dist) solo los ficheros que necesita pi para usar el paquete.
|
|
#
|
|
# Toma el contenido del commit actual (HEAD), no del directorio de trabajo.
|
|
# Cada publicación añade un commit y una etiqueta vX.Y.Z (versión de
|
|
# package.json) en el repositorio de distribución.
|
|
set -euo pipefail
|
|
|
|
REMOTO_DEF="https://git.sargatxet.cloud/sargatxet/pi-new-project-dist.git"
|
|
DESARROLLO="https://git.sargatxet.cloud/sargatxet/pi-new-project"
|
|
INSTALAR="git:git.sargatxet.cloud/sargatxet/pi-new-project-dist"
|
|
# Lo único que se publica (README.md se genera aparte).
|
|
RUTAS=(package.json LICENSE extensions skills)
|
|
|
|
uso() {
|
|
cat <<EOF
|
|
Uso: $(basename "$0") [opciones]
|
|
|
|
Publica en el repositorio de distribución los ficheros necesarios para usar
|
|
el paquete: ${RUTAS[*]} y un README.md mínimo.
|
|
|
|
-n, --dry-run Prepara la publicación sin subir nada y muestra el contenido.
|
|
-r, --remoto URL Repositorio de distribución (por defecto: $REMOTO_DEF).
|
|
-h, --help Muestra esta ayuda.
|
|
EOF
|
|
}
|
|
|
|
die() { printf 'error: %s\n' "$*" >&2; exit 1; }
|
|
info() { printf '%s\n' "$*"; }
|
|
|
|
DRY_RUN=0
|
|
REMOTO="$REMOTO_DEF"
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-n|--dry-run) DRY_RUN=1 ;;
|
|
-r|--remoto) [[ $# -ge 2 ]] || die "falta el valor de $1"; REMOTO="$2"; shift ;;
|
|
-h|--help) uso; exit 0 ;;
|
|
*) die "opción desconocida: $1 (usa --help)" ;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
RAIZ="$(git -C "$(dirname "$0")" rev-parse --show-toplevel)" || die "no estoy dentro del repositorio"
|
|
cd "$RAIZ"
|
|
|
|
# 1. Comprobaciones
|
|
[[ -z "$(git status --porcelain -- "${RUTAS[@]}")" ]] \
|
|
|| die "hay cambios sin commitear en: ${RUTAS[*]}"
|
|
VERSION="$(sed -n 's/^[[:space:]]*"version":[[:space:]]*"\([^"]*\)".*/\1/p' package.json | head -n1)"
|
|
[[ -n "$VERSION" ]] || die "no encuentro la versión en package.json"
|
|
ETIQUETA="v$VERSION"
|
|
ORIGEN="$(git rev-parse --short HEAD)"
|
|
if [[ -n "$(git ls-remote --tags "$REMOTO" "refs/tags/$ETIQUETA")" ]]; then
|
|
die "$ETIQUETA ya está publicada en $REMOTO; sube la versión en package.json"
|
|
fi
|
|
if git rev-parse -q --verify '@{u}' >/dev/null && [[ -n "$(git log --oneline '@{u}..HEAD')" ]]; then
|
|
info "aviso: HEAD ($ORIGEN) tiene commits sin subir al repositorio de desarrollo"
|
|
fi
|
|
|
|
# 2. Preparar el contenido sobre el último estado del repositorio de distribución
|
|
TMP="$(mktemp -d)"
|
|
if [[ $DRY_RUN -eq 0 ]]; then trap 'rm -rf "$TMP"' EXIT; fi
|
|
DIST="$TMP/dist"
|
|
git clone -q "$REMOTO" "$DIST" 2>/dev/null || die "no puedo clonar $REMOTO"
|
|
if ! git -C "$DIST" rev-parse -q --verify HEAD >/dev/null; then
|
|
git -C "$DIST" symbolic-ref HEAD refs/heads/main # repositorio vacío
|
|
fi
|
|
find "$DIST" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
|
|
git archive HEAD "${RUTAS[@]}" | tar -x -C "$DIST"
|
|
|
|
cat >"$DIST/README.md" <<EOF
|
|
# pi-new-project (distribución)
|
|
|
|
Versión instalable de **pi-new-project** $ETIQUETA: solo los ficheros que pi
|
|
necesita para usar el paquete (skill \`new-project\` y orden \`/modelo-proyecto\`).
|
|
|
|
\`\`\`bash
|
|
pi install $INSTALAR
|
|
# versión fija:
|
|
pi install $INSTALAR@$ETIQUETA
|
|
\`\`\`
|
|
|
|
Documentación, cambios e incidencias: <$DESARROLLO>
|
|
|
|
> Repositorio generado automáticamente desde $DESARROLLO
|
|
> (commit \`$ORIGEN\`). No hagas cambios aquí: se perderán en la próxima publicación.
|
|
|
|
Licencia MIT, ver [\`LICENSE\`](LICENSE).
|
|
EOF
|
|
|
|
git -C "$DIST" add -A
|
|
if git -C "$DIST" diff --cached --quiet; then
|
|
info "sin cambios respecto a la última publicación; no hay nada que publicar"
|
|
exit 0
|
|
fi
|
|
git -C "$DIST" commit -q -m "release $ETIQUETA (origen $ORIGEN)"
|
|
git -C "$DIST" tag -a "$ETIQUETA" -m "pi-new-project $ETIQUETA (origen $ORIGEN)"
|
|
|
|
info "contenido de $ETIQUETA:"
|
|
git -C "$DIST" ls-tree -r --name-only HEAD | sed 's/^/ /'
|
|
|
|
# 3. Publicar
|
|
if [[ $DRY_RUN -eq 1 ]]; then
|
|
info "dry-run: no se ha subido nada; revisa $DIST"
|
|
exit 0
|
|
fi
|
|
git -C "$DIST" push -q origin HEAD:refs/heads/main "refs/tags/$ETIQUETA"
|
|
info "publicado $ETIQUETA en $REMOTO"
|
|
info "instalar: pi install $INSTALAR"
|