/get-persistent-value

Gets a value that persists through GitHub Action jobs, steps, or workflows.

Primary LanguageTypeScriptMIT LicenseMIT

uptime uptime uptime uptime

Overview

Set or get a value that persists through GitHub Actions jobs, steps, or workflows.

  • Execute some logic if a file hash has changed
  • Keep track of a URL required in other steps of your workflow (like a Vercel preview URL)
  • Set a boolean value to make other steps in your workflow optional

Any questions, comments, feedback? Join the #gh-persistent-values channel or open a new issue.

Usage

Set a persistent value

Set a single value

For single values, the action takes the inputs below:

Input Description
key The key for the value you want to set
value The value to set
access_token Visit this URL, then add this access token as a GitHub secret to your repo (e.g. PERSISTENT_VALUE_ACCESS_TOKEN).
steps:
  - name: Set a persistent value
    id: set_persistent_value
    uses: aaimio/set-persistent-value@v1.2.1
    with:
      key: foo
      value: bar
      access_token: ${{ secrets.PERSISTENT_VALUE_ACCESS_TOKEN }}

Set multiple values

For multiple values, the action takes the inputs below:

Input Description
json A JSON string with the keys and values you want to set
access_token Visit this URL, then add this access token as a GitHub secret to your repo (e.g. PERSISTENT_VALUE_ACCESS_TOKEN).
steps:
  - name: Set a persistent value
    id: set_persistent_value
    uses: aaimio/set-persistent-value@v1.2.1
    with:
      json: '{ "some_key": 42, "foo": "bar", "boolean_value": true }'
      access_token: ${{ secrets.PERSISTENT_VALUE_ACCESS_TOKEN }}

Get a persistent value

This action takes the inputs below:

Input Description
key The key for the value you want to retrieve
access_token Visit this URL, then add this access token as a GitHub secret to your repo (e.g. PERSISTENT_VALUE_ACCESS_TOKEN).
steps:
  - name: Get a persistent value
    id: get_persistent_value
    uses: aaimio/get-persistent-value@v1.2.1
    with:
      key: foo
      access_token: ${{ secrets.PERSISTENT_VALUE_ACCESS_TOKEN }}
  - name: Some other step
    run: |
      echo ${{ steps.get_persistent_value.outputs.value }}

Using the API directly

In the background, the action is talking to a simple key-value store.

To reduce the overhead of downloading the action or introducing yet another step into your workflow, you could also use the API directly:

Setting a value

curl -X POST \
  -H 'x-api-key: ${{ secrets.PERSISTENT_VALUE_ACCESS_TOKEN }}' \
  -H 'x-github-repo: <GITHUB_OWNER/GITHUB_REPO>' \
  -H 'content-type: application/json' \
  -d '{ "value": "some_value" }' \
  'https://persistent.aaim.io/api/values/set?key=YOUR_KEY&output=plain'

Getting a value

SOME_VALUE=$(curl -X GET \
  -H 'x-api-key: ${{ secrets.PERSISTENT_VALUE_ACCESS_TOKEN }}' \
  -H 'x-github-repo: <GITHUB_OWNER/GITHUB_REPO>' \
  'https://persistent.aaim.io/api/values/get?key=YOUR_KEY&output=plain')

echo $SOME_VALUE
  • The x-github-repo header is completely optional, it will only keep track of which repositories are using the action or API.

Things to note

  • Items will persist until the access_token hasn't been used for 3 months.