---
name: ami-prepare-release
description: Prepares GitHub releases by calculating the next semantic version tag and generating bilingual release notes (English and Spanish) from git commit history in a single unified workflow.
allowed-tools: Bash, Read, Write
---

# Skill: Release Preparer

Act as a Version Control Manager and Technical Release Author. Your job is to analyze unreleased commits, compute the next SemVer version tag, and generate bilingual user-facing Release Notes in a single unified workflow.

## Operational Modes

- **Mode A: Full Preparation (Default):** Calculates the next version tag and drafts the bilingual release notes.
- **Mode B: Tag Only:** Computes only the semantic version tag.
- **Mode C: Notes Only:** Formulates only the bilingual release notes draft.

## Workflow

### 1. Fetch Remote State & Identify Baseline Tag
- **Mandatory Remote Tags Synchronization:**
  - Run `git fetch --tags` to ensure all remote tags (including tags created via GitHub Releases or external pipelines) are fetched locally. Standard `git fetch` does NOT guarantee downloading remote tags.
- **Remote Releases Cross-Check:**
  - If GitHub CLI (`gh`) is available, run `gh release list --limit 5` to inspect the most recent published releases and their associated tags directly from the remote repository.
  - Cross-check candidate tags from GitHub releases against local tags. If a release tag (e.g., `v1.8.0`) is listed remotely, ensure it is considered when resolving the baseline version to prevent suggesting an already existing version tag.
- **Baseline Tag Resolution:**
  - Locate the latest tag reachable from `HEAD` using `git describe --tags --abbrev=0`.
  - Also inspect all local tags sorted by version using `git tag -l --sort=-version:refname`.
  - Determine the true baseline tag by selecting the highest SemVer tag found across `git describe`, `git tag -l`, and `gh release list --limit 5`. If no tags exist, use `v0.0.0` as the baseline.
- **Scan Versioning Policies:** Scan repository documentation for versioning policies (e.g., `VERSIONING.md`, `CONTRIBUTING.md`, or `README.md`). If a non-standard tagging convention (such as package prefixes or date-based QA tags) is specified, adhere to it.
- **Current Tag Verification:** Compare the commit hash of the baseline tag (`git rev-list -n 1 <last-tag>`) with `HEAD` (`git rev-parse HEAD`). If identical, the current commit is already tagged; recommend reusing the existing tag.

### 2. Extract & Inspect Unreleased Commits
- Run `git log <last-tag>..HEAD --oneline` (or `--pretty=format:"%s"` for raw titles).
- **No Changes Check:** If the commit list is empty, report that no new unreleased commits exist and stop.
- **Product Scope & Release Necessity Check (Release Gate):**
  - Run `git diff <last-tag>..HEAD --name-only` to inspect modified files alongside commit titles.
  - If all unreleased commits consist exclusively of non-product changes—such as pure documentation updates (`docs:`, markdown files, ADRs), internal automated tests or benchmarks (`test:`), CI/CD maintenance (`ci:`), or internal developer chores (`chore:`) that do not alter the distributed product/library source code:
    - **Halt and reject release preparation.** Inform the user that no release is warranted because no core product functionality was modified. Do not compute a new SemVer tag or generate release notes.

### 3. Calculate Semantic Version Tag (SemVer)
Analyze commit messages against Conventional Commits:
- **Major Bump (x.0.0):** If any commit contains `!` (e.g., `feat!:`) or `BREAKING CHANGE:` modifying public API contracts.
- **Minor Bump (0.x.0):** If commits introduce new user-facing features or product capabilities (`feat:`).
- **Patch Bump (0.0.x):** If commits consist of bug fixes (`fix:`), runtime performance improvements (`perf:`), or internal refactoring (`refactor:`) touching the actual distributed product codebase.
- **No Release (Rejection):** Commits limited strictly to documentation updates (`docs:`), internal tests (`test:`), CI/CD workflows (`ci:`), or internal developer chores (`chore:`) that do not alter the shipped product do NOT qualify for a patch bump and MUST NOT trigger a release.

**Tag Modifiers (if requested):**
- **QA / RC:** Append `-qa.YYYYMMDD.n` or `-rc.YYYYMMDD.n` based on the current date and daily increment.
- **Stable:** Standard base version (e.g., `v1.3.0`).

- **Build Order Advisory:** For binary distribution pipelines, source version declarations and package manifests must be updated and committed before initiating compilation or packaging installers.

### 4. Categorize & Draft Bilingual Release Notes
- **Focus on Product Value:** Filter out internal developer chores (`chore:`, `bump version...`, `[skip ci]`), internal rule citations, and minor landing page edits. Translate technical changes into clear user-facing capability improvements.
- **Group Commits:**
  - `feat:` -> Features / Nuevas Funcionalidades
  - `fix:` -> Bug Fixes / Correcciones de Errores
  - `refactor:`, `test:`, `perf:` -> Maintenance / Mantenimiento
  - `!` / `BREAKING CHANGE` -> BREAKING CHANGES / CAMBIOS IMPORTANTES
- **Formatting Constraints:**
  - Strict prohibition against emojis in titles, language separators, or section headers.
  - Strictly adhere to the Zero Flags Invariant: NEVER use country flags anywhere in release notes. Use clean semantic text links (`[English](#english) | [Español](#español)`).

**English Template:**
```markdown
# Release [Version]

## BREAKING CHANGES

## Features

## Bug Fixes

## Maintenance
```

**Spanish Template:**
```markdown
---
# Lanzamiento [Versión]

## CAMBIOS IMPORTANTES

## Nuevas Funcionalidades

## Correcciones de Errores

## Mantenimiento
```

### 5. Output
Present the prepared release bundle clearly:
1. **Target Version Tag:** e.g., `v5.2.0`
2. **Bilingual Release Notes Draft:** English followed by Spanish.
3. CONFIRMATION 1 - Publish release: STOP and present the target tag, the notes draft, and any manifest version changes to the user. Await explicit approval before creating the tag, publishing the release, or editing package manifests.

> [!IMPORTANT]
> **Build Order & Pre-Build Version Bump Advisory:**
> In projects producing executable binaries or distribution packages (`.exe`, `.msi`, `.apk`, installers), version bumps in source configuration files (`*.csproj`, `app.manifest`, `constants.py`, `package.json`, `Cargo.toml`, etc.) MUST be completed and committed BEFORE initiating binary builds or packaging installers.
> For installers (e.g. Inno Setup, WiX, NSIS), the build output path must match the installer script's source paths, otherwise a stale binary is packaged silently; check the built binary reports the new version before packaging.

### 6. Post-Publish Verification
- **Tag scope:** `git log --oneline origin/main..<TAG>` must be empty (or contain only the intended commits); unmerged stacked-PR work must not leak into the tag.
- **Assets:** A release that ships binaries is not done until its assets are attached: `gh release view <TAG> --json assets` must list the expected files. Missing or stale assets -> propose `gh release upload <TAG> <files> --clobber`.
- **Deployment truth:** A green pipeline is not a deployment. If the release deploys, confirm the running version from the serving system (e.g. the deployed container image, or a version/build endpoint).
- **Cleanup:** Remove gitignored build/dist output with the toolchain's native clean (e.g. `cargo clean`, `dotnet clean`) or explicit paths, never broad globs like `*build*` or `*bin*` that can match source folders.

---
**Language Rule:** Although your code and commits MUST be in English, you MUST communicate and interact in the chat using the same language the user is speaking (e.g., Spanish, French, etc.).
