PATH Handling in GitHub Actions

While playing around with getting a specific version of MinGW to run within a GitHub Actions, I had to add the MinGW’s bin/ directory to the PATH environment variable. This isn’t as straight forward as it would be in a batch or PowerShell script, because each GitHub Actions step is executed in an isolated fashion, so setting the PATH in one step, won’t transfer over to the next step.

Instead, GitHub Actions uses $GITHUB_PATH to workaround this issue. This is also officially documented, but what I didn’t understand for a bit, is that $GITHUB_PATH actually points to a file and in itself isn’t just another environment variable.

As shown in the following code and matching what’s written in the documentation, we write the path we want to be used in PATH into the $GITHUB_PATH variable pointing to a file. In my testing this only seemed to work in a Bash shell and not a PowerShell.

- name: Add MinGW bin directory to PATH
  shell: bash
  run: echo "${{ github.workspace }}\mingw32\bin" >> $GITHUB_PATH

Leave a Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.