Skip to content

fix(case-studies): map _caseStudy field to first title (#234) #266

fix(case-studies): map _caseStudy field to first title (#234)

fix(case-studies): map _caseStudy field to first title (#234) #266

name: Deploy to Railway
permissions:
contents: read
on:
push:
branches:
- main
- staging
- 'release/pr-v*'
workflow_dispatch:
inputs:
deploy-env:
description: 'Environment to deploy'
required: true
type: choice
options:
- Development
- Staging
- Production
default: Development
restore-db:
description: 'Restore database to original state (Reset database for Development and restore anon dump for Staging and Production)'
required: false
type: boolean
default: false
create-admin:
description: 'Create first admin user'
required: false
type: boolean
default: false
jobs:
deploy-to-railway:
name: Deploy to Railway
runs-on: ubuntu-latest
environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || (startsWith(github.ref_name, 'release/pr-v') && 'Production') || (github.ref_name == 'staging' && 'Staging') || 'None' }}
env:
RAILWAY_TOKEN: ${{ secrets.RAILWAY_GITHUB_ACTIONS }}
steps:
- name: Print environment
run: |
echo "Environment: ${{ vars.ENV_NAME }} from ${{ github.ref_name }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Install Railway CLI
run: npm i -g @railway/cli
- name: Apply new image to Railway
run: railway up --service=apostrophe-cms
restore-db:
name: Restore DB
needs: deploy-to-railway
environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || (startsWith(github.ref_name, 'release/pr-v') && 'Production') || (github.ref_name == 'staging' && 'Staging') || 'None' }}
runs-on: ubuntu-latest
if: ${{ inputs.restore-db == true }}
env:
MONGO_URI: ${{ secrets.MONGO_URI }}
DB_NAME: ${{ vars.DB_NAME }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Drop DB
run: ./scripts/drop_collections.sh
- name: Update DB
run: ./scripts/import_mongodb.sh ./export
shell: bash
create-admin:
name: Create Admin User
needs: restore-db
if: ${{ inputs.create-admin == true }}
runs-on: ubuntu-latest
environment: ${{ inputs.deploy-env || (github.ref_name == 'main' && 'Development') || (startsWith(github.ref_name, 'release/pr-v') && 'Production') || (github.ref_name == 'staging' && 'Staging') || 'None' }}
env:
APOS_MONGODB_URI: ${{ secrets.MONGO_URI }}
ADMIN_PASSWORD: ${{ secrets.ADMIN_PASSWORD }}
DB_NAME: ${{ vars.DB_NAME }}
NODE_ENV: ${{ inputs.deploy-env == 'Production' && 'production' || inputs.deploy-env == 'Staging' && 'staging' || 'development' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Start services with Docker Compose
run: |
docker compose up -d mongodb
sleep 5 # Wait for MongoDB to start
- name: Create admin user
run: |
docker compose run --rm \
-e APOS_MONGODB_URI="$APOS_MONGODB_URI" \
apostrophe \
/bin/sh -c "echo \"$ADMIN_PASSWORD\" | node app.js @apostrophecms/user:add admin admin"