# Generate with AI

> Convert GitHub Actions workflows into a Mélodium pipeline with an AI assistant, the Mélodium skill and MCP server.

Web page: https://docs.cadence.ci/en/github/ai-skills

If you already have a GitHub Actions workflow, an AI coding assistant can produce the equivalent Mélodium pipeline in minutes, without you having to learn the language first.

## What You Need

- Your existing `.github/workflows/` directory, the agent will read it directly.
- An AI coding assistant running locally in your project (Claude Code, Cursor, Zed, or similar).
- The Mélodium skill installed in your AI tool, the [Mélodium MCP server](https://docs.cadence.ci/en/with-ai/install-mcp.md) connected to it, or both. See [Install the Mélodium Skill](https://docs.cadence.ci/en/with-ai/install-skill.md). The MCP server provides the same migration guide through `get_cicd_migration_guide`, and lets the AI check the program it writes.

## Step 1: Make Sure the Migration Reference Is Included

The general Mélodium skill covers the language and project layout. For a GitHub Actions migration, the AI also needs `skills/melodium/references/github-migration.md`, which has the exact treatment patterns for `runAction`, `prepareContexts`, `githubJobResult`, matrix jobs, and status reporting.

With **Claude Code**, this comes included automatically once the skill is installed under `~/.claude/skills/melodium`, it loads its reference files on demand. With **Cursor** or **Zed**, make sure your rule file includes it:

```sh
# Cursor
cat skills/melodium/SKILL.md \
    skills/melodium/references/github-migration.md \
    skills/melodium/references/projects.md \
    > .cursor/rules/melodium.md

# Zed
cat skills/melodium/SKILL.md \
    skills/melodium/references/github-migration.md \
    skills/melodium/references/projects.md \
    > .rules
```

## Step 2: Ask for the Migration

Your AI agent is already running inside your project and can read your workflow files directly, so a simple prompt is enough:

```text
Read the workflows in .github/workflows/ and migrate them to Mélodium.
Generate a complete project under .melodium-ci/ with Compo.toml and .mel files.
Use simpleStep for container jobs, localStep for self-hosted jobs.
Report status back to GitHub using the token and project parameters.
```

If your workflows reference composite actions stored in `.github/actions/`, mention them so the agent reads those too:

```text
Also read the composite actions in .github/actions/ and inline them as treatments.
```

The AI will produce a ready-to-use Mélodium project: a `Compo.toml` declaring the right dependencies, one `.mel` file per workflow with one treatment per job, parallel wiring for matrix jobs, artifact streaming between jobs that depend on each other, and GitHub commit status reporting.

## Step 3: Review and Adjust

Read through the generated code before running it. The `cpu`, `memory`, and `storage` parameters in `simpleStep` have generic defaults, adjust them to your actual build requirements. Check that `github_project` and `github_sha` are wired to the right entrypoint parameters, and that the token is read from the right secret: `github_token` defaults to `"env:MELODIUM_SECRET_GITHUB_TOKEN"`, which the [reusable workflows](https://docs.cadence.ci/en/github/run-on-github.md) provide. Third-party actions (`uses:`) from the marketplace can't be translated automatically, the AI inlines their logic as shell commands where it can, but complex actions may need your attention. And for conditional jobs (`if:`), verify the `filterBlock` wiring actually matches the intent of the original condition.

## Concept Reference

If you want to understand what the AI produced, or adjust it yourself, this table shows how GitHub Actions concepts map to Mélodium:

| GitHub Actions | Mélodium |
|---|---|
| Workflow file | `.mel` treatment |
| Job | Treatment with `simpleStep` or `localStep` |
| `run:` step | `runAction[contexts=contexts]()` |
| `${{ }}` expression | Evaluated via `JavaScriptEngine` |
| `jobs.<job>.needs` | Sequential wiring + `includeNeeds` |
| `strategy.matrix` | Parallel treatment instances with `one<void>()` |
| `jobs.<job>.if` | `filterBlock<void>()` on the job trigger |
| `actions/cache` | `cache` parameter of `simpleStep`, or `work/cache` in programs (see [Caches](https://docs.cadence.ci/en/pipelines/caches.md)) |
| `actions/upload-artifact` / `download-artifact` | `artifacts` parameter of `simpleStep`, or `work/artifact` in programs (see [Run Artifacts](https://docs.cadence.ci/en/pipelines/artifacts.md)) |
| Status reporting | `postGithubState` / `postGithubStateContext` |

Full API documentation is at [doc.melodium.tech](https://doc.melodium.tech/latest/en/).

## Going Further

The generated code is a good starting point, and can be extended with any Mélodium element. For distribution across multiple machines and more advanced parallelisation, see [Simple CI/CD Implementation](https://docs.cadence.ci/en/from-template/cicd.md) and [Advanced CI/CD Implementation](https://docs.cadence.ci/en/from-template/advanced-implementation.md).
