Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build action does not pick up environment variables input #6

Open
imajus opened this issue Dec 6, 2024 · 2 comments · May be fixed by #7
Open

Build action does not pick up environment variables input #6

imajus opened this issue Dec 6, 2024 · 2 comments · May be fixed by #7

Comments

@imajus
Copy link

imajus commented Dec 6, 2024

I'm building Next.js app that requires all app's environment variables to be provided at the build stage:

- name: Build and push Docker images
  uses: iloveitaly/github-action-nixpacks@main
  with:
    push: true
    env: |
      NEXT_PUBLIC_BASE_URL=${{ vars.BASE_URL }}
      NEXT_PUBLIC_TEMPLATE_CLIENT_ID=${{ vars.THIRDWEB_CLIENT_ID }}
      NEXT_PUBLIC_EAS_CONTRACT_ADDRESS=${{ vars.EAS_CONTRACT_ADDRESS }}
      NEXT_PUBLIC_CONTRACT_SCHEMA_ID=${{ vars.CONTRACT_SCHEMA_ID }}
      NEXT_PUBLIC_SIGNATORY_SCHEMA_ID=${{ vars.SIGNATORY_SCHEMA_ID }}

However, this step fails with a build error indicating that one of the required environment variables is missing.

Based on my limited knowledge of bash I've found that this may be the problem:

# Include environment variables in the build command
if [ -n "${INPUT_ENV}" ]; then
  IFS=',' read -ra ENVS <<<"$INPUT_ENV"
  for env_var in "${ENVS[@]}"; do
    BUILD_CMD="$BUILD_CMD --env $env_var"
  done
fi

So the script expects the values to be passed as comma separated, whereas in YAML there's a standard way to create a list of strings separated by line breaks, and there's no such way for comma separated lists.

Or maybe I'm missing something out? What is the correct way to pass multiple environment variables to the build stage execution context?

@imajus imajus linked a pull request Dec 7, 2024 that will close this issue
@iloveitaly
Copy link
Owner

iloveitaly commented Dec 8, 2024

This seems like an obvious miss on my part, so I think there may have been a good reason for why I did it this way, but I can't remember what my past self was thinking off the top of my head. Thanks for the PR, going to look at this next week and merge or get to the bottom of my reasoning here.

Thanks!

@imajus
Copy link
Author

imajus commented Dec 8, 2024

Sure. Feel free to reject my PR and provide your own solution, since it's obvious that you know the shell scripting much better than I do.
What I've submitted is a minimal change that has allowed me to successfully deploy my own project. But it may break the deployment pipeline for anyone who relies on the old way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants