Home > Enterprise >  Can I pass a heredoc script to Elixir from Bash?
Can I pass a heredoc script to Elixir from Bash?

Time:06-24

I am playing around with the idea of using Elixir in GitHub actions workflows, because I think it would make for an excellent CI language (better than bash at least).

GitHub Actions does not have a straight-forward way to do this (like it does with nodejs). There is an action for installing Elixir though, so I have access to elixir and iex within the bash runtime of my workflow.

I'm thinking I could do something like this:

      # Install Elixir
      - uses: erlef/setup-beam@v1
        with:
          elixir-version: ${{ env.ELIXIR_VERSION }}
      # Run Elixir code via bash
      - run: |
          elixir -e "IO.puts(1336   1)"

This works. But is it possible to pass a multiline string, containing my script, to elixir -e? The following does not work:

elixir -e <<-EOT
  IO.puts(68 1)
EOT

I guess I could just create a file, but for small scripts I feel like it would be cleaner to just pipe in a heredoc.

CodePudding user response:

Since you don't want to use the stdin of elixir, using a here-doc is pointless. You could however provide a multiline string:

 elixir -e 'first line
 second line
 third line
 '

CodePudding user response:

I found a solution within GitHub actions, but I'm still curious about how I could use a heredoc instead of a single-line quoted string with elixir -e.

      - uses: erlef/setup-beam@v1
        with:
          otp-version: ${{ env.OTP_VERSION }}
          elixir-version: ${{ env.ELIXIR_VERSION }}

      - id: main
        run: |
          IO.puts(1 1)
        shell: elixir -r {0}
  • Related