name: Deploy To Ghaymah

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Create .ghaymah.json
        run: |
          cat > .ghaymah.json << 'EOF'
          {
            "id": "da97e2b8-0b2c-49d8-a672-1d162c8e15f1",
            "name": "oudelaa-api",
            "projectId": "1137d5bd-c997-4654-9d01-3c7a88b07269",
            "ports": [
              {
                "expose": true,
                "number": 4000
              }
            ],
            "publicAccess": {
              "enabled": true
            },
            "resourceTier": "g1.nano",
            "dockerFileName": "Dockerfile"
          }
          EOF

          cat .ghaymah.json

      - name: Install Ghaymah CLI
        run: curl -sSl https://cli.ghaymah.systems/install.sh | bash

      - name: Login to Ghaymah
        run: |
          $HOME/ghaymah/bin/gy auth login \
            --email "${{ secrets.GHAYMAH_EMAIL }}" \
            --password "${{ secrets.GHAYMAH_PW }}" \
            --no-auto-update

      - name: Deploy
        run: $HOME/ghaymah/bin/gy resource app launch --no-auto-update