https://github.com/zentered/cloudflare-kv-action
GitHub Action set and get Cloudflare KV values
https://github.com/zentered/cloudflare-kv-action
cloudflare-kv cloudflare-pages cloudflare-workers
Last synced: 6 months ago
JSON representation
GitHub Action set and get Cloudflare KV values
- Host: GitHub
- URL: https://github.com/zentered/cloudflare-kv-action
- Owner: zentered
- License: mit
- Created: 2022-04-11T18:18:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-20T14:26:52.000Z (over 1 year ago)
- Last Synced: 2025-04-02T23:05:58.532Z (6 months ago)
- Topics: cloudflare-kv, cloudflare-pages, cloudflare-workers
- Language: JavaScript
- Homepage:
- Size: 488 KB
- Stars: 16
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudflare KV Action


[](https://github.com/semantic-release/semantic-release)
[](https://conventionalcommits.org)Put and get values from Cloudflare KV.
## Table of Contents
- [Usage](#usage)
- [Environment Variables](#environment-variables--secret)
- [Inputs](#inputs)
- [Outputs](#outputs)## Usage
[Copy your "Global API Key"](https://dash.cloudflare.com/profile/api-tokens)
Cloudflare needs a little time to build the preview, you can check the average
build time in your deployments and add the seconds plus a little to a `sleep`
action, to wait until the deployment is ready. The action only works on
branches, so make sure you exclude the `main` branch from the trigger:```yaml
on:
push:
branches:
- '**'
- '!main'
```Here are the steps for an example job:
```yaml
- run: sleep 30
- name: cloudflare-kv-action
uses: zentered/cloudflare-kv-action@v1.0.0
id: cloudflare_kv
env:
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
namespace_identifier: '123'
key_name: 'hello'
value: 'world'
expiration_ttl: 120
- name: Value
run: echo "${{ steps.cloudflare_kv.outputs.value }}"
```## Environment Variables / Secret
In the repository, go to "Settings", then "Secrets" and add
"CLOUDFLARE_API_TOKEN", the value you can retrieve on your
[Cloudflare account](https://dash.cloudflare.com/profile/api-tokens). You also
need to add:- `CLOUDFLARE_ACCOUNT_EMAIL` (your login email, optional)
- `CLOUDFLARE_ACCOUNT_ID` (from the URL:
`https://dash.cloudflare.com/123abc....`)
- `CLOUDFLARE_API_KEY` (from the URL:
`https://dash.cloudflare.com/profile/api-tokens`)## Inputs
| Name | Requirement | Description |
| ---------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `namespace_identifier` | required | Cloudflare namespace ID |
| `key_name` | required | KV key name |
| `value` | optional | Optional: Use "value" to set a key, otherwise it will be retrieved |
| `expiration` | optional | Optional: expiration |
| `expiration_ttl` | optional | Optional: If neither expiration nor expiration_ttl is specified, the key-value pair will never expire. If both are set, expiration_ttl is used and expiration is ignored. |[Cloudflare API Reference](https://api.cloudflare.com/#workers-kv-namespace-write-key-value-pair)
## Outputs
| Name | Description |
| ------- | ----------- |
| `value` | KV value |## Contributing
See [CONTRIBUTING](CONTRIBUTING.md).
## License
See [LICENSE](LICENSE).