# N8n Commit

> Export n8n workflows from the running GKE pod in fenrir-marketing namespace and commit them to infrastructure/n8n/workflows/. Creates a PR automatically. Use when the user says '/n8n-commit', 'export n8n workflows', 'commit n8n workflows', or 'sync n8n'.

- Skill: `majiayu000/n8n-commit` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/n8n-commit`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/n8n-commit/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Marketing & Growth
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/n8n-commit

---


# n8n-commit — Export n8n Workflows to Git

Exports all n8n workflows from the live pod in the `fenrir-marketing` namespace,
copies them into `infrastructure/n8n/workflows/`, commits any changes, and opens a PR.

## Usage

```
/n8n-commit
```

## Instructions

### Step 1 — Find the n8n pod

```bash
N8N_POD=$(kubectl get pods -n fenrir-marketing -l app.kubernetes.io/name=n8n,app.kubernetes.io/component=main -o jsonpath='{.items[0].metadata.name}')
echo "Pod: $N8N_POD"
```

If no pod is found (empty output), stop and report:
> "No n8n pod found in fenrir-marketing namespace. Is n8n running?"

### Step 2 — Export workflows from the pod

```bash
kubectl exec -n fenrir-marketing "$N8N_POD" -- n8n export:workflow --all --output=/tmp/n8n-export.json
```

If the export command fails, stop and report the error.

### Step 3 — Copy exported file to local and split into individual workflow files

```bash
kubectl cp "fenrir-marketing/$N8N_POD:/tmp/n8n-export.json" /tmp/n8n-export.json
```

n8n exports all workflows as a JSON array. Split into individual files named by workflow id:

```bash
# Count workflows in the export
COUNT=$(jq 'length' /tmp/n8n-export.json)
echo "Exported $COUNT workflows"

# Split array into individual files, named by id field (kebab-case)
for i in $(seq 0 $((COUNT - 1))); do
  ID=$(jq -r ".[$i].id" /tmp/n8n-export.json)
  jq ".[$i]" /tmp/n8n-export.json > "infrastructure/n8n/workflows/${ID}.json"
  echo "  → infrastructure/n8n/workflows/${ID}.json"
done
```

This writes each workflow as a separate JSON file in `infrastructure/n8n/workflows/`.

### Step 4 — Check for changes

```bash
git diff --stat infrastructure/n8n/workflows/
git status --short infrastructure/n8n/workflows/
```

**If there are no changes** (both commands produce no output):
- Report: "No workflow changes detected — infrastructure/n8n/workflows/ is already up to date."
- Stop here. Do NOT create a branch or PR.

**If there are changes**, continue to Step 5.

### Step 5 — Create a branch, commit, and push

```bash
DATE=$(date +%Y-%m-%d)
BRANCH="chore/n8n-export-$DATE"

git checkout -b "$BRANCH"
git add infrastructure/n8n/workflows/
git commit -m "chore: export n8n workflows $DATE

# Summary of changes

## Summary

- Export all n8n workflows from fenrir-marketing pod to infrastructure/n8n/workflows/"
git push origin "$BRANCH"
```

### Step 6 — Create a PR

```bash
gh pr create \
  --title "chore: export n8n workflows" \
  --body "$(cat <<'EOF'
## Summary

- Automated export of all n8n workflows from the running pod in `fenrir-marketing` namespace
- Workflows written to `infrastructure/n8n/workflows/`
- No manual changes — generated by `/n8n-commit`

## How to verify

1. Review the diff in `infrastructure/n8n/workflows/`
2. Confirm workflow JSON files match expected workflow names in the n8n UI
EOF
)" \
  --base main
```

Report the PR URL to the user.

### Step 7 — Report

Print a summary:

```
## n8n Workflow Export Complete

- **Pod:** <N8N_POD>
- **Workflows exported to:** infrastructure/n8n/workflows/
- **Branch:** chore/n8n-export-<DATE>
- **PR:** <PR_URL>
```

## Notes

- Namespace: `fenrir-marketing` (not `fenrir-analytics`)
- Requires `kubectl` configured for the GKE cluster with access to `fenrir-marketing`
- Requires `gh` CLI authenticated for PR creation
- Requires the repo working directory to be on `main` (clean state) before running
- The `infrastructure/n8n/workflows/` directory is the canonical store for workflow backups

