# Gallery versions

> Keep what your gallery showed at each release, v1.0.0 and v2.0.0 side by side, at stable URLs, by reporting versions from your release workflow.

Source: https://visualci.com/docs/gallery/versions/
All of VisualCI's documentation: https://visualci.com/llms.txt

A gallery always shows the default branch as it is now. To keep what it showed at a release, so people can see what your app looked like at v1.0.0 and at v2.0.0, report the version when you release. Each reported version keeps the gallery's screenshots, groups and names as they were at that commit, for good, at URLs of its own. Nothing changes for a project that doesn't report versions.

## Report a version

Run `visualci release` where you release, once the release commit's default-branch build is approved:

```sh
visualci release v2.0.0
```

Without a version, it takes the tag the CI run builds (`GITHUB_REF_NAME` on a tag push, `CIRCLE_TAG`, `CI_COMMIT_TAG`, `BUILDKITE_TAG`, `BITBUCKET_TAG`, `SEMAPHORE_GIT_TAG_NAME`, `TRAVIS_TAG`, `TAG_NAME`), else the commit's own tag. It records what the gallery published at that commit: the approved screenshots of the newest default-branch builds at or before it. A later commit's approval doesn't count, even when it's made before you record the version. It takes the commit and its ancestors from git, so the checkout needs its history.

A version is recorded once. Running the same command again answers the version already recorded. The same version at another commit is refused, since a version's screenshots never change. A version is up to 64 letters, digits, dots, dashes, underscores and plus signs, with at least one letter or digit, and can't be called `latest`.

### GitHub Actions

<!-- example: crates/visualci-cli/examples/release/github-actions.yml -->
```yaml
# .github/workflows/release.yml
name: Release
on:
  push:
    tags: ["v*"]
jobs:
  gallery-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0 # VisualCI finds what the gallery published through the commit's ancestors
      - name: Install VisualCI
        run: |
          curl -fsSLo visualci.tar.gz https://github.com/DocSpring/visualci/releases/download/v0.2.32/visualci-x86_64-unknown-linux-musl.tar.gz
          echo "b2d6630d7a98a7819dcd2989a3eecb89bbdd75076832d3eb16a67e360fe58bb4  visualci.tar.gz" | sha256sum -c
          mkdir -p "$RUNNER_TEMP" && tar xzf visualci.tar.gz --strip-components=1 -C "$RUNNER_TEMP" visualci-x86_64-unknown-linux-musl/visualci
          echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
      - run: visualci release
        env:
          VISUALCI_TOKEN: ${{ secrets.VISUALCI_TOKEN }}
```

### CircleCI

<!-- example: crates/visualci-cli/examples/release/circleci.yml -->
```yaml
# .circleci/config.yml: a job, and a workflow that runs it for tags only
jobs:
  gallery-version:
    docker:
      - image: cimg/base:current
    steps:
      - checkout
      - run: |
          curl -fsSLo visualci.tar.gz https://github.com/DocSpring/visualci/releases/download/v0.2.32/visualci-x86_64-unknown-linux-musl.tar.gz
          echo "b2d6630d7a98a7819dcd2989a3eecb89bbdd75076832d3eb16a67e360fe58bb4  visualci.tar.gz" | sha256sum -c
          sudo tar xzf visualci.tar.gz --strip-components=1 -C /usr/local/bin visualci-x86_64-unknown-linux-musl/visualci
      - run: visualci release
workflows:
  release:
    jobs:
      - gallery-version:
          context: visualci # holds VISUALCI_TOKEN
          filters:
            tags:
              only: /^v.*/
            branches:
              ignore: /.*/
```

### GitLab CI

