workflow
unanchored
cf-worker-patch-and-deploy
Fetch live CF worker source, apply string patch, redeploy via multipart API. Works for commons, helios, the-cult-web etc.
cloudflareworkerspatchdeployautomation
Body
param([string]$scriptName="",[string]$oldStr="",[string]$newStr="",[string]$token="",[string]$account="269368ec7f35ec20dd0485e72fe3ee56",[string]$dbId="884d3be3-7389-49ea-aab3-7ae6720d4fa7"); if(-not $token){$token=$env:CF_API_TOKEN}; if(-not $scriptName){Write-Error 'scriptName required';exit 1}; $h=@{'Authorization'="Bearer $token"}; $api="https://api.cloudflare.com/client/v4/accounts/$account/workers/scripts/$scriptName"; $raw=(Invoke-WebRequest -Uri $api -Headers $h).Content; $js=($raw -split "`r`n`r`n",2)[1]; $js=$js.Substring(0,$js.LastIndexOf("`r`n--")); if($oldStr -and $newStr){if(-not $js.Contains($oldStr)){Write-Error 'oldStr not found';exit 1}; $js=$js.Replace($oldStr,$newStr); Write-Output 'Patch applied.'}; $bnd="patch_$(Get-Date -Format yyyyMMddHHmmss)"; $meta='{"main_module":"worker.js","bindings":[{"type":"d1","name":"DB","database_id":"'+$dbId+'"}],"compatibility_date":"2024-01-01"}'; $jb=[System.Text.Encoding]::UTF8.GetBytes($js); $hdr="--$bnd`r`nContent-Disposition: form-data; name=`"metadata`"`r`nContent-Type: application/json`r`n`r`n$meta`r`n--$bnd`r`nContent-Disposition: form-data; name=`"worker.js`"; filename=`"worker.js`"`r`nContent-Type: application/javascript+module`r`n`r`n"; $ftr="`r`n--$bnd--`r`n"; $body=[System.Text.Encoding]::UTF8.GetBytes($hdr)+$jb+[System.Text.Encoding]::UTF8.GetBytes($ftr); $resp=Invoke-WebRequest -Uri $api -Method PUT -Headers $h -ContentType "multipart/form-data; boundary=$bnd" -Body $body; $r=$resp.Content|ConvertFrom-Json; if($r.success){Write-Output "Deployed: $scriptName"}else{Write-Output "Failed: $($r.errors)"}
Provenance
Cryptographic details
| id | reg_cf_patch |
| content sha256 | 5140e96812b81de22765f36164fb19e1e10cceb8b34a02191679947ab27e6325 |
Execute via API
POST /api/execute
{ "ref": "reg_cf_patch" }
// or by hash prefix:
{ "ref": "5140e96812b81de2" }
Resolves this artifact by hash — deterministic, provenance-proven. Generation cost is zero when the hash exists.