-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Adds testing Railway deployment to CI #3157
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
c83fa1b
22dd692
ad40c39
b8545ee
8a4dd36
249b2fb
7da3c83
800a361
db6c079
80c3596
4b1f099
5a8343c
b21a236
648848a
d2bb57a
389ebce
9f0aba4
b1532c8
5d2df2d
b2d5c5d
a18dee1
9fb7499
3454f9d
7cdef81
af5ac9e
cd71c8d
53c40a7
d88cd0f
e8e9931
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ on: | |
- ".github/**" | ||
branches: | ||
- main | ||
# TODO: remove before merging this PR | ||
- miho-railway-deployment-test-ci | ||
tags: | ||
- v* | ||
workflow_dispatch: | ||
|
@@ -15,11 +17,12 @@ env: | |
APP_PREFIX: ci-${{ github.sha }} | ||
FLY_API_TOKEN: ${{ secrets.FLY_GITHUB_TESTING_TOKEN }} | ||
FLY_REGION: mia | ||
RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_GITHUB_TESTING_TOKEN }} | ||
APP_TO_DEPLOY: waspc/examples/todoApp | ||
|
||
jobs: | ||
fly_deploy_app: | ||
name: Deploy Wasp app | ||
name: Deploy Wasp app to Fly.io | ||
|
||
runs-on: ubuntu-latest | ||
|
||
|
@@ -79,7 +82,7 @@ jobs: | |
server_hostname: ${{ steps.save_hostnames.outputs.server_hostname }} | ||
client_hostname: ${{ steps.save_hostnames.outputs.client_hostname }} | ||
|
||
smoke_test_app: | ||
fly_smoke_test_app: | ||
name: Run smoke tests on deployed app | ||
|
||
runs-on: ubuntu-latest | ||
|
@@ -100,7 +103,7 @@ jobs: | |
fly_destroy_app: | ||
runs-on: ubuntu-latest | ||
name: Clean up deployed Fly app | ||
needs: [fly_deploy_app, smoke_test_app] | ||
needs: [fly_deploy_app, fly_smoke_test_app] | ||
# NOTE: Fly deployments can sometimes "fail" but still deploy the apps. We | ||
# want to always clean them up. | ||
if: always() | ||
|
@@ -119,3 +122,104 @@ jobs: | |
flyctl apps destroy -y $APP_PREFIX-server || true | ||
flyctl apps destroy -y $APP_PREFIX-client || true | ||
flyctl apps destroy -y $APP_PREFIX-db || true | ||
|
||
railway_deploy_app: | ||
name: Deploy Wasp app to Railway | ||
|
||
runs-on: ubuntu-latest | ||
|
||
environment: | ||
name: railway-deploy-test | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: ./.github/actions/setup-haskell | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
cache: "npm" | ||
node-version: "22" | ||
|
||
- name: Install Wasp CLI | ||
working-directory: waspc | ||
run: ./run install | ||
|
||
- name: Install Railway CLI | ||
run: | | ||
npm install -g @railway/cli | ||
|
||
- name: Deploy App to Railway | ||
working-directory: ${{ env.APP_TO_DEPLOY }} | ||
run: | | ||
set -e | ||
|
||
# NOTE: This assumes env var values don't contain: | ||
# - The character `#`. | ||
# - An empty line (i.e., there are no multiline env values). | ||
mapfile -t ENV_VAR_ARGUMENTS < <( | ||
cat .env.server.example | | ||
sed -E 's/#.*//' | | ||
awk 'NF {$1=$1;print}' | | ||
sed -E 's/^/--server-secret\n/' | ||
) | ||
|
||
echo "Deploying with prefix: $APP_PREFIX" | ||
# NOTE: | ||
# - We use a Bash array for `$ENV_VAR_ARGUMENTS` to ensure proper | ||
# word splitting (i.e., force Bash to interpret the flags separately | ||
# instead of passing it as a single string value). | ||
echo $RAILWAY_API_TOKEN | ||
RAILWAY_API_TOKEN=$RAILWAY_API_TOKEN wasp-cli deploy railway launch "$APP_PREFIX" --workspace wasp "${ENV_VAR_ARGUMENTS[@]}" | ||
|
||
- name: Save deployed app hostnames | ||
id: save_hostnames | ||
working-directory: ${{ env.APP_TO_DEPLOY }} | ||
run: | | ||
server_service_name="${APP_PREFIX}-server" | ||
client_service_name="${APP_PREFIX}-client" | ||
|
||
echo "server_hostname=$(railway status --json | jq -r --arg NAME "$server_service_name" '.services.edges[] | select(.node.name == $NAME) | .node.serviceInstances.edges[0].node.domains.serviceDomains[0].domain')" >> "$GITHUB_OUTPUT" | ||
echo "client_hostname=$(railway status --json | jq -r --arg NAME "$client_service_name" '.services.edges[] | select(.node.name == $NAME) | .node.serviceInstances.edges[0].node.domains.serviceDomains[0].domain')" >> "$GITHUB_OUTPUT" | ||
outputs: | ||
server_hostname: ${{ steps.save_hostnames.outputs.server_hostname }} | ||
client_hostname: ${{ steps.save_hostnames.outputs.client_hostname }} | ||
|
||
railway_smoke_test_app: | ||
|
||
name: Run smoke tests on deployed app | ||
|
||
runs-on: ubuntu-latest | ||
needs: railway_deploy_app | ||
env: | ||
SERVER_HOSTNAME: ${{ needs.railway_deploy_app.outputs.server_hostname }} | ||
CLIENT_HOSTNAME: ${{ needs.railway_deploy_app.outputs.client_hostname }} | ||
|
||
steps: | ||
- name: Smoke test the server | ||
run: | | ||
curl --fail --silent -X POST https://$SERVER_HOSTNAME/operations/get-date | jq '.json' | ||
|
||
- name: Smoke test the client | ||
run: | | ||
curl --fail --silent https://$CLIENT_HOSTNAME | grep 'ToDo App' | ||
|
||
railway_destroy_app: | ||
runs-on: ubuntu-latest | ||
name: Clean up deployed Railway app | ||
needs: [railway_deploy_app, railway_smoke_test_app] | ||
# NOTE: Fly deployments can sometimes "fail" but still deploy the apps. We | ||
# want to always clean them up. | ||
if: always() | ||
|
||
steps: | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: "22" | ||
|
||
- name: Install Railway CLI | ||
run: | | ||
npm install -g @railway/cli | ||
|
||
- name: Clean up testing app from Railway | ||
run: | | ||
echo "Not implemented yet, manually delete the project in Railway dashboard" |
Uh oh!
There was an error while loading. Please reload this page.