Skip to content

zentered/cloudflare-kv-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Cloudflare KV Action

Test Release semantic-release: conventional Conventional Commits

Put and get values from Cloudflare KV.

Table of Contents

Usage

Bearer Token (recommended)

Create an API Token with Workers KV Storage permissions.

- name: cloudflare-kv-action
  uses: zentered/cloudflare-kv-action@v2
  id: cloudflare_kv
  env:
    CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    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 }}"

Legacy Auth (API Key + Email)

- name: cloudflare-kv-action
  uses: zentered/cloudflare-kv-action@v2
  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 your Cloudflare credentials. You can retrieve them on your Cloudflare account.

Variable Required Description
CLOUDFLARE_ACCOUNT_ID required From the URL: https://dash.cloudflare.com/123abc....
CLOUDFLARE_API_KEY required API Token (Bearer) or Global API Key (legacy)
CLOUDFLARE_ACCOUNT_EMAIL optional Required only for legacy API Key auth

Inputs

Name Requirement Description
namespace_identifier required Cloudflare namespace ID
key_name required KV key name
value optional Use "value" to set a key; omit to retrieve the current value
expiration optional Absolute expiration (Unix timestamp)
expiration_ttl optional Relative expiration in seconds. If both expiration and expiration_ttl are set, expiration takes precedence.

Cloudflare API Reference

Outputs

Name Description
value KV value

Development

Requirements: Node >= 20

# Install dependencies
npm install

# Copy and fill in your Cloudflare credentials
cp .env.example .env

# Run linter
npm run lint

# Run tests (unit tests run without credentials; integration tests require .env)
npm test

# Rebuild dist/ after code changes
npm run prepare

Contributing

See CONTRIBUTING.

License

See LICENSE.

About

GitHub Action set and get Cloudflare KV values

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Contributors