From ca5a84819054d5653f73f88c3aa4b9ea42210380 Mon Sep 17 00:00:00 2001 From: Brody Over <10548119+brody192@users.noreply.github.com> Date: Fri, 10 Jan 2025 01:41:28 -0500 Subject: [PATCH] Add docs for running post deploy actions (#649) * Add docs for running post deploy actions * more hyperlinks --- src/data/sidebar.ts | 7 ++- src/docs/guides/create.md | 4 ++ .../tutorials/github-post-deploy-actions.md | 52 +++++++++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/docs/tutorials/github-post-deploy-actions.md diff --git a/src/data/sidebar.ts b/src/data/sidebar.ts index 1e33b8535..64a2cfe80 100644 --- a/src/data/sidebar.ts +++ b/src/data/sidebar.ts @@ -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"), ], }, ], diff --git a/src/docs/guides/create.md b/src/docs/guides/create.md index 6577ddf96..9d6a4361c 100644 --- a/src/docs/guides/create.md +++ b/src/docs/guides/create.md @@ -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 diff --git a/src/docs/tutorials/github-post-deploy-actions.md b/src/docs/tutorials/github-post-deploy-actions.md new file mode 100644 index 000000000..0644d8467 --- /dev/null +++ b/src/docs/tutorials/github-post-deploy-actions.md @@ -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 == '' +``` +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! \ No newline at end of file