<!-- example: crates/visualci-cli/examples/release/gitlab-ci.yml -->
```yaml
# .gitlab-ci.yml
gallery-version:
  image: node:lts
  rules:
    - if: $CI_COMMIT_TAG
  variables:
    GIT_DEPTH: 0 # VisualCI finds what the gallery published through the commit's ancestors
  script:
    - curl -fsSLo visualci.tar.gz https://github.com/DocSpring/visualci/releases/download/v0.2.32/visualci-x86_64-unknown-linux-musl.tar.gz
    - echo "b2d6630d7a98a7819dcd2989a3eecb89bbdd75076832d3eb16a67e360fe58bb4  visualci.tar.gz" | sha256sum -c
    - mkdir -p /usr/local/bin && tar xzf visualci.tar.gz --strip-components=1 -C /usr/local/bin visualci-x86_64-unknown-linux-musl/visualci
    - visualci release
```

Other CI providers: run `visualci release` in the job your tags start, after installing the CLI as in [your provider's guide](https://visualci.com/docs/ci/other.md), with `VISUALCI_TOKEN` set.

## Show versions in your gallery

The [gallery libraries](https://visualci.com/docs/gallery.md) show versions two ways, both opt-in:

- **A Version switch:** with the `versions` option on (`"versions": true`, `versions=True` in Python, `versions: true`
  in Ruby, `.versions(true)` in Rust), the grid gets a switch over its tabs: Latest, then each version, newest first.
  Choosing one shows that release's screenshots in place, keeping the reader's tab and values. See
  [Versions](https://visualci.com/docs/gallery/options.md#versions) in the options.
- **One version, for good:** give `ref` with the manifest's URL to render a release instead of Latest, for a page
  that documents that release: `load({manifest, ref: "v1.0.0"})` in JavaScript, `ref="v1.0.0"` in the Astro
  component and Hugo's shortcode, the version's own manifest URL (`…/web@v1-0-0.json`) in the Docusaurus and
  VitePress plugins' `manifests` and their components, `VisualCI::Gallery.fetch(url, ref: "v1.0.0")` in Ruby,
  `visualci_gallery.fetch(url, ref="v1.0.0")` in Python, and `visualci_gallery::manifest_url(url, Some("v1.0.0"))` in
  Rust, which gives the URL to fetch. A label or its key both work.

## What's served

Each version has a key: its label lowercased, with each run of other characters one hyphen (`v1.0.0+build.5` is `v1-0-0-build-5`).

- **Its manifest:** `https://app.visualci.com/g/<org>/<project>@<key>.json`, the same shape as the [gallery's manifest](https://visualci.com/docs/gallery.md#whats-served) with the groups and screenshots as they were, plus `version` (`key`, `label`, `released_at`) and the `versions` list.
- **Its images:** `https://app.visualci.com/g/<org>/<project>@<key>/<name>.png`, and `.thumb.webp` thumbnails. They never change, so they're cached for a year.
- **The `versions` list** in the main manifest and in every version's: each version's `key`, `label`, `released_at` and `manifest` URL, newest first. Versions released at the same moment come in the order they were recorded, the last recorded first. The gallery libraries show the list in this order.

```text
"versions": [
  { "key": "v2-0-0", "label": "v2.0.0", "released_at": "2026-12-05T04:00:00+00:00", "manifest": "https://app.visualci.com/g/acme/web@v2-0-0.json" },
  { "key": "v1-0-0", "label": "v1.0.0", "released_at": "2026-11-02T10:31:07+00:00", "manifest": "https://app.visualci.com/g/acme/web@v1-0-0.json" }
]
```

The main manifest stays the default branch's gallery as it is now (call it Latest), which may be ahead of the newest version. A version's thumbnails appear a few seconds after it's recorded, like the gallery's. A version recorded while the gallery is off is kept, and served once the gallery is on.

The project's page lists its versions under its public screenshots. `GET /api/v1/versions` lists them with a project token.

## Storage and cost

A version's images are kept for as long as the project, however old, while other images go after 30 days unless a baseline needs them. A project keeps up to 500 versions; past that, `visualci release` is refused, so tag releases rather than every commit, and [contact support](mailto:support@visualci.com) if you need more. Images served from a version's URLs cost credits like the gallery's own (see [Caching and cost](https://visualci.com/docs/gallery.md#caching-and-cost)); there's no charge for keeping them.
