[bug#77703] guix-install.sh: Add to GITHUB_PATH in CI

Message ID 20250410065645.4242-1-rik.huijzer@gmail.com
State New
Headers
Series [bug#77703] guix-install.sh: Add to GITHUB_PATH in CI |

Commit Message

Rik Huijzer April 10, 2025, 6:55 a.m. UTC
  I was trying to use guix inside a GitHub CI runner, and saw that this
code works:

```yaml
- uses: actions/checkout@v4
- run: sudo apt install guix
- run: echo "$HOME/.guix-profile/bin" >> $GITHUB_PATH
- run: guix install hello
- run: hello
```

But, I wonder if the line that adds `.guix-profile/bin` to the path can
be avoided. Without it the run fails. Normally, `apt install` also
modifies the PATH, so for me as a naive user it would be more intuitive
if the installer could do so here too.

For security reasons, GitHub has switched to the `$GITHUB_PATH`
environment variable in 2020
(https://stackoverflow.com/a/64831469/5056635). This PR suggests to add
it to the installer.

The code verifies that the CI env var is set to "true", which is always
true in GitHub Runners (see first entry in table at
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables).
Then it also checks that GITHUB_PATH is set. I think it's a reasonable
assumption that if a system sets CI to true and GITHUB_PATH to
something, then it must be a GitHub Runner or at
least a system that looks like a GitHub Runner. But of course I could be
wrong.
---
 etc/guix-install.sh | 3 +++
 1 file changed, 3 insertions(+)


base-commit: 2934de1447f87b361608ef3a2a756b8a5d2f42e6
  

Patch

diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index b5d833c..c6a2c54 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -752,6 +752,9 @@  export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
 # `guix pull` profile
 GUIX_PROFILE="$HOME/.config/guix/current"
 export PATH="$GUIX_PROFILE/bin${PATH:+:}$PATH"
+if [ "${CI}" == "true" ] && [ -n "${GITHUB_PATH}" ]; then
+  echo "$GUIX_PROFILE/bin" >> $GITHUB_PATH
+fi
 # Add to INFOPATH and MANPATH so the latest Guix documentation is available to
 # info and man readers.  When INFOPATH is unset, add a trailing colon so Emacs
 # searches 'Info-default-directory-list'.  When MANPATH is unset, add a