Deploy #103
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - "**.rs" | |
| - "**.vue" | |
| - "**.ts" | |
| - ".github/workflows/deploy.yaml" | |
| - "**Dockerfile" | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:16 | |
| ports: | |
| - 5432:5432 | |
| env: | |
| POSTGRES_USER: postgres | |
| POSTGRES_PASSWORD: postgres | |
| POSTGRES_DB: app | |
| options: >- | |
| --health-cmd="pg_isready -U postgres" | |
| --health-interval=5s | |
| --health-timeout=5s | |
| --health-retries=5 | |
| permissions: | |
| contents: read | |
| id-token: write | |
| packages: write | |
| env: | |
| DATABASE_URL: postgres://postgres:postgres@localhost:5432/app | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Wait for Postgres | |
| run: | | |
| for i in {1..10}; do | |
| pg_isready -h localhost -p 5432 -U postgres && exit 0 | |
| sleep 1 | |
| done | |
| exit 1 | |
| - name: Write .env for sqlx compile-time macros | |
| run: | | |
| echo "DATABASE_URL=${DATABASE_URL}" > src-api/.env | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v2 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Restore build cache | |
| uses: actions/cache/restore@v4 | |
| id: build-cache | |
| with: | |
| path: | | |
| src-api/target | |
| src-crypto/target | |
| src-macro/target | |
| ~/.cargo/bin | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| node_modules | |
| key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }} | |
| ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json') }} | |
| ${{ runner.os }}-build- | |
| - name: Set up Rust | |
| if: steps.build-cache.outputs.cache-hit != 'true' | |
| uses: dtolnay/rust-toolchain@master | |
| with: | |
| toolchain: nightly-2025-11-15 | |
| targets: wasm32-unknown-unknown | |
| components: rustfmt | |
| - name: Install wasm-pack | |
| uses: jetli/wasm-pack-action@v0.4.0 | |
| - name: Install Bun | |
| uses: oven-sh/setup-bun@v2 | |
| - name: Check if sqlx CLI is cached | |
| id: checkfile | |
| run: | | |
| if [ -f "$HOME/.cargo/bin/sqlx" ]; then echo "exists=true" >> $GITHUB_OUTPUT | |
| else echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Install sqlx CLI | |
| if: steps.checkfile.outputs.exists == 'false' | |
| run: cargo install sqlx-cli --no-default-features --features postgres | |
| - name: Run database migrations | |
| working-directory: src-api | |
| run: sqlx migrate run | |
| - name: Install dependencies | |
| run: bun i | |
| - name: Generate static site | |
| run: bun generate | |
| - name: Build API | |
| working-directory: src-api | |
| run: cargo build --release --locked | |
| - name: Build Docker image | |
| run: docker build . -t ghcr.io/${{ github.repository }}:latest | |
| - name: Push Docker image | |
| run: docker push ghcr.io/${{ github.repository }}:latest | |
| - name: Save build cache | |
| if: always() | |
| uses: actions/cache/save@v4 | |
| with: | |
| path: | | |
| src-api/target | |
| src-crypto/target | |
| src-macro/target | |
| ~/.cargo/bin | |
| ~/.cargo/registry | |
| ~/.cargo/git | |
| node_modules | |
| key: ${{ runner.os }}-build-${{ hashFiles('**/Cargo.lock') }}-${{ hashFiles('**/package-lock.json') }} |