# Themes from Bitbucket

The theme of each site can live in its own Bitbucket or GitHub repository. Several sites of one agency can also share one. Every push to `main` builds the theme and puts it live. Every push to `staging` puts it on staging. Nobody uploads by hand, and nobody needs access to the server.

A theme is PHP, and the engine runs it. That is why a theme of your own runs only on a **frontend of your own**. That frontend can be at Lightbolt or on your own hosting. It never runs on the shared frontend, where only the themes of the platform run. So a site on the shared frontend cannot be chosen for a repository.

## Connect your Bitbucket or GitHub, once

Go to **Integrations** of your organisation. Add **Bitbucket (theme repositories)** or **GitHub (theme repositories)**. Each agency uses its own workspace or GitHub organisation. So the repositories are yours, and your developers have access as always. When you have no connection of your own, the one of the platform (Lightbolt) may be offered.

**Organisation → Themes → Repositories** is the one place for all of it:

- your connections, each with **Change**, which opens its page under Integrations;
- every repository as a card, with **Open in Bitbucket**, its pipeline, its sites and its branches;
- **New repository**.

The own repository of a site also shows under **Theme → Repository** of that site, with the site chosen already. The page of a connection under Integrations lists the repositories made with it.

There is one connection per service per organisation. A second workspace goes under the Integrations of a suborganisation, for its sites.

What each connection needs:

- **Bitbucket** needs the workspace, an optional project key, the e-mail address of the Atlassian account, and an **API token with scopes**. You make that token at id.atlassian.com → Security → API tokens → *Create API token with scopes*, with the app Bitbucket. Give it these scopes: `read:user`, `read:workspace`, `read:project`, `read:repository`, `write:repository`, `admin:repository`, `read:pipeline`, `write:pipeline` and `admin:pipeline`.
- **GitHub** needs the organisation or account, and a **fine-grained personal access token** for it. You make that under Settings → Developer settings → Fine-grained tokens. Give it all repositories, with read and write on Administration, Contents, Secrets, Workflows and Actions.

**Test** on the connection only reads. It shows who the token is, the workspace or owner, and its repositories.

## Made by Lightbolt: the quickest way

Go to **Organisation → Themes → Repositories**. Choose the site, and optionally a key. Under **Where**, choose your connection. Click **Make the repository**. Lightbolt then does these steps, in this order:

1. When the site has only live, it makes a **staging** environment. Staging gets the content of live, and its test hostname, in Plesk too.
2. It makes a private repository `theme-<key>`. On Bitbucket, it goes in the project.
3. It turns Pipelines on. That is for Bitbucket. On GitHub, Actions are on already.
4. It makes a pipeline key for that site, and sets it as the secret `LIGHTBOLT_TOKEN`. Nobody sees it.
5. It puts the starter on `main`, with only its own pipeline. That first push builds the theme and puts it live.
6. It makes a branch from `main` for every other environment, such as `staging`. The first build of that branch puts the theme there too. A repository made before version 564 also gets a new `lightbolt.json`, `bin/deploy.sh` and pipeline, once.
7. It protects `main`. That means no force push, and no deleting. The free plan of GitHub has no protection for private repositories. Then Lightbolt says so.

The **Theme** of the site then links to the repository and its pipeline.

**A new environment later.** Add it under **Domains and environments** of the site. Lightbolt makes its branch from `main` in the repository right away. The pipeline key may then choose a version for it too. Nothing changes in the files of the repository, because Lightbolt decides which branch goes to which environment.

You see each step with ✓ or ✗. Lightbolt stops at the first step that fails. Click **Make the repository** again to go on. What is done stays as it is. Then clone the repository, and work in it.

## Set it up yourself, once per site

Under **Where**, choose *Download the starter* for a repository of your own. On GitHub, the secret goes under Settings → Secrets and variables → Actions, and Actions are on already.

1. In Lightbolt, go to **Organisation → Themes → Repositories**. Choose the site, and optionally a key for the theme. Click **Make the token and the starter**.
2. Click **Download the starter repository**. It is filled in for that site, with the CMS and the site. It holds no secret.
3. In Bitbucket, make an empty repository. Unzip the starter, and push it to the branch `main`.
4. Go to **Repository settings → Pipelines → Settings**, and enable Pipelines.
5. Go to **Repository settings → Repository variables**. Add `LIGHTBOLT_TOKEN` with the token that Lightbolt showed, and tick **Secured**. The token is shown only once. If you lose it, make a new one.
6. Go to **Repository settings → Branch restrictions**. On `main`, allow merges only through a pull request, and no force push.
7. Make a branch from `main` for each environment that is not live, with its name, such as `staging`. Push it. Do the same for an environment that you add later.

The token may only upload the themes of this agency. It may only choose a version for the environments of this site. You can see it and stop it under **Organisation → Themes → Pipeline keys**.

## What is in the starter

