Skip to content

Commit ecb69f8

Browse files
authored
Merge pull request #72 from gadget-inc/nix-github-actions
Use nix to setup the environment in CI
2 parents 6b13ca4 + 45e4c75 commit ecb69f8

File tree

1 file changed

+42
-25
lines changed

1 file changed

+42
-25
lines changed

.github/actions/setup-test-env/action.yml

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,49 @@ outputs: {}
55
runs:
66
using: "composite"
77
steps:
8-
- name: Install Node.js
9-
uses: actions/setup-node@v3
10-
with:
11-
node-version: 21
8+
- uses: cachix/install-nix-action@v18
9+
with:
10+
install_url: https://releases.nixos.org/nix/nix-2.11.1/install
11+
- run: |
12+
source <(nix print-dev-env --show-trace)
13+
output_file="nix-env.txt"
1214
13-
- uses: pnpm/action-setup@v2
14-
name: Install pnpm
15-
id: pnpm-install
16-
with:
17-
version: 8
18-
run_install: false
15+
# Clear the output file
16+
> $output_file
1917
20-
- name: Get pnpm store directory
21-
id: pnpm-cache
22-
shell: bash
23-
run: |
24-
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
18+
# Loop over each variable in the environment
19+
while IFS='=' read -r -d '' name value; do
20+
# Skip if the variable is a function or read-only or non-alphanumeric
21+
[[ "$(declare -p $name)" =~ "declare -[a-z]*r[a-z]* " ]] && continue
22+
[[ ! $name =~ ^[a-zA-Z_][a-zA-Z0-9_]*$ ]] && continue
2523
26-
- uses: actions/cache@v3
27-
name: Setup pnpm cache
28-
with:
29-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
30-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
31-
restore-keys: |
32-
${{ runner.os }}-pnpm-store-
24+
# Check if the variable value contains a newline
25+
if [[ "$value" != *$'\n'* ]]; then
26+
# It doesn't, so write the variable and its value (stripping quotes) to the file
27+
echo "${name}=${value//\"/}" >> $output_file
28+
fi
29+
done < <(env -0)
3330
34-
- name: Install dependencies
35-
shell: bash
36-
run: pnpm install
31+
# useful for debugging what env is exported
32+
# cat nix-env.txt
33+
shell: bash
34+
- run: cat nix-env.txt >> "$GITHUB_ENV"
35+
shell: bash
36+
37+
- name: Get pnpm store directory
38+
id: pnpm-cache
39+
shell: bash
40+
run: |
41+
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
42+
43+
- uses: actions/cache@v3
44+
name: Setup pnpm cache
45+
with:
46+
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
47+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
48+
restore-keys: |
49+
${{ runner.os }}-pnpm-store-
50+
51+
- name: Install dependencies
52+
shell: bash
53+
run: pnpm install

0 commit comments

Comments
 (0)