# Deploy

> Build on every push and deploy to stage from the stage branch and to production from main, one deploy per environment at a time.
> **Available** in repositories branchd reads pipeline files for. It is switching repositories on one at a time: until yours is, it keeps running its `.forge-ci.yaml` or `.xeonr-ci.yaml`. See [What is available](https://docs.branchd.run/branchd/pipelines#what-is-available).

```yaml title=".branchd/pipelines/ci.yaml"
# .branchd/pipelines/ci.yaml
# Build on every push, deploy to stage from the stage branch and to
# production from main. One deploy per environment runs at a time.
name: CI
on:
  push:
    branches: [main, stage]
jobs:
  build:
    image: golang:1.26
    outputs:
      version: ${{ steps.version.outputs.version }}
    steps:
      - run: go build -o dist/server ./cmd/server
      - id: version
        run: echo "version=$CI_COMMIT_SHORT_SHA" >> "$BRANCHD_OUTPUT"
    artifacts: [dist]
  deploy:
    needs: [build]
    if: branch == 'main' || branch == 'stage'
    image: alpine:3
    environment:
      name: ${{ branch == 'main' && 'production' || 'stage' }}
      url: ${{ branch == 'main' && 'https://app.example.com' || 'https://stage.app.example.com' }}
    concurrency: deploy-${{ branch }}
    secrets: [DEPLOY_TOKEN]
    steps:
      - run: ./scripts/deploy.sh "${{ branch }}" "${{ needs.build.outputs.version }}"
```

- **One deploy job for two environments.** `&&` and `||` return one of their
  operands, so `${{ branch == 'main' && 'production' || 'stage' }}` is
  `production` on `main` and `stage` elsewhere.
- **`environment:`** records a deployment of that name, with its `url`, on
  each run of the job.
- **`concurrency: deploy-${{ branch }}`** is a lock: one job holding
  `deploy-main` runs at a time in this repository, and the next waits. Two
  runs never deploy one environment at once.
- **`secrets: [DEPLOY_TOKEN]`** grants the job the secret, as the
  environment variable `$DEPLOY_TOKEN`. See [Secrets](https://docs.branchd.run/branchd/pipelines/secrets).
- **Outputs and artifacts.** `deploy` reads `build`'s `version` output, and
  finds `build`'s `dist/` (its artifacts) in its working directory.

To make a person release the production deploy, see
[Environments and manual approval](https://docs.branchd.run/branchd/pipelines/environments-and-approval).

Source: https://docs.branchd.run/branchd/pipelines/deploy
