I am trying to build an all-github workflow for CI and CD using Actions and the Deployments API. The CI part is done, and I am now facing a couple of confusing aspects when tackling the CD side of things.
1. How to run a workflow only when deployment environment == ‘production’?
I am planning on having a different workflow for staging and production. Intuitively, I was hoping I can do something like this:
on: deployment: types: [production]
or better yet - something close to “on push tags”:
on: ## this is available # push: # tags: ['v[0-9].[0-9]+.[0-9]+*'] ## this is not available deployment: environments: [stage]
But according to the Events that trigger workflows documentation there are no additional arguments (e.g. “types”) to that event. So how am I expected to run this workflow only if it is on a specific environment (e.g. “stage”)?
I hope the answer is not using some “if: conditionals”… in the same way that I can filter branches / tags on push, I hope to be able filter environments on deployment.
2. (Auto-) updating deployment status
When triggering a deployment using the API, I can see the workflow being triggered, and the deployment added to the Environments tab, as expected:
What was less expected, is that status remains at “Pending” after the workflow completed successfully.
Does this mean I have to take care of manually updating the status, from my workflow script, using the API? This seems way too tedious - go out using an API and access token, just to send message back in, where everything is already authorized and authenticated.
I understand it if this is just a temporary situation, since until recently, deployments were meant to execute external services - but now with GitHub Actions, I expected a workflow that runs on deployment, to automatically update the status, in the same way that CI (automated tests) automatically update the PR status.
If this is not the case, or not planned - I would love to have an official GitHub Action or “echo ::pattern::” to do that.
I found an external action that updates the deployment status, but it feels very dirty to use a user-built action for a concept so native to GitHub.
Also - if there is no document that outlines (by example) how to use GitHub Actions with deployment, I think there should be one (I could not find any) - I think these two concepts belong tightly together.
Thanks in advance if anyone can enlighten me.