Automatic deployment paired with Github Actions = failure for environment variables?

I am currently trying to automate my Atlas App Services workflow and need some help setting the environment. To start, I’ve been reading the documentation as well as working from this article:

I’m starting with a simple use case where I have:

  • connected each of my pre-existing apps to a branch in my Github repo
  • set up each of the apps to use Github automatic deployment
  • created different values in my app’s /environment folder for development.json, testing.json, production.json, etc.

However, I need to find a way to dynamically modify root_config.json as part of the deploy process to set the environment based on the particular Github branch being committed (dev, qa, testing).

That’s where things get confusing.

I’m following the instructions in the article on how to use Github actions to modify the root_config.json file, e.g.

sed -i txt 's/{/{ "environment": "development",/' root_config.json

But even after this action runs successfully, the deploy isn’t working on AppServices and it’s giving a really vague error (Failed: error processing request). I have no additional information from the deploy to help me troubleshoot what went wrong, and trying to export the state just exports the last successful build – not the one that’s throwing the error.

Digging in deeper, the example from the article doesn’t seem to be using Github automatic deployment at all. It looks like it’s manually pushing the commit to Realm using the CLI tool inside Github Actions.

So am I supposed to use Github automatic deployment? If so, how can I set the environment based on the branch?

Or if the only way to do that is with Github actions, does that mean I have to disable Github automatic deployment entirely and just rely on Github actions to do the pushes directly via the realm-cli inside my Github action?

And if I disable Github automatic deployment, that seems like it could potentially impact sync issues with any updates I might have to potentially make using the UI.

My experience with this has been confusing and the docs aren’t helping at all to explain how these two things interact, so thought someone else here might have some insight.

After spending the day trying various ways to work around this, I’ve found a solution – and uncovered a very annoying bug with the appservices cli

The workaround is that I basically have had to completely drop automatic Github deployment and environment values and do everything via Github actions. This is mildly annoying because it means I can’t ever really make use of the Atlas UI tools to make a small change.

However, the annoying bug I discovered is that if you have “Automatic deployments enabled” on your project, then it will always try to build from the raw Github repo even if you’re performing Github actions and calling the appservices cli locally.

In my example, I was using github actions to modify my root_config.json file and then using appservices push to deploy the modified app. However, since “Automatic deployments enabled” was activated from my account, even when I specificed appservices push --local to tell it to push my locally modified project, the system would still just pull the raw, unaltered project from Github (and then it would compile with an error or incorrect values).

So my only solution for using Github actions was to completely go all in on it, and not use any of the Github integration tools. This was super confusing for me, hope it helps someone else.