1
0

ci.yml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. name: UNA CI
  2. on:
  3. push:
  4. branches: [ "master" ]
  5. pull_request:
  6. branches: [ "master" ]
  7. types: [opened, synchronize, reopened, closed]
  8. permissions:
  9. contents: read
  10. pull-requests: write
  11. # A newer push to a PR, or closing it, cancels that PR's run in progress, so the teardown can't
  12. # race a preview deploy that is still creating the environment. Master pushes never cancel.
  13. concurrency:
  14. group: ci-${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || github.sha }}
  15. cancel-in-progress: ${{ github.event_name == 'pull_request' }}
  16. jobs:
  17. dependencies:
  18. # Composer (plugins/) and Yarn (plugins_public/, via the postinstall build) are the same
  19. # tree for every PHP version, so they are installed once and the test legs download them.
  20. name: Install dependencies
  21. if: github.event_name == 'push' || github.event.action != 'closed'
  22. runs-on: ubuntu-latest
  23. steps:
  24. - uses: actions/checkout@v4
  25. # WARNING: after `composer update` or `composer upgrade`, replace this commit SHA
  26. # with the current shivammathur/setup-php release. Both Setup PHP steps must match.
  27. - name: Setup PHP
  28. uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
  29. with:
  30. php-version: '8.5'
  31. extensions: intl, curl, gd, mbstring, zip, exif, pdo_mysql
  32. ini-values: short_open_tag=On, memory_limit=256M
  33. tools: composer
  34. - name: Setup Node
  35. uses: actions/setup-node@v4
  36. with:
  37. node-version: '24'
  38. cache: yarn
  39. - name: Install PHP dependencies
  40. run: composer install --prefer-dist --no-progress --no-dev
  41. - name: Install JS dependencies
  42. run: yarn install --frozen-lockfile
  43. - name: Upload dependencies
  44. uses: actions/upload-artifact@v4
  45. with:
  46. name: una-dependencies
  47. retention-days: 1
  48. include-hidden-files: true
  49. if-no-files-found: error
  50. path: |
  51. plugins
  52. plugins_public
  53. test:
  54. # Units and Integration each get a runner per PHP version. Deploy waits on every leg, and a
  55. # failure in one does not cancel the other. The package is built only on the PHP 8.5 Units
  56. # leg so it is uploaded once.
  57. name: ${{ matrix.suite == 'Units' && 'Unit tests' || 'Integration tests' }} (PHP ${{ matrix.php }})
  58. needs: dependencies
  59. if: github.event_name == 'push' || github.event.action != 'closed'
  60. runs-on: ubuntu-latest
  61. strategy:
  62. fail-fast: false
  63. matrix:
  64. suite: [Units, Integration]
  65. php: ['8.3', '8.4', '8.5']
  66. services:
  67. mysql:
  68. image: mariadb:11
  69. env:
  70. MYSQL_ROOT_PASSWORD: root
  71. MYSQL_DATABASE: una
  72. MYSQL_USER: una
  73. MYSQL_PASSWORD: una
  74. ports:
  75. - 3306:3306
  76. options: >-
  77. --health-cmd="healthcheck.sh --connect --innodb_initialized"
  78. --health-interval=10s
  79. --health-timeout=5s
  80. --health-retries=10
  81. steps:
  82. - uses: actions/checkout@v4
  83. # WARNING: after `composer update` or `composer upgrade`, replace this commit SHA
  84. # with the current shivammathur/setup-php release. Both Setup PHP steps must match.
  85. - name: Setup PHP
  86. uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
  87. with:
  88. php-version: ${{ matrix.php }}
  89. extensions: intl, curl, gd, mbstring, zip, exif, pdo_mysql
  90. ini-values: short_open_tag=On, memory_limit=256M
  91. tools: phing, phpunit:12
  92. - name: Download dependencies
  93. uses: actions/download-artifact@v4
  94. with:
  95. name: una-dependencies
  96. - name: Prepare writable paths
  97. run: |
  98. mkdir -p cache cache_public logs tmp storage
  99. chmod a+rwX inc cache cache_public logs tmp storage
  100. test -f plugins/ffmpeg/ffmpeg.exe && chmod 0755 plugins/ffmpeg/ffmpeg.exe
  101. - name: Install UNA
  102. working-directory: install
  103. run: >
  104. php cmd.php
  105. -m bx_antispam
  106. --db_host=127.0.0.1
  107. --db_name=una
  108. --db_user=una
  109. --db_password=una
  110. --server_http_host=localhost
  111. --server_php_self=/install/index.php
  112. - name: Run PHPUnit
  113. run: phpunit -c tests/phpunit.xml --testsuite "${{ matrix.suite }}"
  114. - name: Build package
  115. if: success() && matrix.suite == 'Units' && matrix.php == '8.5'
  116. run: phing package -Dbuild=${{ github.run_number }}
  117. - name: Upload package artifact
  118. if: success() && matrix.suite == 'Units' && matrix.php == '8.5'
  119. uses: actions/upload-artifact@v4
  120. with:
  121. name: una-package
  122. path: packages/*.zip
  123. if-no-files-found: error
  124. preview-env:
  125. # Same-repo PRs only: forks and Dependabot get no secrets, and Dependabot PRs need no preview.
  126. name: Prepare PR environment
  127. if: >-
  128. github.event_name == 'pull_request' && github.event.action != 'closed'
  129. && github.event.pull_request.head.repo.full_name == github.repository
  130. && github.event.pull_request.user.login != 'dependabot[bot]'
  131. runs-on: ubuntu-latest
  132. env:
  133. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  134. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  135. RAILWAY_BASE_ENVIRONMENT: ${{ secrets.RAILWAY_ENVIRONMENT }}
  136. RAILWAY_TEMPLATE_ENVIRONMENT: pr-template
  137. RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
  138. UNA_PREVIEW_API_KEY: ${{ secrets.UNA_PREVIEW_API_KEY }}
  139. steps:
  140. - uses: actions/checkout@v4
  141. with:
  142. sparse-checkout: |
  143. .github/actions
  144. scripts/railway
  145. - uses: ./.github/actions/railway-cli
  146. - name: Provision PR environment
  147. run: |
  148. if [ -z "$RAILWAY_API_TOKEN" ] || [ -z "$RAILWAY_PROJECT_ID" ]; then
  149. echo "Set secrets RAILWAY_API_TOKEN (account token) and RAILWAY_PROJECT_ID" >&2
  150. exit 1
  151. fi
  152. base="${RAILWAY_BASE_ENVIRONMENT:-production}"
  153. template="${RAILWAY_TEMPLATE_ENVIRONMENT:-pr-template}"
  154. railway link --project "$RAILWAY_PROJECT_ID" --environment "$base" --json
  155. # Railway services are project-scoped: mariadb, una and neo already exist, so `railway add`
  156. # cannot create them again and a plain new environment holds no instances of them
  157. # (every preview after the first failed this way). A PR environment therefore gets
  158. # its instances by duplicating the template environment. An environment left over
  159. # from a failed run has no una instance; recreate it.
  160. if ! railway service status --service una --environment "$RAILWAY_PR_ENVIRONMENT" >/dev/null 2>&1; then
  161. railway environment delete "$RAILWAY_PR_ENVIRONMENT" -y >/dev/null 2>&1 || true
  162. railway environment new "$RAILWAY_PR_ENVIRONMENT" --duplicate "$template" --json
  163. # a duplicate may carry the template's deployments; the builds below replace them
  164. railway down --service una --environment "$RAILWAY_PR_ENVIRONMENT" -y >/dev/null 2>&1 || true
  165. railway down --service neo --environment "$RAILWAY_PR_ENVIRONMENT" -y >/dev/null 2>&1 || true
  166. fi
  167. railway link --project "$RAILWAY_PROJECT_ID" --environment "$RAILWAY_PR_ENVIRONMENT" --json
  168. # An environment duplicated before the neo service existed lacks it.
  169. scripts/railway/neo.sh instance "$RAILWAY_PR_ENVIRONMENT"
  170. # The duplicated una instance is what `railway up` deploys into. Setting its variables
  171. # doubles as the readiness check: it fails with "ServiceInstance not found" until it exists.
  172. for i in $(seq 1 12); do
  173. railway variable set --service una --environment "$RAILWAY_PR_ENVIRONMENT" --skip-deploys \
  174. MYSQLHOST=mariadb.railway.internal \
  175. MYSQLPORT=3306 \
  176. MYSQLDATABASE=una \
  177. MYSQLUSER=una \
  178. MYSQLPASSWORD=una \
  179. UNA_DEMO_SEED=1 \
  180. ${UNA_PREVIEW_API_KEY:+UNA_API_KEY="$UNA_PREVIEW_API_KEY"} \
  181. && break
  182. sleep 5
  183. done
  184. # Previews live on their Railway domains (<service>-pr-<n>.up.railway.app), which share
  185. # Railway's wildcard certificate. Custom pr-<n> / api-pr-<n> hosts on unacms.app needed two
  186. # Let's Encrypt certificates per PR, and a busy week ran into Let's Encrypt's rate limit
  187. # (PR #5934 got none). UNA_AUTO_HOSTNAME makes UNA build its URLs from its host.
  188. railway domain --service una --environment "$RAILWAY_PR_ENVIRONMENT" || true
  189. railway domain --service neo --environment "$RAILWAY_PR_ENVIRONMENT" || true
  190. service_host() {
  191. railway domain list --service "$1" --environment "$RAILWAY_PR_ENVIRONMENT" --json | jq -r '.domains[] | select(.type == "service") | .domain' | head -n1
  192. }
  193. una_host=$(service_host una)
  194. neo_host=$(service_host neo)
  195. [ -n "$una_host" ] || { echo "No Railway domain for una" >&2; exit 1; }
  196. [ -n "$neo_host" ] || { echo "No Railway domain for neo" >&2; exit 1; }
  197. una_url="https://${una_host#https://}"
  198. neo_url="https://${neo_host#https://}"
  199. railway variable set --service una --environment "$RAILWAY_PR_ENVIRONMENT" --skip-deploys UNA_CLIENT_URL="$neo_url"
  200. scripts/railway/neo.sh vars "$RAILWAY_PR_ENVIRONMENT" "$una_url" "$neo_url"
  201. deploy:
  202. name: Deploy PR to Railway (una)
  203. needs: [test, preview-env]
  204. runs-on: ubuntu-latest
  205. env:
  206. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  207. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  208. RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
  209. steps:
  210. - uses: actions/checkout@v4
  211. - uses: actions/download-artifact@v4
  212. with:
  213. name: una-package
  214. path: packages
  215. - name: Prepare artefact
  216. run: |
  217. mkdir -p deploy
  218. unzip -q packages/*.zip -d /tmp/una-pkg
  219. pkg_dir=$(find /tmp/una-pkg -mindepth 1 -maxdepth 1 -type d | head -n 1)
  220. cp -a "$pkg_dir"/. deploy/
  221. cp scripts/railway/Dockerfile scripts/railway/entrypoint.sh scripts/railway/railway.toml scripts/railway/.railwayignore \
  222. scripts/railway/configure.php scripts/railway/seed.php deploy/
  223. chmod +x deploy/entrypoint.sh
  224. - uses: ./.github/actions/railway-cli
  225. - name: Deploy artefact
  226. run: railway up ./deploy --path-as-root --no-gitignore --verbose --ci --service una --environment "$RAILWAY_PR_ENVIRONMENT" --project "$RAILWAY_PROJECT_ID"
  227. deploy-neo:
  228. # NEO isn't covered by `test`, so it builds alongside it.
  229. name: Deploy PR to Railway (neo)
  230. needs: preview-env
  231. runs-on: ubuntu-latest
  232. env:
  233. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  234. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  235. RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
  236. steps:
  237. - uses: actions/checkout@v4
  238. - uses: ./.github/actions/railway-cli
  239. - name: Deploy NEO
  240. run: |
  241. scripts/railway/neo.sh stage /tmp/deploy-neo
  242. railway up /tmp/deploy-neo --path-as-root --no-gitignore --verbose --ci --service neo --environment "$RAILWAY_PR_ENVIRONMENT" --project "$RAILWAY_PROJECT_ID"
  243. preview-comment:
  244. name: Comment preview URLs
  245. needs: [preview-env, deploy, deploy-neo]
  246. if: always() && needs.preview-env.result == 'success'
  247. runs-on: ubuntu-latest
  248. env:
  249. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  250. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  251. RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
  252. UNA_RESULT: ${{ needs.deploy.result }}
  253. NEO_RESULT: ${{ needs.deploy-neo.result }}
  254. GH_TOKEN: ${{ github.token }}
  255. PR_NUMBER: ${{ github.event.pull_request.number }}
  256. steps:
  257. - uses: actions/checkout@v4
  258. with:
  259. sparse-checkout: .github/actions
  260. - uses: ./.github/actions/railway-cli
  261. - name: Comment preview URLs on PR
  262. run: |
  263. railway link --project "$RAILWAY_PROJECT_ID" --environment "$RAILWAY_PR_ENVIRONMENT" --json >/dev/null
  264. service_url() {
  265. local host
  266. host=$(railway domain list --service "$1" --environment "$RAILWAY_PR_ENVIRONMENT" --json | jq -r '.domains[] | select(.type == "service") | .domain' | head -n1)
  267. [ -n "$host" ] && echo "https://${host#https://}"
  268. }
  269. una_url=$(service_url una || true)
  270. neo_url=$(service_url neo || true)
  271. state() { [ "$1" = success ] && echo "" || echo " (deploy: $1)"; }
  272. marker="<!-- railway-preview -->"
  273. body=$(printf '%s\n**Preview**: %s (NEO web client%s)\n**API**: %s (UNA%s)\n\nRailway environment: `%s`. A fresh UNA install takes about 10 minutes.' \
  274. "$marker" "$neo_url" "$(state "$NEO_RESULT")" "$una_url" "$(state "$UNA_RESULT")" "$RAILWAY_PR_ENVIRONMENT")
  275. comment_id=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate \
  276. --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | contains(\"${marker}\"))) | .id" \
  277. | head -n1)
  278. if [ -n "$comment_id" ]; then
  279. gh api --method PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${comment_id}" -f body="$body"
  280. else
  281. gh pr comment "$PR_NUMBER" --body "$body"
  282. fi
  283. deploy-production:
  284. # Runs next to the Jenkins deploy to ci.una.io, which is unchanged.
  285. name: Deploy master to Railway (api.unacms.app)
  286. needs: test
  287. if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  288. runs-on: ubuntu-latest
  289. concurrency:
  290. group: railway-production
  291. cancel-in-progress: false
  292. environment:
  293. name: production
  294. url: https://api.unacms.app
  295. env:
  296. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  297. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  298. RAILWAY_ENVIRONMENT: production
  299. VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
  300. VERCEL_TEAM: yasko
  301. UNA_API_KEY: ${{ secrets.UNA_API_KEY }}
  302. steps:
  303. - uses: actions/checkout@v4
  304. - uses: actions/download-artifact@v4
  305. with:
  306. name: una-package
  307. path: packages
  308. - name: Prepare artefact
  309. run: |
  310. mkdir -p deploy
  311. unzip -q packages/*.zip -d /tmp/una-pkg
  312. pkg_dir=$(find /tmp/una-pkg -mindepth 1 -maxdepth 1 -type d | head -n 1)
  313. cp -a "$pkg_dir"/. deploy/
  314. cp scripts/railway/Dockerfile scripts/railway/entrypoint.sh scripts/railway/railway.toml scripts/railway/.railwayignore \
  315. scripts/railway/configure.php scripts/railway/seed.php deploy/
  316. chmod +x deploy/entrypoint.sh
  317. - uses: ./.github/actions/railway-cli
  318. - name: Configure production
  319. run: |
  320. if [ -z "$RAILWAY_API_TOKEN" ] || [ -z "$RAILWAY_PROJECT_ID" ]; then
  321. echo "Set secrets RAILWAY_API_TOKEN (account token) and RAILWAY_PROJECT_ID" >&2
  322. exit 1
  323. fi
  324. railway link --project "$RAILWAY_PROJECT_ID" --environment "$RAILWAY_ENVIRONMENT" --json
  325. # Database credentials and UNA_HASH_SECRET live in the Railway environment, not here.
  326. railway variable set --service una --environment "$RAILWAY_ENVIRONMENT" --skip-deploys \
  327. UNA_CLIENT_URL=https://unacms.app \
  328. ${UNA_API_KEY:+UNA_API_KEY="$UNA_API_KEY"}
  329. - name: Deploy artefact
  330. run: railway up ./deploy --path-as-root --no-gitignore --verbose --ci --service una --environment "$RAILWAY_ENVIRONMENT" --project "$RAILWAY_PROJECT_ID"
  331. - name: api.unacms.app DNS
  332. if: env.VERCEL_TOKEN != ''
  333. run: scripts/railway/domains.sh railway-domain api.unacms.app "$RAILWAY_ENVIRONMENT" una
  334. - name: Smoke test
  335. # A fresh production install takes about 4 minutes; allow 10.
  336. run: |
  337. for i in $(seq 1 60); do
  338. code=$(curl -s -o /dev/null -w '%{http_code}' https://api.unacms.app/ || true)
  339. [ "$code" = "200" ] && { echo "api.unacms.app is up"; exit 0; }
  340. # Until the certificate is issued, check the Railway hostname instead.
  341. host=$(railway domain list --service una --environment "$RAILWAY_ENVIRONMENT" --json | jq -r '.domains[] | select(.type == "service") | .domain' | head -n1)
  342. if [ -n "$host" ] && [ "$(curl -s -o /dev/null -w '%{http_code}' "https://${host#https://}/" || true)" = "200" ]; then
  343. echo "up at https://$host (api.unacms.app answered $code; certificate may still be pending)"
  344. exit 0
  345. fi
  346. sleep 10
  347. done
  348. echo "UNA did not come up" >&2
  349. exit 1
  350. deploy-production-neo:
  351. # The NEO web client for unacms.app. NEO_PRODUCTION_HOST (a repository variable) is the
  352. # public host; until it is set, the client is only on its Railway domain.
  353. name: Deploy master to Railway (neo)
  354. if: github.event_name == 'push' && github.ref == 'refs/heads/master'
  355. runs-on: ubuntu-latest
  356. concurrency:
  357. group: railway-production-neo
  358. cancel-in-progress: false
  359. environment:
  360. name: production-neo
  361. url: ${{ steps.urls.outputs.app_url }}
  362. env:
  363. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  364. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  365. RAILWAY_ENVIRONMENT: production
  366. VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
  367. VERCEL_TEAM: yasko
  368. NEO_PRODUCTION_HOST: ${{ vars.NEO_PRODUCTION_HOST }}
  369. steps:
  370. - uses: actions/checkout@v4
  371. - uses: ./.github/actions/railway-cli
  372. - name: Configure neo
  373. id: urls
  374. run: |
  375. railway link --project "$RAILWAY_PROJECT_ID" --environment "$RAILWAY_ENVIRONMENT" --json
  376. railway domain --service neo --environment "$RAILWAY_ENVIRONMENT" || true
  377. neo_host=$(railway domain list --service neo --environment "$RAILWAY_ENVIRONMENT" --json | jq -r '.domains[] | select(.type == "service") | .domain' | head -n1)
  378. neo_host=${neo_host#https://}
  379. [ -n "$neo_host" ] || { echo "No Railway domain for neo" >&2; exit 1; }
  380. app_url="https://${NEO_PRODUCTION_HOST:-$neo_host}"
  381. scripts/railway/neo.sh vars "$RAILWAY_ENVIRONMENT" https://api.unacms.app "$app_url"
  382. echo "app_url=$app_url" >> "$GITHUB_OUTPUT"
  383. echo "neo_url=https://$neo_host" >> "$GITHUB_OUTPUT"
  384. - name: Deploy NEO
  385. run: |
  386. scripts/railway/neo.sh stage /tmp/deploy-neo
  387. railway up /tmp/deploy-neo --path-as-root --no-gitignore --verbose --ci --service neo --environment "$RAILWAY_ENVIRONMENT" --project "$RAILWAY_PROJECT_ID"
  388. - name: Production host DNS
  389. if: env.NEO_PRODUCTION_HOST != '' && env.VERCEL_TOKEN != ''
  390. run: scripts/railway/domains.sh railway-domain "$NEO_PRODUCTION_HOST" "$RAILWAY_ENVIRONMENT" neo
  391. - name: Smoke test
  392. env:
  393. NEO_URL: ${{ steps.urls.outputs.neo_url }}
  394. run: |
  395. for i in $(seq 1 30); do
  396. code=$(curl -s -o /dev/null -w '%{http_code}' "$NEO_URL/" || true)
  397. [ "$code" = "200" ] && { echo "NEO is up at $NEO_URL"; exit 0; }
  398. sleep 10
  399. done
  400. echo "NEO did not answer 200 at $NEO_URL (last: $code)" >&2
  401. exit 1
  402. teardown:
  403. name: Remove PR Railway environment
  404. if: >-
  405. github.event_name == 'pull_request' && github.event.action == 'closed'
  406. && github.event.pull_request.head.repo.full_name == github.repository
  407. && github.event.pull_request.user.login != 'dependabot[bot]'
  408. runs-on: ubuntu-latest
  409. env:
  410. RAILWAY_API_TOKEN: ${{ secrets.RAILWAY_API_TOKEN }}
  411. RAILWAY_PROJECT_ID: ${{ secrets.RAILWAY_PROJECT_ID }}
  412. RAILWAY_BASE_ENVIRONMENT: ${{ secrets.RAILWAY_ENVIRONMENT }}
  413. RAILWAY_PR_ENVIRONMENT: pr-${{ github.event.pull_request.number }}
  414. VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
  415. VERCEL_TEAM: yasko
  416. PREVIEW_API_HOST: api-pr-${{ github.event.pull_request.number }}.unacms.app
  417. PREVIEW_CLIENT_HOST: pr-${{ github.event.pull_request.number }}.unacms.app
  418. steps:
  419. - uses: actions/checkout@v4
  420. with:
  421. sparse-checkout: |
  422. .github/actions
  423. scripts/railway
  424. # Previews created before they moved to Railway domains (2026-10-20) still have DNS records
  425. # on unacms.app; this step can go once those PRs are closed.
  426. - name: Remove preview domains
  427. if: env.VERCEL_TOKEN != ''
  428. continue-on-error: true
  429. run: |
  430. scripts/railway/domains.sh client-unalias "$PREVIEW_CLIENT_HOST"
  431. scripts/railway/domains.sh dns-remove "$PREVIEW_CLIENT_HOST"
  432. scripts/railway/domains.sh dns-remove "$PREVIEW_API_HOST"
  433. - uses: ./.github/actions/railway-cli
  434. - name: Delete PR environment
  435. run: |
  436. if [ -z "$RAILWAY_API_TOKEN" ] || [ -z "$RAILWAY_PROJECT_ID" ]; then
  437. echo "Set secrets RAILWAY_API_TOKEN (account token) and RAILWAY_PROJECT_ID" >&2
  438. exit 1
  439. fi
  440. base="${RAILWAY_BASE_ENVIRONMENT:-production}"
  441. railway link --project "$RAILWAY_PROJECT_ID" --environment "$base" --json
  442. # The run for the PR's last push is cancelled above (workflow concurrency), so nothing
  443. # can create the environment after this. A PR closed before its first deploy has none.
  444. if railway environment delete "$RAILWAY_PR_ENVIRONMENT" -y; then
  445. echo "Deleted $RAILWAY_PR_ENVIRONMENT"
  446. else
  447. echo "No environment $RAILWAY_PR_ENVIRONMENT to delete"
  448. fi