11name : " Test - Wasp Deploy"
22
33on :
4+ push :
5+ # TODO: remove before merging this PR
6+ branches :
7+ - miho-railway-deployment-test-ci
48 workflow_call :
59 secrets :
610 FLY_GITHUB_TESTING_TOKEN :
@@ -10,114 +14,138 @@ on:
1014
1115env :
1216 WASP_TELEMETRY_DISABLE : 1
13-
14- APP_PREFIX : ci-${{ github.sha }}
17+ # - We use run_id because it's shorter than commit SHA since
18+ # the max length for project name in Railway is 25 characters.
19+ # - We append run_attempt to avoid name collisions on job retries,
20+ # becuase run_id is the same across retries.
21+ APP_PREFIX : ci-${{ github.run_id }}-${{ github.run_attempt }}
22+ APP_TO_DEPLOY : examples/kitchen-sink
1523 FLY_API_TOKEN : ${{ secrets.FLY_GITHUB_TESTING_TOKEN }}
1624 FLY_REGION : dfw
17- APP_TO_DEPLOY : examples/kitchen-sink
25+ FLY_ORG : wasp-testing
26+ RAILWAY_API_TOKEN : ${{ secrets.RAILWAY_GITHUB_TESTING_TOKEN }}
27+ RAILWAY_WASP_WORKSPACE_ID : ${{ secrets.RAILWAY_WASP_WORKSPACE_ID }}
1828
1929jobs :
20- fly_deploy_app :
21- name : Deploy Wasp app
22-
30+ test_fly_deployment :
31+ name : Test Fly deployment
2332 runs-on : ubuntu-latest
24-
2533 environment :
2634 name : fly-deploy-test
2735
2836 steps :
2937 - uses : actions/checkout@v6
3038
31- - uses : ./.github/actions/setup-haskell
32-
33- - uses : actions/setup-node@v6
34- with :
35- cache : " npm"
36- node-version : " 22"
37-
38- - name : Install Wasp CLI
39- working-directory : waspc
40- run : ./run install
39+ - uses : ./.github/actions/prepare-deploy-test
4140
41+ - name : Install Fly CLI
4242 # NOTE: We tell users to install the latest version of Fly CLI,
4343 # so we use it here too.
44- - uses : superfly/flyctl-actions/setup-flyctl@v1
44+ uses : superfly/flyctl-actions/setup-flyctl@v1
4545
46- - name : Deploy App to Fly.io
46+ - name : Deploy app to Fly
4747 working-directory : ${{ env.APP_TO_DEPLOY }}
4848 run : |
49- set -e
50-
5149 # `fly launch` fails if Fly toml files already exist.
52- rm -f fly-server.toml fly-client.toml
53-
54- # NOTE: This assumes env var values don't contain:
55- # - The character `#`.
56- # - An empty line (i.e., there are no multiline env values).
57- mapfile -t ENV_VAR_ARGUMENTS < <(
58- cat .env.server.example |
59- sed -E 's/#.*//' |
60- awk 'NF {$1=$1;print}' |
61- sed -E 's/^/--server-secret\n/'
62- )
50+ rm -f fly-server.toml fly-client.toml
6351
6452 echo "Deploying with prefix: $APP_PREFIX"
53+ mapfile -d $'\0' -t ENV_VAR_ARGUMENTS < <(node ../../scripts/deploy-test/prepare-deploy-secrets.mjs .env.server.example)
6554 # NOTE:
6655 # - The `yes` command is necessary because the `fly launch` command
6756 # prompts for confirmation.
6857 # - We use a Bash array for `$ENV_VAR_ARGUMENTS` to ensure proper
6958 # word splitting (i.e., force Bash to interpret the flags separately
7059 # instead of passing it as a single string value).
71- yes | wasp-cli deploy fly launch "$APP_PREFIX" "$FLY_REGION" --org wasp-testing "${ENV_VAR_ARGUMENTS[@]}"
60+ yes | wasp-cli deploy fly launch "$APP_PREFIX" "$FLY_REGION" --org "$FLY_ORG" "${ENV_VAR_ARGUMENTS[@]}"
7261
73- - name : Save deployed app hostnames
74- id : save_hostnames
62+ - name : Smoke test deployed app
7563 working-directory : ${{ env.APP_TO_DEPLOY }}
7664 run : |
77- echo "server_hostname=$(flyctl status -j -c fly-server.toml | jq -r '.Hostname')" >> "$GITHUB_OUTPUT"
78- echo "client_hostname=$(flyctl status -j -c fly-client.toml | jq -r '.Hostname')" >> "$GITHUB_OUTPUT"
79-
80- outputs :
81- server_hostname : ${{ steps.save_hostnames.outputs.server_hostname }}
82- client_hostname : ${{ steps.save_hostnames.outputs.client_hostname }}
83-
84- smoke_test_app :
85- name : Run smoke tests on deployed app
86-
87- runs-on : ubuntu-latest
88- needs : fly_deploy_app
89- env :
90- SERVER_HOSTNAME : ${{ needs.fly_deploy_app.outputs.server_hostname }}
91- CLIENT_HOSTNAME : ${{ needs.fly_deploy_app.outputs.client_hostname }}
92-
93- steps :
94- - name : Smoke test the server
95- run : |
96- curl --fail --silent -X POST https://$SERVER_HOSTNAME/operations/get-date | jq '.json'
97-
98- - name : Smoke test the client
99- run : |
100- curl --fail --silent https://$CLIENT_HOSTNAME | grep 'Wasp Kitchen Sink'
101-
102- fly_destroy_app :
65+ # Get deployed app hostnames
66+ function get_fly_app_hostname() {
67+ config_file="$1"
68+ flyctl status -j -c "$config_file" | jq -r '.Hostname'
69+ }
70+ SERVER_HOSTNAME=$(get_fly_app_hostname fly-server.toml)
71+ CLIENT_HOSTNAME=$(get_fly_app_hostname fly-client.toml)
72+
73+ # Run smoke test
74+ ../../scripts/deploy-test/smoke-test-deployed-test-app.sh "https://$SERVER_HOSTNAME" "https://$CLIENT_HOSTNAME"
75+
76+ cleanup_fly_deploy_test :
77+ name : Clean up Fly deployment test apps
10378 runs-on : ubuntu-latest
104- name : Clean up deployed Fly app
105- needs : [fly_deploy_app, smoke_test_app]
79+ needs : test_fly_deployment
10680 # NOTE: Fly deployments can sometimes "fail" but still deploy the apps. We
10781 # want to always clean them up.
10882 if : always()
10983
11084 steps :
11185 - uses : superfly/flyctl-actions/setup-flyctl@v1
11286 with :
113- # NOTE: We pinned the Fly because we don't want the changes in the
87+ # NOTE: We pinned the Fly version because we don't want the changes in the
11488 # Fly CLI to affect our cleanup procedure. `fly destroy` isn't a part
11589 # of Wasp, we're just incidentally using the same tool Wasp uses.
11690 version : v0.3.164
11791
118- - name : Clean up testing app from Fly.io
92+ - name : Clean up test apps
11993 run : |
12094 # NOTE: We are relying on Wasp's naming conventions here
12195 flyctl apps destroy -y $APP_PREFIX-server || true
12296 flyctl apps destroy -y $APP_PREFIX-client || true
12397 flyctl apps destroy -y $APP_PREFIX-db || true
98+
99+ test_railway_deployment :
100+ name : Test Railway deployment
101+ runs-on : ubuntu-latest
102+ environment :
103+ name : railway-deploy-test
104+
105+ steps :
106+ - uses : actions/checkout@v5
107+
108+ - uses : ./.github/actions/prepare-deploy-test
109+
110+ - name : Install Railway CLI
111+ run : npm install -g @railway/cli@4.11.1
112+
113+ - name : Deploy app to Railway
114+ working-directory : ${{ env.APP_TO_DEPLOY }}
115+ run : |
116+ echo "Deploying with prefix: $APP_PREFIX"
117+ mapfile -d $'\0' -t ENV_VAR_ARGUMENTS < <(node ../../scripts/deploy-test/prepare-deploy-secrets.mjs .env.server.example)
118+ # NOTE:
119+ # - We use a Bash array for `$ENV_VAR_ARGUMENTS` to ensure proper
120+ # word splitting (i.e., force Bash to interpret the flags separately
121+ # instead of passing it as a single string value).
122+ wasp-cli deploy railway launch "$APP_PREFIX" --workspace $RAILWAY_WASP_WORKSPACE_ID "${ENV_VAR_ARGUMENTS[@]}"
123+
124+ - name : Smoke test deployed app
125+ working-directory : ${{ env.APP_TO_DEPLOY }}
126+ run : |
127+ # Get deployed app hostnames
128+ function get_railway_service_hostname() {
129+ service_name="$1"
130+ railway status --json | jq -r --arg NAME "$service_name" '.services.edges[] | select(.node.name == $NAME) | .node.serviceInstances.edges[0].node.domains.serviceDomains[0].domain'
131+ }
132+ server_service_name="${APP_PREFIX}-server"
133+ client_service_name="${APP_PREFIX}-client"
134+ SERVER_HOSTNAME=$(get_railway_service_hostname "$server_service_name")
135+ CLIENT_HOSTNAME=$(get_railway_service_hostname "$client_service_name")
136+
137+ # Run smoke test
138+ ../../scripts/deploy-test/smoke-test-deployed-test-app.sh "https://$SERVER_HOSTNAME" "https://$CLIENT_HOSTNAME"
139+
140+ cleanup_railway_deploy_test :
141+ name : Clean up Railway deployment project
142+ runs-on : ubuntu-latest
143+ needs : test_railway_deployment
144+ # NOTE: Railway deployments can sometimes "fail" but still deploy the apps. We
145+ # want to always clean them up.
146+ if : always()
147+ steps :
148+ - uses : actions/checkout@v5
149+
150+ - name : Clean up test project
151+ run : node ./scripts/deploy-test/cleanup-railway-project.mjs "$APP_PREFIX"
0 commit comments