name: Deploy to Railway on: push: branches: - master workflow_dispatch: permissions: contents: read packages: write env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} jobs: build-and-deploy: name: Build and Deploy runs-on: ubuntu-latest outputs: digest: ${{ steps.docker_build.outputs.digest }} steps: - name: Checkout uses: actions/checkout@v6 - name: Read emsdk version from package.json id: versions run: | EMSDK_VERSION=$(jq -r '.config.emsdkVersion' package.json) if [ -z "$EMSDK_VERSION" ] || [ "$EMSDK_VERSION" = "null" ]; then echo "::error::emsdkVersion not found in package.json config" exit 1 fi echo "emsdk=$EMSDK_VERSION" >> $GITHUB_OUTPUT # ========== Docker Build and Push ========== # Note: WASM and frontend are built inside Docker using multi-stage build - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - name: Log in to GitHub Container Registry uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata for Docker id: meta uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=ref,event=branch type=sha,prefix={{branch}}- type=raw,value=latest,enable={{is_default_branch}} - name: Build and push Docker image id: docker_build uses: docker/build-push-action@v6 with: context: . file: ./pacman-server/Dockerfile push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha,mode=max build-args: | GIT_COMMIT_SHA=${{ github.sha }} EMSDK_VERSION=${{ steps.versions.outputs.emsdk }} # Wait for ghcr.io propagation (paranoid safety) - name: Wait for registry propagation run: sleep 5 # Deploy to Railway - separate job to use container properly deploy: name: Deploy to Railway runs-on: ubuntu-latest needs: build-and-deploy container: ghcr.io/railwayapp/cli:latest env: RAILWAY_TOKEN: ${{ secrets.RAILWAY_TOKEN }} steps: - name: Check Railway Token run: | if [ -z "$RAILWAY_TOKEN" ]; then echo "::warning::RAILWAY_TOKEN not available - deployment skipped (common for Dependabot PRs)" exit 0 fi - name: Generate proxy Dockerfile if: env.RAILWAY_TOKEN != '' run: echo "FROM ghcr.io/xevion/pac-man@${{ needs.build-and-deploy.outputs.digest }}" > Dockerfile - name: Deploy to Railway if: env.RAILWAY_TOKEN != '' run: railway up --service pac-man