-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
68 lines (57 loc) · 1.97 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: 'Switch into Nix Shell'
description: 'Switch into a Nix shell and export environment variables to subsequent steps.'
author: 'Lukas Mertens'
inputs:
nix_args:
description: 'Additional arguments to pass to nix print-dev-env.'
required: false
default: ''
install_nix:
description: 'Whether to install Nix. Set to false if Nix is already installed.'
required: false
default: 'true'
runs:
using: 'composite'
steps:
- name: Install Nix
if: ${{ inputs.install_nix == 'true' }}
uses: cachix/install-nix-action@v27
- name: Switch into Nix Shell
shell: bash
run: |
set -xe
# Function to save environment variables to a file
save_env() {
compgen -e | while read -r var; do
value="${!var}"
# Replace newlines with \n for comparison
escaped_value=$(printf '%s' "$value" | sed ':a;N;$!ba;s/\n/\\n/g')
echo "${var}=${escaped_value}"
done | sort > "$1"
}
before_env=$(mktemp)
after_env=$(mktemp)
diff_env=$(mktemp)
# Save initial environment
save_env "$before_env"
# Load Nix environment
nix_dev_env_script=$(mktemp)
nix print-dev-env ${{ inputs.nix_args }} > "$nix_dev_env_script"
source "$nix_dev_env_script"
# Save environment after loading Nix
save_env "$after_env"
# Find differences
diff "$before_env" "$after_env" | grep '^>' | sed 's/^> //' > "$diff_env" || true
# Add changed variables to GITHUB_ENV
while IFS='=' read -r name value; do
# Unescape newlines
unescaped_value=$(printf '%s' "$value" | sed 's/\\n/\n/g')
echo "${name}<<EOF" >> "$GITHUB_ENV"
echo "$unescaped_value" >> "$GITHUB_ENV"
echo "EOF" >> "$GITHUB_ENV"
done < "$diff_env"
echo "Environment variables added to GITHUB_ENV:"
cat "$diff_env"
branding:
icon: 'terminal'
color: 'blue'