Skip to content

Commit

Permalink
Add docs for running post deploy actions (#649)
Browse files Browse the repository at this point in the history
* Add docs for running post deploy actions

* more hyperlinks
  • Loading branch information
brody192 authored Jan 10, 2025
1 parent cef4aeb commit ca5a848
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/data/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,17 @@ export const sidebarContent: ISidebarContent = [
],
},
{
subTitle: "GitHub Tutorials",
subTitle: "Git Tutorials",
pages: [
{
title: "GitHub Actions",
url: "https://blog.railway.com/p/github-actions",
},
{
title: "Gitlab CI/CD",
url: "https://blog.railway.com/p/gitlab-ci-cd",
},
makePage("GitHub Post-Deploy Actions", "tutorials"),
],
},
],
Expand Down
4 changes: 4 additions & 0 deletions src/docs/guides/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ The current template variable functions are:
- `openssl rand -hex 32``${{secret(64, "abcdef0123456789")}}`
- `openssl rand -hex 64``${{secret(128, "abcdef0123456789")}}`

Or even generate a UUIDv4 string -

`${{secret(8, "0123456789abcdef")}}-${{secret(4, "0123456789abcdef")}}-4${{secret(3, "0123456789abcdef")}}-${{secret(1, "89ab")}}${{secret(3, "0123456789abcdef")}}-${{secret(12, "0123456789abcdef")}}`

2. `randomInt(min?: number, max?: number)`: Generates a random integer between min and max (defaults to 0 and 100)

## Managing Your Templates
Expand Down
52 changes: 52 additions & 0 deletions src/docs/tutorials/github-post-deploy-actions.md
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!

0 comments on commit ca5a848

Please sign in to comment.