name: CI on: pull_request: push: branches: [main] workflow_dispatch: permissions: contents: read concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} jobs: test: name: Test runs-on: ubuntu-24.04 env: MIX_ENV: test services: postgres: image: postgres:18.6 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres ports: - 5432:5432 options: >- --health-cmd "pg_isready -U postgres" --health-interval 5s --health-timeout 5s --health-retries 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1 - uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b #v5.2.7 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0 with: path: | deps ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-mix-test-${{ hashFiles('mix.lock', 'mise.toml') }} restore-keys: | ${{ runner.os }}-mix-test- - run: mix local.hex --force - run: mix local.rebar --force - run: mix deps.get - run: mix format --check-formatted - run: mix precommit build-release: name: Build release needs: test runs-on: ubuntu-24.04 env: MIX_ENV: prod SECRET_KEY_BASE: build-only-secret-key-base-build-only-secret-key-base-build-only-secret-key-base DATABASE_URL: ecto://postgres:postgres@127.0.0.1:5432/chesstrainer_build SES_REGION: eu-north-1 SES_ACCESS_KEY_ID: build SES_SECRET_ACCESS_KEY: build steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1 - uses: jdx/mise-action@b44d12e7d0d8ee7461bb893e1b1993500433185b #v5.2.7 - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 #v6.1.0 with: path: | deps ~/.cargo/registry ~/.cargo/git assets/node_modules key: ${{ runner.os }}-mix-prod-${{ hashFiles('mix.lock', 'mise.toml', 'assets/package-lock.json') }} restore-keys: | ${{ runner.os }}-mix-prod- - run: mix local.hex --force - run: mix local.rebar --force - run: npm ci --prefix assets --no-audit --no-fund - run: mix deps.get --only prod - run: mix assets.setup - run: mix assets.deploy - run: mix release - run: tar -czf chesstrainer-release.tar.gz -C _build/prod/rel/chesstrainer . - uses: actions/upload-artifact@v4 with: name: chesstrainer-release path: chesstrainer-release.tar.gz retention-days: 7 deploy: name: Deploy needs: build-release if: github.ref == 'refs/heads/main' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') runs-on: ubuntu-24.04 environment: production concurrency: group: production cancel-in-progress: false steps: - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 #v8.0.2 with: name: chesstrainer-release - name: Install SSH key run: | mkdir -p ~/.ssh printf '%s\n' "${{ secrets.VPS_SSH_KEY }}" > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 printf '%s\n' "${{ secrets.VPS_KNOWN_HOSTS }}" > ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts - name: Upload release run: | scp -i ~/.ssh/id_ed25519 -o BatchMode=yes \ chesstrainer-release.tar.gz \ "${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}:/tmp/chesstrainer-release.tar.gz" - name: Activate release run: | ssh -i ~/.ssh/id_ed25519 -o BatchMode=yes \ "${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }}" \ 'sudo -n /opt/chesstrainer/src/deploy/activate /tmp/chesstrainer-release.tar.gz' - name: Public smoke test run: | curl -fsS https://innersquare.app/health curl -fsS -o /dev/null https://innersquare.app/