| File | What it holds |
| --- | --- |
| `THEME` | The key, the version (`1.0.0`) and the engine it needs (`>=1.118.0`). |
| `theme.php` | Its parent (`base`), its presets for the field Classes, and what its templates show (`display`). |
| `lightbolt.json` | The CMS and the site. Lightbolt says which branch goes where: `main` goes to live, and a branch named after an environment goes to that environment. |
| `bitbucket-pipelines.yml` | For Bitbucket: one step for every branch, `sh bin/deploy.sh "$BITBUCKET_BRANCH"`. |
| `.github/workflows/lightbolt.yml` | For GitHub: the same, on every push. |
| `bin/deploy.sh` | It builds the package with `bin/build-theme.php`, and uploads it. |
| `bin/build-theme.php` | The build tool of the frontend. The own themes of the engine are built with the same tool. |
| `templates/`, `assets/` | Your theme. It only holds what differs from `base`. See [Building a theme](/md/docs/themes/building-a-theme/). |

## What a push does

1. `deploy.sh` copies the theme into a folder named after the key. It leaves out the own files of the repository. It fetches the settings of `base` from Lightbolt. Then it builds the package with `bin/build-theme.php`. The package has `THEME`, with the presets and display of base merged in, and `MANIFEST.sha256`.
2. The version is MAJOR.MINOR from `THEME`, plus the build number. So build 37 of `1.0.0` is `1.0.37`. For a bigger change, raise MAJOR.MINOR in `THEME`.
3. It asks Lightbolt which environment the branch goes to, with `GET /delivery/v1/themes/branch?site=…&branch=…`. For such a branch, it uploads the zip with `POST /delivery/v1/themes?site=…&environment=…`. Lightbolt keeps the version, and chooses it for that environment. The site fetches it within seconds.
4. Any other branch only builds. That checks that the package is complete.

For the same files and build number, the package is the same, byte for byte. So a build that runs again gives the same version. Lightbolt takes it as the one it has.

## How Lightbolt knows what goes where

No name has to match. The repository may be called anything.

| What | What decides it |
| --- | --- |
| **The site** | The pipeline key, `LIGHTBOLT_TOKEN`. It belongs to one site. `lightbolt.json` names the same site. |
| **The theme** | `key` in `THEME`. A new key is a new theme. The same key is a new version of it. |
| **The environment** | The branch. `main` is always live, whatever live is called. Any other environment has its own name: `staging` goes to `staging`, and `acceptance-2` goes to `acceptance-2`. Environment names use lower case, a–z, 0–9 and `-`. They cannot be renamed, so the branch always matches. A branch that matches no environment only builds. |

Lightbolt works this out at every push, with `GET /delivery/v1/themes/branch`. So a new environment needs no change in the files of the repository. It only needs its branch. Lightbolt makes that branch itself, in a repository that it made or linked. In a repository that you set up yourself, you make that branch from `main`. **Theme → Repository** of the site lists which branch goes where.

## Back to an earlier version

In Lightbolt, go to the site → **Theme → Theme version**, and choose the earlier one. That works at once. The next push to that branch puts a new version there again. So revert the commit too, to stay on the earlier version.

## When the pipeline is red

| What you see | What it means | What to do |
| --- | --- | --- |
| `LIGHTBOLT_TOKEN is not set` | The repository variable is missing. | Add it, secured, as in step 5. |
| `401` | The token does not work. It was stopped, or copied wrong. | Make a new one. |
| `409` … *Uploaded, but not chosen: …* | The version is in Lightbolt, but it could not go on the environment. The reason follows. Maybe the site is not on a frontend of your own. Maybe the theme needs a newer engine than the environment runs. Or it is still the empty starter, while the environment runs a theme. Then the site keeps its look until the theme is in the repository. | Fix the reason. Then choose the version under **Theme** of the site, or push again. |
| `409` … *This token may not choose a version for …* | The token is for another site, or the site got another environment. | Make a token for this site. |
| `PHP errors above: nothing built.` | A PHP file does not parse. | Check it with `php -l`, fix it, and push again. |
| *The parent themes' settings could not be fetched* | Lightbolt could not be reached for the settings of `classic` or `base`. On a branch that goes somewhere, nothing is uploaded. So no choices of the field Classes get lost. | Run the pipeline again. |
| `422` … *is there already* | That version exists with other files. A build number was used again. | Raise MAJOR.MINOR in `THEME`. |
| `422` … *no THEME* or *no MANIFEST.sha256* | The package is not complete. | Check that `THEME` is at the root of the repository. |

## The rights it needs

The pipeline itself needs no right from the connection. It talks to Lightbolt with the pipeline key. The rights of the connection only spare you work by hand. Fewer rights never break it. What the token may not do becomes a step **by hand** (✋) on the screen, with what to do. Lightbolt does the rest.

