Skip to content
\n

(explicitly instructed to not read from .bash_profile and .bashrc files).

\n

I tried adding an explicit shell: bash {0} to each step, but this does not seem to have made any difference.

\n

Below is an example workflow.

\n

For nvm: the --install argument when sourcing into the shell tells nvm to auto-install & switch to the version of node found in the .nvmrc file

\n

For rvm: the rvm_install_on_use_flag environment variable tells rvm to auto-install & switch to the version of ruby found in the .ruby-version file.

\n
frontend:\n    runs-on: ubuntu-latest\n
steps:\n- name: Checkout repository\n  uses: actions/checkout@v1\n
\n
    \n
  • \n

    name: Check versions (before)
    \nshell: bash {0}
    \nrun: |
    \nnode --version
    \nnpm --version

    \n
      \n
    • \n

      name: Install nvm
      \nshell: bash {0}
      \nrun: |
      \ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
      \nexport NVM_DIR=\"$HOME/.nvm\"
      \necho \"source $NVM_DIR/nvm.sh --install\" >> \"$HOME/.bash_profile\"

      \n
    • \n
    • \n

      name: Check versions (after)
      \nshell: bash {0}
      \nrun: |
      \nnode --version
      \nnpm --version

      \n
    • \n
    \n

    backend:
    \nruns-on: ubuntu-latest

    \n

    steps:

    \n
      \n
    • name: Checkout repository
      \nuses: actions/checkout@v1
    • \n
    \n
  • \n
  • \n

    name: Install rvm
    \nshell: bash {0}
    \nrun: |
    \ngpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
    \ncurl -sSL https://get.rvm.io | bash -s stable
    \nexport rvm_install_on_use_flag=1
    \necho \"source $HOME/.rvm/scripts/rvm\" >> \"$HOME/.bash_profile\"

    \n
      \n
    • name: Check versions (after)
      \nshell: bash {0}
      \nrun: |
      \nrvm --version
      \nruby --version
      \ngem --version
      \nbundler --version
      \n
\n\n\n\n

For the frontend job, I had expected node --version to be v10.16.3 in the ‘before’ step; and v12.1.0 in the ‘after’ step;  but it is v10.16.3 in both.

\n

It seems that the changes to .bash_profile are not seen by other steps?  (for what it’s worth, I also tried .bashrc instead…to no avail).

\n

Is there a way that I can have the NVM/RVM scripts sourced into all subsequent shell processes in a job?

\n

(also, having to repeat shell: bash {0} in every step is pretty annoying).

","upvoteCount":8,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

You were close: You can actually just add shell: bash -l {0} (the -l was missing from yours) for steps where you need to source the bash_profile. See: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

\n

I am aso assuming that install script primarily exports/updates the PATH to include the nvm install location, so youd only need to add the shell option for steps that need to exec node

\n

The default was to invoke bash non-interactive and non-login since semantically thats closest to what we are doing- just running scripts, and I wanted to avoid adding potential side effects, unexpected behavior, re-running the same statup files repeatedly for each step, etc. The shell option was intended to allow you to manage these types of scenarios as necessary. Its not really the expected default behavior since we have setup actions that download/install tools and modify the PATH, etc, so that the tools installed are available everywhere not just from bash steps that pass down the environment, PATH is tracked by the runner across steps, etc

","upvoteCount":4,"url":"https://github.com/orgs/community/discussions/25061#discussioncomment-3246364"}}}

How to share shell profile between steps? (or: how to use nvm/rvm in steps?) #25061

Answered by dakale
scottohara asked this question in Actions
Discussion options

You must be logged in to vote

You were close: You can actually just add shell: bash -l {0} (the -l was missing from yours) for steps where you need to source the bash_profile. See: https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html

I am aso assuming that install script primarily exports/updates the PATH to include the nvm install location, so youd only need to add the shell option for steps that need to exec node

The default was to invoke bash non-interactive and non-login since semantically thats closest to what we are doing- just running scripts, and I wanted to avoid adding potential side effects, unexpected behavior, re-running the same statup files repeatedly for each step, etc. The shel…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants