---
title: Deploy from your own CI
description: >-
  Run your tests in GitHub Actions, GitLab CI, or any pipeline, and deploy to
  Olimpia only when they pass.
sidebar:
  label: From your CI
  icon: workflow
---
[Automatic deploys with GitHub](/en/apps/github) deploy every push with no extra steps. If you want your pipeline to decide when to deploy (for example, after running your tests), use an app with [uploaded code](/en/apps/subir-codigo) and call the API from your CI.

## What you need [#qué-necesitás]

1. An app created with `source: "upload"`. See [Upload your folder](/en/apps/subir-codigo#el-flujo).
2. A [personal token](/en/cuenta/tokens), stored as a CI secret (`OLIMPIA_TOKEN`).
3. The app's `id`, stored as a CI variable (`OLIMPIA_APP_ID`).

## GitHub Actions

```yaml .github/workflows/deploy.yml
name: Deploy a Olimpia

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test

  deploy:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Subir y desplegar
        env:
          OLIMPIA_TOKEN: ${{ secrets.OLIMPIA_TOKEN }}
          APP_ID: ${{ vars.OLIMPIA_APP_ID }}
        run: |
          api=https://api.olimpia.dev
          auth="Authorization: Bearer $OLIMPIA_TOKEN"
          upload=$(curl -fsS -X POST -H "$auth" "$api/apps/$APP_ID/source")
          git archive --format=tar.gz --prefix=src/ -o /tmp/src.tar.gz HEAD
          curl -fsS -X PUT -T /tmp/src.tar.gz "$(echo "$upload" | jq -r .upload_url)"
          curl -fsS -X POST -H "$auth" -H 'content-type: application/json' \
            -d "{\"source\": \"$(echo "$upload" | jq -r .key)\", \"message\": \"$GITHUB_SHA\"}" \
            "$api/apps/$APP_ID/deployments" > /dev/null
```

## GitLab CI

```yaml .gitlab-ci.yml
deploy:
  stage: deploy
  image: alpine:3.22
  only: [main]
  script:
    - apk add --no-cache curl jq git
    - api=https://api.olimpia.dev
    - auth="Authorization: Bearer $OLIMPIA_TOKEN"
    - upload=$(curl -fsS -X POST -H "$auth" "$api/apps/$OLIMPIA_APP_ID/source")
    - git archive --format=tar.gz --prefix=src/ -o /tmp/src.tar.gz HEAD
    - curl -fsS -X PUT -T /tmp/src.tar.gz "$(echo "$upload" | jq -r .upload_url)"
    - >
      curl -fsS -X POST -H "$auth" -H 'content-type: application/json'
      -d "{\"source\": \"$(echo "$upload" | jq -r .key)\", \"message\": \"$CI_COMMIT_SHA\"}"
      "$api/apps/$OLIMPIA_APP_ID/deployments"
```

## Wait for the result [#esperar-el-resultado]

The deployments `POST` returns right away. To make the pipeline fail when the deploy fails, poll the latest deploy until it finishes:

```bash
until status=$(curl -fsS -H "$auth" "$api/apps/$APP_ID/deployments" | jq -r '.[0].status'); \
  [ "$status" = active ] || [ "$status" = failed ] || [ "$status" = canceled ]; do sleep 10; done
[ "$status" = active ]
```

:::note
Apps connected to GitHub deploy automatically on every push and don't need this.
:::
