-
Notifications
You must be signed in to change notification settings - Fork 375
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for running post deploy actions (#649)
* Add docs for running post deploy actions * more hyperlinks
- Loading branch information
Showing
3 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: GitHub Post-Deploy Actions | ||
--- | ||
|
||
[Github Actions](https://github.com/features/actions) come with a pretty neat set of features to automate your workflows. In this post, we talk about using Github Actions to run post-deploy actions. | ||
|
||
At Railway, we've set up Github triggers for automatic deployments when you push to a selected branch, and with Github Actions, you can automate several parts of your development workflow. Recently, within our [Discord](https://discord.gg/railway) and [Slack](/reference/support#slack), we've had a couple of users ask us how they'd go about running commands or webhooks after their app is deployed so we thought it'd be a good idea to publish a short tutorial doing just that, with Github Actions. | ||
|
||
## The Action | ||
|
||
Since Railway makes the deployment status available to Github, we'll be using the `deployment_status` event to trigger our action. This event is triggered when a deployment status changes, and we'll be using the `success` state to trigger our action. | ||
|
||
Make a new file in your repository called `.github/workflows/post-deploy.yml` and add the following - | ||
|
||
```yaml | ||
name: Post-Deployment Actions | ||
|
||
on: | ||
deployment_status: | ||
states: [success] | ||
|
||
jobs: | ||
post-deploy: | ||
runs-on: ubuntu-latest | ||
if: github.event.deployment_status.state == 'success' | ||
steps: | ||
- name: Debug - Print github.event object | ||
run: | | ||
echo "github.event context:" | ||
echo '${{ toJSON(github.event) }}' | ||
# Only run if this is a production environment deployment that succeeded | ||
- name: Run post-deploy actions | ||
if: github.event.deployment.environment == 'production' | ||
run: | | ||
echo "Production deployment succeeded" | ||
``` | ||
If you have your repository deploying to multiple services, you can modify the `if` condition to check for the service you want to run the command for - | ||
|
||
```yaml | ||
if: github.event.deployment.environment == 'production' && github.event.deployment.payload.serviceId == '<service-id>' | ||
``` | ||
You can also see what `github.event` contains and build your own conditions from there. | ||
|
||
Information on how to find the Service ID and Environment IDs as needed can be found [here](https://docs.railway.com/guides/public-api#resource-ids). | ||
|
||
It's that simple! You can now customize the final run step to execute any commands or send webhooks using Curl or other methods of your choice. | ||
|
||
## Conclusion | ||
|
||
We hope this tutorial has been helpful and that you'll find it useful for your own projects. If you have any questions or feedback, please feel free to reach out to us on [Discord](https://discord.gg/railway), [Slack](/reference/support#slack) or the [Help Station](https://help.railway.com). Happy coding! |