# Release the newest releasable commit

Describe how your repository releases in one file, then release with one command or one button, without picking a commit.

A release starts your release workflow (for example a deploy workflow with a `production` input)
with one commit: the newest commit of the release branch that has passed everything you require,
such as a green test workflow and a successful staging deploy. You do not look up a commit id, and
a commit that has not passed is never picked for you.

Replace repo-id with the repository's id.

## Prerequisites

- `ci:ListRuns` on the repository to see which commit a release would take.
- `ci:StartWorkflow` on the repository to start the release. A release is a manual start of the
  release workflow, recorded in the audit log as one.
- A release workflow that accepts a manual start (`on: workflow_dispatch`) with an input that names
  the commit to release.

## Describe how the repository releases

Commit `.dcloud/release.yml` to the default branch:

```yaml
name: production # the button reads "Release to production"
workflow: deploy.yml # .github/workflows/deploy.yml
branch: main # the release branch; default: the default branch
ref_input: ref # the workflow input that receives the commit id
inputs: # the other inputs of a release
  production: true
requires:
  workflows: [tests.yml] # the newest completed run on the commit succeeded
  statuses: [deploy/staging] # this commit status is success
```

A commit is releasable when, for each workflow under `requires.workflows`, the newest completed run
of that workflow on the commit succeeded, and each commit status under `requires.statuses` is
`success`. A failed run that a re-run turned green counts as green; a green run followed by a red
re-run counts as red.

Commit statuses are set with GitHub's API from a job, for example after your staging deploy:

```sh
gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
  -f state=success -f context=deploy/staging
```

The job needs `permissions: statuses: write` (see
[Call the GitHub API from a job](call-the-github-api-from-a-job.md)).

## Tag each release

Add `tag_prefix` to the file to have every release tag the commit it ships:

```yaml
tag_prefix: prod # a release tags its commit prod-2026-12-03-1
```

The tag is `<tag_prefix>-<YYYY-MM-DD>-<n>`: the date in UTC, and `n` counting that day's releases
from 1. The release makes the tag first, then starts the workflow, so:

- You need `git:PushRepository` on the repository as well, and `git:PushProtectedTag` when a tag
  protection rule covers the tag. Without it nothing is tagged and nothing starts. Protect the
  prefix (for example `prod-*`) to limit who can release.
- The tag starts no workflow of its own, so a workflow with `on: push: tags` does not run a second
  release for it.
- The tag records that a release of this commit was asked for. Whether the release succeeded is
  the workflow run's result: a run that fails or refuses leaves the tag in place.

## Release

**Console**
1. Open the repository in [Git](/git/repositories), then **Actions**.
2. Choose **Release to** _production_ (the name comes from `name` in the file).
3. Check the commit, its age, what it adds to the last release and which newer commits are not
   releasable yet, and why.
4. Choose **Release** with the commit id.

The run list marks the newest run of the commit a release would take **Next release**, and the run
that made the last release **Released to** _production_.

**CLI**
Inside a clone of the repository:

```sh
dcloud ci release --dry-run   # which commit, and nothing else
dcloud ci release             # shows it and asks before it starts
```

Outside a clone, name it with `-R org/repo`. `--ref <commit>` releases that
commit instead; `--yes` does not ask.

**API**
```http
GET /ci/api/repositories/repo-id/release
```

```http
POST /ci/api/repositories/repo-id/release
{ "dryRun": true }
```

`POST` without `dryRun` starts the release. Pass the `ref` you were shown, so the release takes
that commit even when a newer one became releasable in the meantime.

## Result

`201` with `{ sha, subject, releasable, unmet, name, workflowPath, lastRelease, tag, dispatched:
true, runId }`: the release workflow is queued on the release branch with the commit in
`ref_input`. `tag` is the tag the release made, or `null` without `tag_prefix`. With `dryRun`,
`200` and `dispatched: false`; `tag` is then the tag a release made now would get, and no tag is
made.

- `409` with one line when no commit qualifies, naming the commit closest to releasable and what it
  still lacks, for example "No releasable commit since the last release (1a2b3c4d5e6f); the
  nearest, 9f8e7d6c5b4a, has deploy/staging: pending."
- `409` when the repository has no `.dcloud/release.yml`, or it is invalid (the error names the
  field).
- `409` without `ref` when the last release already shipped the newest releasable commit.
- `409` when the tag could not be made (the error says why); nothing was started.
- With `ref`, the commit is started even when it is not releasable; `unmet` lists what it lacks,
  and your workflow decides.

The commit a release takes is never older than the last release: "what it adds" is the commits
between the two. The last release is the newest successful manual run of the release workflow
started with the same `inputs`. When that run named no commit in `ref_input` (it was started by hand
without one), the last release is unknown, and the release looks back up to 200 commits.

## Related

- [Start a workflow by hand](start-a-workflow-by-hand.md)
- [Required checks](required-checks.md)
- `ci.releases.candidate` · `ci.releases.start` · `dcloud ci releases candidate`
