|
| 1 | +# Deploy Primitive Function |
| 2 | + |
| 3 | +GitHub Action that deploys a [Primitive Function](https://primitive.dev) to primitive.dev. Idempotent — creates the function on first run, updates it on subsequent runs. Manages custom `function_secrets` in lockstep with the deploy and triggers a re-bind when bindings change. |
| 4 | + |
| 5 | +## Quick start |
| 6 | + |
| 7 | +```yaml |
| 8 | +- uses: actions/checkout@v4 |
| 9 | +- run: pnpm install --frozen-lockfile && pnpm build |
| 10 | +- uses: primitivedotdev/deploy-function@v1 |
| 11 | + with: |
| 12 | + api-key: ${{ secrets.PRIMITIVE_API_KEY }} |
| 13 | + name: my-function |
| 14 | + code-path: dist/handler.js |
| 15 | + source-map-path: dist/handler.js.map |
| 16 | +``` |
| 17 | +
|
| 18 | +## Inputs |
| 19 | +
|
| 20 | +| Input | Required | Default | Description | |
| 21 | +|---|---|---|---| |
| 22 | +| `api-key` | yes | — | Org-scoped Primitive API key. Pass via `${{ secrets.* }}` — masked in logs. | |
| 23 | +| `api-base-url` | no | `https://api.primitive.dev/v1` | API base URL. Override only if deploying against a non-production environment. | |
| 24 | +| `name` | yes | — | Function name. `/^[a-z0-9_-]{1,64}$/`. Idempotent within the org. | |
| 25 | +| `code-path` | one of | — | Path to a pre-built ESM bundle (e.g. `dist/handler.js`). Mutually exclusive with `files-path`. | |
| 26 | +| `source-map-path` | no | — | Source map for the `code-path` bundle. Surfaces readable stack traces in the dashboard. | |
| 27 | +| `files-path` | one of | — | Path to a source directory for **managed build**. The Action walks the tree, applies ignore patterns, and the platform builds server-side. Directory must contain a `package.json` at its root. Requires the `functions_managed_build` entitlement on the org. Mutually exclusive with `code-path`. | |
| 28 | +| `ignore` | no | — | Newline-delimited basename patterns to skip when walking `files-path`. Layered on top of the [default ignore list](#default-ignore-list). | |
| 29 | +| `secrets` | no | `{}` | JSON object of custom function secrets to upsert. Values are masked. | |
| 30 | +| `redeploy-on-secret-change` | no | `true` | Re-bind the runtime after upserting secrets. | |
| 31 | +| `expected-org-id` | no | — | Safety guard: aborts if the API key's org differs from this UUID. Strongly recommended in production workflows. | |
| 32 | + |
| 33 | +Exactly one of `code-path` and `files-path` must be set. |
| 34 | + |
| 35 | +### Default ignore list |
| 36 | + |
| 37 | +`node_modules`, `.git`, `.github`, `dist`, `build`, `.next`, `.turbo`, `.vercel`, `coverage`, `.DS_Store`, `.env`, `.env.local`, `.env.*` (covers `.env.production`, `.env.staging`, etc). |
| 38 | + |
| 39 | +Add to it via the `ignore` input — basenames anywhere in the tree, exact match or simple glob (`*.log`, `*.test.ts`). `#` comments and blank lines allowed. |
| 40 | + |
| 41 | +## Outputs |
| 42 | + |
| 43 | +| Output | Description | |
| 44 | +|---|---| |
| 45 | +| `function-id` | UUID of the created or updated function. | |
| 46 | +| `deploy-status` | `deployed`, `pending`, or `failed`. | |
| 47 | +| `created` | `true` on initial create, `false` on update. | |
| 48 | + |
| 49 | +## Examples |
| 50 | + |
| 51 | +### Minimal — pre-built bundle |
| 52 | + |
| 53 | +```yaml |
| 54 | +- uses: primitivedotdev/deploy-function@v1 |
| 55 | + with: |
| 56 | + api-key: ${{ secrets.PRIMITIVE_API_KEY }} |
| 57 | + name: my-function |
| 58 | + code-path: dist/handler.js |
| 59 | +``` |
| 60 | + |
| 61 | +### With custom secrets and an org-id guard |
| 62 | + |
| 63 | +```yaml |
| 64 | +- uses: primitivedotdev/deploy-function@v1 |
| 65 | + with: |
| 66 | + api-key: ${{ secrets.PRIMITIVE_API_KEY }} |
| 67 | + expected-org-id: ${{ vars.PRIMITIVE_ORG_ID }} |
| 68 | + name: my-function |
| 69 | + code-path: dist/handler.js |
| 70 | + secrets: | |
| 71 | + { |
| 72 | + "OPENAI_API_KEY": "${{ secrets.OPENAI_API_KEY }}", |
| 73 | + "FEATURE_FLAG": "on" |
| 74 | + } |
| 75 | +``` |
| 76 | + |
| 77 | +The action upserts each secret via `POST /v1/functions/{id}/secrets`, then calls `POST /v1/functions/{id}/redeploy` so the new bindings are live in the runtime. Set `redeploy-on-secret-change: false` to skip the redeploy step (only the secret rows are touched). |
| 78 | + |
| 79 | +### Managed build (`files-path`) |
| 80 | + |
| 81 | +Skip the build step and hand the platform your source. The platform bundles server-side, applying the same Workers-for-Platforms compatibility flags as the dashboard's managed-build path. |
| 82 | + |
| 83 | +```yaml |
| 84 | +- uses: actions/checkout@v4 |
| 85 | +- uses: primitivedotdev/deploy-function@v1 |
| 86 | + with: |
| 87 | + api-key: ${{ secrets.PRIMITIVE_API_KEY }} |
| 88 | + name: my-function |
| 89 | + files-path: ./function-source |
| 90 | + ignore: | |
| 91 | + # local-only assets the platform doesn't need |
| 92 | + fixtures |
| 93 | + *.test.ts |
| 94 | + *.spec.ts |
| 95 | +``` |
| 96 | + |
| 97 | +`function-source/` must contain a `package.json` at its root (dependencies may be empty). |
| 98 | + |
| 99 | +### Using outputs |
| 100 | + |
| 101 | +```yaml |
| 102 | +- id: deploy |
| 103 | + uses: primitivedotdev/deploy-function@v1 |
| 104 | + with: |
| 105 | + api-key: ${{ secrets.PRIMITIVE_API_KEY }} |
| 106 | + name: my-function |
| 107 | + code-path: dist/handler.js |
| 108 | +- run: echo "Deployed function-id=${{ steps.deploy.outputs.function-id }} (created=${{ steps.deploy.outputs.created }})" |
| 109 | +``` |
| 110 | + |
| 111 | +## Security |
| 112 | + |
| 113 | +- The `api-key` input is automatically masked. Pass it as a GitHub secret (`${{ secrets.* }}`) — never hard-code. |
| 114 | +- Every value passed via `secrets` is also masked. |
| 115 | +- Use `expected-org-id` in production workflows. It calls `GET /v1/whoami` before any write and aborts if the API key's org doesn't match. |
| 116 | + |
| 117 | +## Versioning |
| 118 | + |
| 119 | +- Floating major tag `v1` always tracks the latest 1.x. |
| 120 | +- Pin a specific minor/patch (`v1.2.0`) for reproducible deploys. |
| 121 | +- Breaking changes bump the major; `v1` stays alive for a deprecation window. |
| 122 | + |
| 123 | +## Source |
| 124 | + |
| 125 | +This action is authored in [primitivedotdev/primitive-mono-repo](https://github.com/primitivedotdev/primitive-mono-repo) under `tools/actions/deploy-function/` and mirrored here on release tags. See [RELEASING.md](./RELEASING.md) for the release process. |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +MIT — see [LICENSE](./LICENSE). |
0 commit comments