Guelor
Github Actions Env variables not being read from os::env
I’m still new to GitHub action. I’m running a Phoenix/Elixir project, In my config file, I have the following configuration for the test:
# Set HTTPClientMock as the HTTP client for the PayService
config :sender_service, :pay_service,
http_client: SenderService.HTTPClientMock,
url: System.get_env("PAY_URL"),
secret_key: System.get_env("PAY_SECRET_KEY"),
api_key: System.get_env("PAY_API_KEY")
and this a snippet of the test:
defmodule SenderService.PayServiceTest do
use ExUnit.Case, async: true
alias SenderService.PayService
import Mox
describe "pay_service" do
@http_client SenderService.HTTPClientMock
test "get_balances returns a list of balances" do
url = System.get_env("PAY_URL") <> "/v1/accounts/balances"
list_balances_body = [
%{
balance: "0.00000000",
holdAmount: "0.00000000",
productSymbol: "USD"
}
]
expect(@http_client, :get, fn actual_url, actual_headers ->
assert actual_url == "https://uat-pay-api.com/v1/accounts/balances"
# Check that Authorization header is present
authorization_header = List.keyfind(actual_headers, "Authorization", 0)
assert authorization_header != nil
{:ok, %HTTPoison.Response{body: list_balances_body |> Jason.encode!(), status_code: 200}}
end)
assert {:ok, balances} = PayService.get_balances()
expected_balances = [
%{
"balance" => "0.00000000",
"holdAmount" => "0.00000000",
"productSymbol" => "USD"
}
]
assert expected_balances == balances
Mox.verify!(@http_client)
end
end
end
which works locally with the config/test.exs file that I provide. But I’m getting the following error on GitHub action:
- test pay_service get_balances returns a list of balances ( SenderService.PayServiceTest)
Error: test/sender_service/pay_service_test.exs:11
** (ArgumentError) construction of binary failed: segment 1 of type ‘binary’: expected a binary but got: nil
code: url = System.get_env(“PAY_URL”) <> “/v1/accounts/balances”
stacktrace:
test/sender_service/pay_service_test.exs:12: (test)
I attempted to add the environment variables to both the “Actions secrets and variables” on GitHub, but I’m still encountering the error mentioned above. Am I missing something? Below are the “.yml” files for the workflow:
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
name: Elixir CI
on:
push:
jobs:
verify:
# Set up a Postgres DB service. By default, Phoenix applications
# use Postgres. This creates a database for running tests.
# Additional services can be defined here if required.
runs-on: ubuntu-latest
strategy:
# Specify the OTP and Elixir versions to use when building
# and running the workflow steps.
matrix:
otp: [25.0.4] # Define the OTP version [required]
elixir: [1.14.3] # Define the elixir version [required]
services:
db:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: sender_service_dev
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Step: Setup Elixir + Erlang image as the base.
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}
# Step: Check out the code.
- name: Checkout code
uses: actions/checkout@v3
# Step: Define how to cache deps. Restores existing cache if present.
- name: Cache deps
id: deps-cache
uses: actions/cache@v3
env:
cache-name: cache-elixir-deps
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
# Step: Define how to cache the `_build` directory. After the first run,
# this speeds up tests runs a lot. This includes not re-compiling our
# project's downloaded deps every run.
- name: Cache compiled build
id: build-cache
uses: actions/cache@v3
env:
cache-name: cache-compiled-build
with:
path: _build
key: ${{ runner.os }}-build-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
# Step: Download project dependencies. If unchanged, uses
# the cached version.
- name: Install deps
run: |
mix deps.get
# Step: Check that the checked in code has already been formatted.
# This step fails if something was found unformatted.
- name: Check Formatting
run: mix format --check-formatted
# Step: Execute the tests
- name: Run tests
run: mix test
# deploy:
# # only run this job if the verify job succeeds
# needs: verify
# # only run this job if the workflow is running on the master branch
# if: github.ref == 'refs/heads/master'
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# # actions/checkout@v2 only checks out the latest commit,
# # so we need to tell it to check out the entire master branch
# with:
# ref: master
# fetch-depth: 0
# # configure the gigalixir-actions with our credentials and app name
# - uses: mhanberg/gigalixir-action@v0.1.0
# with:
# GIGALIXIR_USERNAME: ${{ secrets.GIGALIXIR_USERNAME }}
# GIGALIXIR_PASSWORD: ${{ secrets.GIGALIXIR_PASSWORD }}
# GIGALIXIR_APP: ${{ secrets.GIGALIXIR_APP }}
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
Any help on this would be deeply appreciated, thanks! ![]()
Popular in Questions
In Ruby, I can go:
User.find_by(email: "foobar@email.com").update(email: "hello@email.com")
How can I do something similar in Elixir? ...
New
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lis...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size?
Thanks
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I’ve been re-reading swift book again and noticed that multiline strings there don’t have a trailing line break, unlike in elixir
iex(2)...
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hi folks,
Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
by Lance Halvorsen
Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
New







