Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ jobs:
node-version: '20'
- run: |
yarn
echo "👉 Running yarn build:once"
yarn build:once

echo "👉 Running yarn test:once"
yarn test:once

echo "👉 Running yarn lint"
yarn lint

echo "👉 Running yarn format:preview"
yarn format:preview
37 changes: 31 additions & 6 deletions .github/workflows/run-integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ jobs:
with:
variables: |
URL=https://github.com
# Next step: verify that the variable has been saved in the ENV.
- run: |
echo "Exported variable URL=$URL"
if [ -z "$URL" ]; then
echo "Error: github-action-store-variable lib did not save 'URL' to ENV as expected. The library is not working as intended."
exit 1
fi
echo "Exported variable URL is: $URL"
env:
URL: ${{ env.URL }}

run-integration-test2:
runs-on: ubuntu-22.04
needs: run-integration-test1
Expand All @@ -41,12 +47,22 @@ jobs:
variables: |
URL
SECOND_URL=https://github.com/UnlyEd
# Next step: verify that both URL and SECOND_URL were propagated.
- run: |
echo "Found from previous job URL=$URL"
echo "Exported variable SECOND_URL=$SECOND_URL"
if [ -z "$URL" ]; then
echo "Error: github-action-store-variable lib did not propagate 'URL' to the environment as expected. The library is not working as intended."
exit 1
fi
if [ -z "$SECOND_URL" ]; then
echo "Error: github-action-store-variable lib did not save 'SECOND_URL' to ENV as expected. The library is not working as intended."
exit 1
fi
echo "Found from previous job, URL is: $URL"
echo "Exported variable SECOND_URL is: $SECOND_URL"
env:
URL: ${{ env.URL }}
SECOND_URL: ${{ env.SECOND_URL }}

run-integration-test3:
runs-on: ubuntu-22.04
needs: run-integration-test2
Expand All @@ -61,9 +77,18 @@ jobs:
variables: |
URL
SECOND_URL
# Next step: verify that URL and SECOND_URL are available.
- run: |
echo "Found from previous job URL=$URL"
echo "Found from previous job SECOND_URL=$SECOND_URL"
if [ -z "$URL" ]; then
echo "Error: github-action-store-variable lib did not propagate 'URL' to the environment as expected. The library is not working as intended."
exit 1
fi
if [ -z "$SECOND_URL" ]; then
echo "Error: github-action-store-variable lib did not propagate 'SECOND_URL' to the environment as expected. The library is not working as intended."
exit 1
fi
echo "Found from previous job, URL is: $URL"
echo "Found from previous job, SECOND_URL is: $SECOND_URL"
env:
URL: ${{ env.URL }}
SECOND_URL: ${{ env.SECOND_URL }}
Expand All @@ -80,4 +105,4 @@ jobs:
with:
variables: |
UNKNOWN_VAR
failIfNotFound: false # Default is false
failIfNotFound: false # Default is false, so missing UNKNOWN_VAR is allowed.
101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,107 @@

# GitHub Action - Store variables between your jobs

## Overview

This GitHub Action was originally created **in 2021** to allow you to **store variables** in a global store and then **read them in
later jobs**—something that was not natively possible in GitHub Actions. It automatically adds read variables to
your `${{ env }}` so that they become available for subsequent steps.

## But… GitHub Actions native outputs make this library largely unnecessary!

### What Are Native Outputs?

GitHub Actions now provides native support for sharing data between jobs through the use of step outputs and job
outputs. You can:

- **Set a step output:** Write key/value pairs to `$GITHUB_OUTPUT` in a step.
- **Define job outputs:** Map outputs from a step to a job-level output.
- **Access job outputs:** In downstream jobs, access these outputs using the `needs` context.

Similarly, the `$GITHUB_ENV` file allows you to persist environment variables across steps in the same job.

Source: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/passing-information-between-jobs

### Why Is This a Game Changer?

Originally, this library provided a way to emulate global variable sharing:

- **Before:** GitHub Actions did not support sharing environment variables between jobs.
- **Now:** Native outputs let you write a variable in one job and read it in another without extra actions or artifacts.

This native support simplifies your workflows, reduces dependencies, and improves reliability.

---

## Converting a Use Case

### Old Approach (Using `UnlyEd/github-action-store-variable`) - ⚠️ DEPRECATED

Below is an example of how you might have stored and retrieved a variable with the library:

```yaml
jobs:
compute-data:
runs-on: ubuntu-22.04
steps:
- name: Compute data
run: |
MY_VAR="Hello, World!"
echo "MY_VAR=$MY_VAR" >> $GITHUB_ENV

- name: Store variable using the library
uses: UnlyEd/[email protected]
with:
variables: |
MY_VAR=${{ env.MY_VAR }}

use-data:
runs-on: ubuntu-22.04
needs: compute-data
steps:
- name: Retrieve variable using the library
uses: UnlyEd/[email protected]
with:
variables: |
MY_VAR
- name: Use variable
run: echo "MY_VAR is $MY_VAR"
```

### New Approach (Using Native Outputs)
Here’s how you can achieve the same result without an external action:

```yaml
jobs:
compute-data:
runs-on: ubuntu-22.04
outputs:
MY_VAR: ${{ steps.set-output.outputs.MY_VAR }}
steps:
- name: Compute data
run: |
MY_VAR="Hello, World!"
echo "MY_VAR=$MY_VAR" >> $GITHUB_ENV

- name: Set step output
id: set-output
run: |
# Export MY_VAR as a step output, so it can be mapped to the job output
echo "MY_VAR=${MY_VAR}" >> $GITHUB_OUTPUT

use-data:
runs-on: ubuntu-22.04
needs: compute-data
steps:
- name: Use variable from job outputs
run: echo "MY_VAR is ${{ needs.compute-data.outputs.MY_VAR }}"

```

---

# Former documentation

## Code snippet example (minimal example)

```yaml
Expand Down
Loading
Loading