| Level | Bitbucket scopes | GitHub permissions | Lightbolt does | You do by hand |
| --- | --- | --- | --- | --- |
| None | No connection | No connection | The token, and the starter to download. | Everything below. |
| The least | `read:user`, `read:workspace`, `read:repository`, `write:repository` | Contents, Workflows | The starter on `main`, and a branch per environment, also for later ones. | Make the repository (`theme-<key>`), turn Pipelines on, add `LIGHTBOLT_TOKEN` (shown once), and protect `main`. |
| Handy | Also `read:pipeline`, `write:pipeline`, `admin:pipeline` | Also Secrets, Actions | Also Pipelines on, and `LIGHTBOLT_TOKEN`, set and replaced when the token is renewed. | Make the repository, and protect `main`. |
| Everything | Also `read:project`, `admin:repository` | Also Administration | Also the repository, in its project, and `main` protected. | Nothing. |

This is where you do it by hand in Bitbucket:

- the repository, under **Create → Repository**, as private;
- Pipelines, under **Repository settings → Pipelines → Settings**;
- the variable, under **Repository settings → Repository variables**, as Secured;
- `main`, under **Repository settings → Branch restrictions**.

Then click **Make the repository** again. What is there already stays as it is.

A token with these rights may do this in every repository that its account sees. So use an account of its own, which sees only the project of your themes.

## While it works

Making, adding, linking and checking the branches run in the background. When you come back, the screen shows how far it is, and the result. So you can go on elsewhere in Lightbolt.

- Sometimes Bitbucket or GitHub gives no answer, or answers with its own trouble, such as HTTP 5xx or 429. Then Lightbolt tries again after 5 minutes, and then after 15 minutes. **Try again now** does not wait.
- A refusal, such as a missing right or a wrong name, is not tried again.
- After 3 attempts without success, the site gets a ticket. It says what was done, and where it stopped.
- A token that you must put in by hand is shown once, to the person who started it.

## A repository made before

Maybe you made one by hand from the starter, or before Lightbolt kept track of repositories. Then Lightbolt does not know that it belongs to the site. It shows no card, and the connection counts 0.

1. Go to **Organisation → Themes → Repositories → New repository**, or to **Theme → Repository** of the site.
2. Choose the site, and **Link one that is there**.
3. Choose it from the list. The list holds the repositories of the workspace or project that no site has yet, with `theme-…` first. Without the right to read that list, type its name, such as `theme-sun-rise`, or its address.

Lightbolt checks it with the connection. It notes it with the key of its `THEME`, and makes the branches it lacks. Its files stay as they are. So does the token that its pipeline has.

## Several sites, one theme

Sites of one agency with the same layout can share one repository. Under **Where**, choose **Add it to theme-…**. Lightbolt then notes the repository for that site too. It lets the token choose for the environments of that site, and makes the branches it needs.

A push to `main` then puts the theme live on every site in the repository. A push to `staging` puts it on the staging of each site. Nothing changes in the files of the repository.

## A theme out of the engine

Some sites still draw a theme that sits in the engine itself. Platform staff can move such a theme into a repository of its own:

1. The site is on a frontend of its own agency.
2. Under **New repository**, platform staff tick **Start with: the theme the site draws from the engine now**.
3. Lightbolt fills the repository with that folder, under the same key. `THEME` gets the engine that live runs as its engine rule. The parent stays in the theme's own `theme.php`.
4. The first push builds the package. Choose it for staging, compare it with live, and then choose it for live.
5. From then on, work only in the repository. The theme can then leave the engine.

Lightbolt refuses `base` and `classic`, and a theme that sites of another agency also draw. Platform staff can also download one theme of an engine version as a zip, under **Platform → Frontends → Engine versions → Themes**.

## Its parent and key

The `theme.php` of the starter has the parent that the theme of the site has now. For imported sites, that is `classic`, with `legacy.css`, the shared components and the `old.*` switches. Otherwise, it is `base`.

Leave **Key of the theme** empty to keep the key that the site has now, such as `sunrise`. Then its versions follow on.

**Its engine rule** is `engine` in `THEME`. It is the oldest engine that the theme works with. When you use something new of the engine, raise it to the version that you tested with in the [dev kit](/md/docs/themes/developing-locally/). That is in `engine/VERSION`.

## Good to know

- Your own themes, with PHP, run only on a frontend of your own. See [Installing a frontend](/md/docs/frontend/installing-a-frontend/).
- Another pipeline, such as GitHub Actions or GitLab CI, works the same. Run `bin/deploy.sh <branch>` with `LIGHTBOLT_TOKEN` as a secret. It needs PHP 8.3 with zip, `jq`, `curl`, `unzip` and `tar`.
- [Themes](/md/docs/themes/packages/) describes the API itself.

*Also called: theme deployment, CI/CD, continuous deployment, git deploy.*

Last changed 26 November 2026
