|
| 1 | +name: SF CLI Integration Test |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + |
| 6 | +jobs: |
| 7 | + sf-cli-integration: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + SF_AUTOUPDATE_DISABLE: true |
| 11 | + NO_COLOR: '1' |
| 12 | + |
| 13 | + steps: |
| 14 | + # ── Setup ───────────────────────────────────────────────────────────────── |
| 15 | + |
| 16 | + - name: Checkout code |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Set up Python 3.11 |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: '3.11' |
| 23 | + |
| 24 | + - name: Install Poetry and Python SDK |
| 25 | + run: | |
| 26 | + python -m pip install --upgrade pip |
| 27 | + pip install poetry |
| 28 | + make develop |
| 29 | +
|
| 30 | + - name: Add Poetry venv to PATH |
| 31 | + run: echo "$(poetry env info --path)/bin" >> $GITHUB_PATH |
| 32 | + |
| 33 | + - name: Set up Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: lts/* |
| 37 | + |
| 38 | + - name: Install Salesforce CLI |
| 39 | + run: npm install -g @salesforce/cli |
| 40 | + |
| 41 | + - name: Install data-code-extension plugin |
| 42 | + run: sf plugins install @salesforce/plugin-data-code-extension --force |
| 43 | + |
| 44 | + - name: Set up Java 17 (required for PySpark during run) |
| 45 | + uses: actions/setup-java@v4 |
| 46 | + with: |
| 47 | + distribution: temurin |
| 48 | + java-version: '17' |
| 49 | + |
| 50 | + # ── Mock Salesforce server + fake org auth ──────────────────────────────── |
| 51 | + |
| 52 | + - name: Start mock Salesforce server |
| 53 | + run: python scripts/mock_sf_server.py & |
| 54 | + env: |
| 55 | + MOCK_SF_PORT: '8888' |
| 56 | + |
| 57 | + - name: Create fake SF CLI auth for org alias 'dev1' |
| 58 | + run: | |
| 59 | + sleep 1 |
| 60 | + python - <<'PYEOF' |
| 61 | + import json, pathlib |
| 62 | + home = pathlib.Path.home() |
| 63 | +
|
| 64 | + # Auth file — @salesforce/core reads ~/.sfdx/<username>.json on Linux |
| 65 | + # (plain-text storage, no OS keychain involved on CI runners) |
| 66 | + sfdx_dir = home / ".sfdx" |
| 67 | + sfdx_dir.mkdir(exist_ok=True) |
| 68 | + auth = { |
| 69 | + "accessToken": "00D000000000001AAA!fakeTokenForCITesting", |
| 70 | + "instanceUrl": "http://localhost:8888", |
| 71 | + "loginUrl": "https://login.salesforce.com", |
| 72 | + "orgId": "00D000000000001AAA", |
| 73 | + "userId": "005000000000001AAA", |
| 74 | + "username": "dev1@example.com", |
| 75 | + "clientId": "PlatformCLI", |
| 76 | + "isDevHub": False, |
| 77 | + "isSandbox": False, |
| 78 | + "created": "2024-01-01T00:00:00.000Z", |
| 79 | + "createdOrgInstance": "CS1", |
| 80 | + } |
| 81 | + (sfdx_dir / "dev1@example.com.json").write_text(json.dumps(auth, indent=2)) |
| 82 | +
|
| 83 | + # Alias mapping — write to both locations for compat across sf versions |
| 84 | + alias_data = {"orgs": {"dev1": "dev1@example.com"}} |
| 85 | + sf_dir = home / ".sf" |
| 86 | + sf_dir.mkdir(exist_ok=True) |
| 87 | + (sf_dir / "alias.json").write_text(json.dumps(alias_data)) |
| 88 | + (sfdx_dir / "alias.json").write_text(json.dumps(alias_data)) |
| 89 | +
|
| 90 | + print("Fake SF CLI org auth written to ~/.sfdx/dev1@example.com.json") |
| 91 | + PYEOF |
| 92 | +
|
| 93 | + # ── Script: init ────────────────────────────────────────────────────────── |
| 94 | + |
| 95 | + - name: '[script] init — sf data-code-extension script init --package-dir testScript' |
| 96 | + run: | |
| 97 | + sf data-code-extension script init --package-dir testScript || { |
| 98 | + echo "::error::sf data-code-extension script init FAILED. Verify --package-dir is still a recognised flag and that the command exits 0 on success." |
| 99 | + exit 1 |
| 100 | + } |
| 101 | +
|
| 102 | + - name: '[script] verify init — expected files exist' |
| 103 | + run: | |
| 104 | + test -f testScript/payload/entrypoint.py || { |
| 105 | + echo "::error::testScript/payload/entrypoint.py not found after init. The init command may not have copied the script template." |
| 106 | + exit 1 |
| 107 | + } |
| 108 | + test -f testScript/.datacustomcode_proj/sdk_config.json || { |
| 109 | + echo "::error::testScript/.datacustomcode_proj/sdk_config.json not found after init. The SDK config marker was not written." |
| 110 | + exit 1 |
| 111 | + } |
| 112 | +
|
| 113 | + # ── Script: scan ────────────────────────────────────────────────────────── |
| 114 | + |
| 115 | + - name: '[script] scan — sf data-code-extension script scan --entrypoint testScript/payload/entrypoint.py' |
| 116 | + run: | |
| 117 | + sf data-code-extension script scan --entrypoint testScript/payload/entrypoint.py || { |
| 118 | + echo "::error::sf data-code-extension script scan FAILED. Verify --entrypoint is still a recognised flag and the command exits 0." |
| 119 | + exit 1 |
| 120 | + } |
| 121 | +
|
| 122 | + - name: '[script] verify scan — config.json contains permissions' |
| 123 | + run: | |
| 124 | + python - <<'EOF' |
| 125 | + import json, sys |
| 126 | + path = "testScript/payload/config.json" |
| 127 | + try: |
| 128 | + with open(path) as f: |
| 129 | + data = json.load(f) |
| 130 | + except Exception as e: |
| 131 | + print(f"::error::Could not read {path}: {e}") |
| 132 | + sys.exit(1) |
| 133 | + if "permissions" not in data: |
| 134 | + print(f"::error::{path} is missing 'permissions' key after scan. Got: {json.dumps(data)}") |
| 135 | + sys.exit(1) |
| 136 | + print("config.json OK:", json.dumps(data, indent=2)) |
| 137 | + EOF |
| 138 | +
|
| 139 | + # ── Script: zip ─────────────────────────────────────────────────────────── |
| 140 | + |
| 141 | + - name: '[script] prepare for zip — clear requirements.txt to skip native-dep Docker build' |
| 142 | + run: echo "" > testScript/payload/requirements.txt |
| 143 | + |
| 144 | + - name: '[script] zip — sf data-code-extension script zip --package-dir testScript' |
| 145 | + run: | |
| 146 | + sf data-code-extension script zip --package-dir testScript || { |
| 147 | + echo "::error::sf data-code-extension script zip FAILED. Verify --package-dir is still recognised and the command exits 0." |
| 148 | + exit 1 |
| 149 | + } |
| 150 | +
|
| 151 | + - name: '[script] verify zip — deployment.zip exists' |
| 152 | + run: | |
| 153 | + test -f deployment.zip || { |
| 154 | + echo "::error::deployment.zip not found after sf data-code-extension script zip. The zip command may have written to a different path or failed silently." |
| 155 | + exit 1 |
| 156 | + } |
| 157 | +
|
| 158 | + # ── Script: run ─────────────────────────────────────────────────────────── |
| 159 | + |
| 160 | + - name: '[script] run — sf data-code-extension script run --entrypoint testScript/payload/entrypoint.py -o dev1' |
| 161 | + run: | |
| 162 | + sf data-code-extension script run \ |
| 163 | + --entrypoint testScript/payload/entrypoint.py \ |
| 164 | + -o dev1 || { |
| 165 | + echo "::error::sf data-code-extension script run FAILED. Check mock server output above for which endpoint failed. The --entrypoint flag or SF CLI org auth contract may have changed." |
| 166 | + exit 1 |
| 167 | + } |
| 168 | +
|
| 169 | + # ── Script: deploy ─────────────────────────────────────────────────────── |
| 170 | + |
| 171 | + - name: '[script] deploy — sf data-code-extension script deploy' |
| 172 | + run: | |
| 173 | + sf data-code-extension script deploy \ |
| 174 | + --name test-script-deploy \ |
| 175 | + --package-version 0.0.1 \ |
| 176 | + --description "Test script deploy" \ |
| 177 | + --package-dir testScript/payload \ |
| 178 | + --cpu-size CPU_2XL \ |
| 179 | + -o dev1 || { |
| 180 | + echo "::error::sf data-code-extension script deploy FAILED. Check mock server output above for which endpoint failed. The deploy command flags or API contract may have changed." |
| 181 | + exit 1 |
| 182 | + } |
| 183 | +
|
| 184 | + # ── Function: init ──────────────────────────────────────────────────────── |
| 185 | + |
| 186 | + - name: '[function] init — sf data-code-extension function init --package-dir testFunction' |
| 187 | + run: | |
| 188 | + sf data-code-extension function init --package-dir testFunction || { |
| 189 | + echo "::error::sf data-code-extension function init FAILED. Verify --package-dir is still recognised and the function template copies correctly." |
| 190 | + exit 1 |
| 191 | + } |
| 192 | +
|
| 193 | + - name: '[function] verify init — expected files exist' |
| 194 | + run: | |
| 195 | + test -f testFunction/payload/entrypoint.py || { |
| 196 | + echo "::error::testFunction/payload/entrypoint.py not found after function init." |
| 197 | + exit 1 |
| 198 | + } |
| 199 | + test -f testFunction/.datacustomcode_proj/sdk_config.json || { |
| 200 | + echo "::error::testFunction/.datacustomcode_proj/sdk_config.json not found after function init." |
| 201 | + exit 1 |
| 202 | + } |
| 203 | +
|
| 204 | + # ── Function: scan ──────────────────────────────────────────────────────── |
| 205 | + |
| 206 | + - name: '[function] scan — sf data-code-extension function scan --entrypoint testFunction/payload/entrypoint.py' |
| 207 | + run: | |
| 208 | + sf data-code-extension function scan --entrypoint testFunction/payload/entrypoint.py || { |
| 209 | + echo "::error::sf data-code-extension function scan FAILED." |
| 210 | + exit 1 |
| 211 | + } |
| 212 | +
|
| 213 | + - name: '[function] verify scan — config.json contains entryPoint' |
| 214 | + run: | |
| 215 | + python - <<'EOF' |
| 216 | + import json, sys |
| 217 | + path = "testFunction/payload/config.json" |
| 218 | + try: |
| 219 | + with open(path) as f: |
| 220 | + data = json.load(f) |
| 221 | + except Exception as e: |
| 222 | + print(f"::error::Could not read {path}: {e}") |
| 223 | + sys.exit(1) |
| 224 | + if "entryPoint" not in data: |
| 225 | + print(f"::error::{path} is missing 'entryPoint' key after scan. Got: {json.dumps(data)}") |
| 226 | + sys.exit(1) |
| 227 | + print("config.json OK:", json.dumps(data, indent=2)) |
| 228 | + EOF |
| 229 | +
|
| 230 | + # ── Function: zip ───────────────────────────────────────────────────────── |
| 231 | + |
| 232 | + - name: '[function] prepare for zip — clear requirements.txt to skip native-dep Docker build' |
| 233 | + run: echo "" > testFunction/payload/requirements.txt |
| 234 | + |
| 235 | + - name: '[function] clean up previous deployment.zip before function zip' |
| 236 | + run: rm -f deployment.zip |
| 237 | + |
| 238 | + - name: '[function] zip — sf data-code-extension function zip --package-dir testFunction' |
| 239 | + run: | |
| 240 | + sf data-code-extension function zip --package-dir testFunction || { |
| 241 | + echo "::error::sf data-code-extension function zip FAILED." |
| 242 | + exit 1 |
| 243 | + } |
| 244 | +
|
| 245 | + - name: '[function] verify zip — deployment.zip exists' |
| 246 | + run: | |
| 247 | + test -f deployment.zip || { |
| 248 | + echo "::error::deployment.zip not found after sf data-code-extension function zip." |
| 249 | + exit 1 |
| 250 | + } |
| 251 | +
|
| 252 | + # ── Function: run ───────────────────────────────────────────────────────── |
| 253 | + |
| 254 | + - name: '[function] run — sf data-code-extension function run --entrypoint testFunction/payload/entrypoint.py -o dev1' |
| 255 | + run: | |
| 256 | + sf data-code-extension function run \ |
| 257 | + --entrypoint testFunction/payload/entrypoint.py \ |
| 258 | + -o dev1 || { |
| 259 | + echo "::error::sf data-code-extension function run FAILED. Check mock server output above; the --entrypoint flag or SF CLI org auth contract may have changed." |
| 260 | + exit 1 |
| 261 | + } |
| 262 | +
|
| 263 | + # ── Function: deploy ───────────────────────────────────────────────────── |
| 264 | + |
| 265 | + - name: '[function] deploy — sf data-code-extension function deploy' |
| 266 | + run: | |
| 267 | + sf data-code-extension function deploy \ |
| 268 | + --name test-function-deploy \ |
| 269 | + --package-version 0.0.1 \ |
| 270 | + --description "Test function deploy" \ |
| 271 | + --package-dir testFunction/payload \ |
| 272 | + --cpu-size CPU_2XL \ |
| 273 | + --function-invoke-opt UnstructuredChunking \ |
| 274 | + -o dev1 || { |
| 275 | + echo "::error::sf data-code-extension function deploy FAILED. Check mock server output above for which endpoint failed. The deploy command flags or API contract may have changed." |
| 276 | + exit 1 |
| 277 | + } |
0 commit comments