---
phase: 13-cicd
plan: 01
type: execute
wave: 1
depends_on: []
files_modified: [.github/workflows/ci.yml]
autonomous: true

must_haves:
  truths:
    - "Push to main/master triggers test workflow automatically"
    - "Pull request to main/master triggers test workflow automatically"
    - "Tests run on MacOS, Linux, and Windows in CI matrix"
    - "Sapling is installed and functional on each CI platform"
    - "Tests pass on all platform/Python version combinations"
  artifacts:
    - path: ".github/workflows/ci.yml"
      provides: "CI test workflow with matrix strategy"
      contains: "matrix:"
  key_links:
    - from: ".github/workflows/ci.yml"
      to: "python test"
      via: "pytest run step"
      pattern: "python test"
    - from: ".github/workflows/ci.yml"
      to: "sl --version"
      via: "Sapling installation verification"
      pattern: "sl --version|sl.exe --version"
---

<objective>
Create GitHub Actions CI workflow that tests gitsl on all platforms

Purpose: Ensure every push and PR is automatically tested on MacOS, Linux, and Windows with Sapling installed, catching cross-platform issues before merge.

Output: `.github/workflows/ci.yml` with matrix strategy testing 3 platforms x 3 Python versions
</objective>

<execution_context>
@~/.claude/get-shit-done/workflows/execute-plan.md
@~/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/13-cicd/13-RESEARCH.md
@.planning/phases/12-packaging/12-01-SUMMARY.md
@test
@pyproject.toml
</context>

<tasks>

<task type="auto">
  <name>Task 1: Create CI workflow file with matrix strategy</name>
  <files>.github/workflows/ci.yml</files>
  <action>
Create `.github/workflows/ci.yml` with:

**Trigger configuration:**
```yaml
on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]
```

**Matrix strategy:**
- OS: ubuntu-latest, macos-latest, windows-latest
- Python: 3.9, 3.11, 3.13 (oldest active, middle, latest per research recommendation)
- fail-fast: false (to see all failures)

**Job structure:**
1. `actions/checkout@v4`
2. `actions/setup-python@v5` with matrix.python-version
3. Platform-specific Sapling installation (see Task 2 for details)
4. Run tests with `python test`

Use the exact Sapling version from research: `0.2.20250521-115337+25ed6ac4`

**Critical:** The Windows step MUST:
- Use PowerShell (`shell: pwsh`)
- Remove the `sl` alias: `Remove-Alias -Name sl -Force -Scope Global -ErrorAction SilentlyContinue`
- Add Sapling to PATH using `$env:GITHUB_PATH`
- Call `sl.exe --version` (explicit .exe)
  </action>
  <verify>File `.github/workflows/ci.yml` exists with valid YAML syntax: `python -c "import yaml; yaml.safe_load(open('.github/workflows/ci.yml'))"`</verify>
  <done>CI workflow file created with matrix covering 3 OS x 3 Python versions = 9 combinations</done>
</task>

<task type="auto">
  <name>Task 2: Add platform-specific Sapling installation steps</name>
  <files>.github/workflows/ci.yml</files>
  <action>
Add three conditional Sapling installation steps in the CI workflow:

**Ubuntu (runner.os == 'Linux'):**
```yaml
- name: Install Sapling (Ubuntu)
  if: runner.os == 'Linux'
  run: |
    SAPLING_VERSION="0.2.20250521-115337+25ed6ac4"
    curl -LO "https://github.com/facebook/sapling/releases/download/${SAPLING_VERSION}/sapling_${SAPLING_VERSION}_amd64.Ubuntu22.04.deb"
    sudo dpkg -i sapling_*.deb
    sl --version
```

**macOS (runner.os == 'macOS'):**
```yaml
- name: Install Sapling (macOS)
  if: runner.os == 'macOS'
  run: |
    brew install sapling
    sl --version
```

**Windows (runner.os == 'Windows'):**
```yaml
- name: Install Sapling (Windows)
  if: runner.os == 'Windows'
  shell: pwsh
  run: |
    $SAPLING_VERSION = "0.2.20250521-115337+25ed6ac4"
    $url = "https://github.com/facebook/sapling/releases/download/$SAPLING_VERSION/sapling_windows_${SAPLING_VERSION}_amd64.zip"
    Invoke-WebRequest -Uri $url -OutFile sapling.zip
    Expand-Archive sapling.zip -DestinationPath "$env:LOCALAPPDATA\Sapling"

    # Add to GITHUB_PATH for subsequent steps
    $saplingPath = "$env:LOCALAPPDATA\Sapling\sapling_windows_${SAPLING_VERSION}_amd64"
    echo $saplingPath >> $env:GITHUB_PATH

    # Remove PowerShell sl alias that conflicts with Sapling
    Remove-Alias -Name sl -Force -Scope Global -ErrorAction SilentlyContinue

    # Verify with explicit .exe
    & "$saplingPath\sl.exe" --version
```

**Important:** The Windows step must use `echo $path >> $env:GITHUB_PATH` instead of environment variable modification because PATH changes don't persist across steps in GitHub Actions.
  </action>
  <verify>Workflow YAML is valid and contains all three platform installation steps: `grep -c "Install Sapling" .github/workflows/ci.yml` returns 3</verify>
  <done>Platform-specific Sapling installation steps added for Ubuntu, macOS, and Windows</done>
</task>

<task type="auto">
  <name>Task 3: Add test execution step</name>
  <files>.github/workflows/ci.yml</files>
  <action>
Add the test execution step after Sapling installation:

```yaml
- name: Run tests
  run: python test
```

For Windows, add a step to remove the sl alias again before running tests (aliases may be restored in new shell sessions):

```yaml
- name: Remove sl alias (Windows)
  if: runner.os == 'Windows'
  shell: pwsh
  run: Remove-Alias -Name sl -Force -Scope Global -ErrorAction SilentlyContinue

- name: Run tests
  run: python test
```

The test script already handles venv creation and pytest installation, so no additional setup is needed.
  </action>
  <verify>Push to a test branch and verify workflow triggers (or validate YAML structure locally)</verify>
  <done>Test execution step added, workflow ready for push to trigger</done>
</task>

</tasks>

<verification>
1. `.github/workflows/ci.yml` exists and has valid YAML
2. Workflow triggers on push to main/master and pull_request to main/master
3. Matrix includes 3 OS (ubuntu-latest, macos-latest, windows-latest)
4. Matrix includes 3 Python versions (3.9, 3.11, 3.13)
5. Platform-specific Sapling installation for all 3 platforms
6. Windows handles PowerShell sl alias conflict
7. Test step runs `python test`
</verification>

<success_criteria>
- CI-01: GitHub Actions workflow runs tests on push/PR (verified by workflow file structure)
- CI-02: Test matrix covers MacOS, Linux, Windows (verified by matrix.os)
- CI-03: CI installs Sapling on each platform (verified by conditional install steps)
- Workflow can be pushed to trigger actual CI run
</success_criteria>

<output>
After completion, create `.planning/phases/13-cicd/13-01-SUMMARY.md`
</output>
