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

Take deployment environment into account when deciding what is affected #162

Open
MxKaras opened this issue Jun 19, 2024 · 3 comments
Open
Assignees

Comments

@MxKaras
Copy link

MxKaras commented Jun 19, 2024

Our problem:

We have three environments in Github: dev, staging, and production. Our flow is that we deploy feature branches to dev, and when it is merged deploy to staging and then production. These latter two are both deploying main.

We are using this action with last-successful-event: deployment.

Right now npx nx affected -t deploy gives the following outcomes:

  • dev: incremental deploy as expected ✅
  • staging: incremental deploy as expected ✅
  • production: nothing is deployed as there is already a successful deployment to main

Proposed Solution:

Change the action to accept an optional deployment-environment that will be used when last-successful-event is deployment to differentiate between deployments to different environments.

@fvalmeida
Copy link

Hey, maintainers, do you have any recommendations on how to deal with this situation? There have been no comments so far, so I'm not sure if this is considered a problem to be addressed.

@meeroslav
Copy link
Collaborator

Hi @MxKaras and @fvalmeida,

Sorry for the delay. I'm not sure I fully understand your problem.
From my understanding the flow should be the following:

- Run `nx-set-shas` on `main` to find `BASE` and `HEAD` SHAs
- Running `nx affected -t deploy` on both `staging` and `production`

If these are running on a separate workflow, I would run the nx-set-shas in a separate job and then pass the BASE and HEAD as input to the other two jobs/workflows.

Does that make sense? If not, can you provide more detailed example?

@meeroslav meeroslav self-assigned this Mar 6, 2025
@MxKaras
Copy link
Author

MxKaras commented Mar 23, 2025

Hi @meeroslav , thanks for the reply. I'll expand on our flow. A merge to main triggers a series of automated steps:

  • Merge PR to main
  • create deployment to GH environment staging
  • trigger build & deploy workflow
    • nx-set-shas with last-successful-event: deployment
    • nx affected -t deploy
    • mark deployment success

Separately, we have a manually run action that creates a deployment to GH environment production, kicking off another build & deploy workflow with the same steps. This is typically run after staging has completed, but it in theory can be used to deploy any ref to any env.

Assuming that the production workflow runs after the staging one has completed successfully, running nx-set-shas will return HEAD == BASE because a successful deployment has already been made to main during the staging deployment.

If it was possible to not only find the commit for the last successful deployment, but the commit for the last successful deployment to a specified environment, that would be very useful. Right now we are deploying all services in production for every change.

Running nx-set-shas separately and caching HEAD/BASE or whatever would be technically possible but I don't want to play around with that if the tool can do the work for me. I could probably raise a PR mysef, but I haven't got around to doing so yet in almost a year so who knows if I'd ever get round to it 😅

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

No branches or pull requests

3 participants