Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/deploy-site-initial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"deploy-site": minor
---

Add the `deploy-site` action: deploy a static site to bunny.net via the `@bunny.net/cli` `sites deploy` command, with per-deploy preview URLs and a sticky pull request preview comment.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
</a>
</div>

Github actions
====
# Github Actions

This is the repository where we put actions to use with
[Bunny](https://bunny.net)!
Expand All @@ -19,16 +18,16 @@ Each action can be used in your workflow this way:

```yaml
steps:
- uses: BunnyWay/actions/<action>@<actions@ref>
- uses: BunnyWay/actions/<action>@<actions@ref>
```

Each action will have its own documentation, you can check the associated documentation
in each folder.
Each action will have its own documentation, you can check the associated documentation in each folder.

It contains:

- [`BunnyWay/actions/deploy-script`](./deploy-script)
- [`BunnyWay/actions/container-update-image`](./container-update-image)
- [`BunnyWay/actions/deploy-site`](./deploy-site)

## Development

Expand All @@ -41,6 +40,6 @@ We handle versionning with [changeset](https://github.com/changesets/changesets)
to indicate the kind of changes you are doing so we can have the auto-release
process ongoing by doing:

```
```bash
pnpm changeset
```
3 changes: 3 additions & 0 deletions deploy-site/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
.lib-action
1 change: 1 addition & 0 deletions deploy-site/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# deploy-site
86 changes: 86 additions & 0 deletions deploy-site/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Deploy a static site to bunny.net

This GitHub Action deploys a built static site to [bunny.net](https://bunny.net)
with one `uses:` step. It wraps the [`@bunny.net/cli`](https://www.npmjs.com/package/@bunny.net/cli)
`sites deploy` command (the CLI is the single deploy path) and owns the sticky
pull request preview comment.

- Deploys a **preview** by default; publishes to **production** when asked.
- On `pull_request` events it upserts one sticky comment with the preview URL,
updated on every commit.
- Runs on `ubuntu-latest` and `macos-latest`. (Windows is not verified; the CLI
ships per-platform binaries and Windows availability has not been confirmed.)

## Usage Example

```yaml
name: Deploy site
on:
push:
branches: [main]
pull_request:

concurrency:
group: bunny-sites-${{ github.ref }}
cancel-in-progress: true

jobs:
deploy:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- run: bun install --frozen-lockfile
- run: bun run build
- uses: BunnyWay/actions/deploy-site@deploy-site_1.0.0
with:
site: my-site
directory: dist
production: ${{ github.event_name == 'push' }}
api_key: ${{ secrets.BUNNY_API_KEY }}
```

> **Fork PRs:** pull requests from forks do not have access to repository
> secrets, so the deploy (and its preview comment) cannot run for them. The
> `if:` condition above skips fork PRs; pushes and same-repo PRs still deploy.

You can scaffold this workflow with `bunny sites ci init`. See the CLI repo's
framework examples (Next.js, Astro, Vite, SvelteKit) for per-framework build
commands and output directories.

## Inputs

| Input | Required | Default | Description |
| -------------- | -------- | --------------------- | -------------------------------------------------------------------------------- |
| `site` | yes | | Site name or storage zone ID. |
| `directory` | yes | | Built output directory to deploy (e.g. `dist`). |
| `api_key` | yes | | bunny.net API key (store it as a repository secret). |
| `production` | no | `"false"` | Publish this deploy as the live site (`"true"`/`"false"`, default preview only). |
| `comment` | no | `"true"` | Upsert a sticky PR comment with the preview URL on `pull_request` events. |
| `github_token` | no | `${{ github.token }}` | Token for the PR comment (needs `pull-requests: write`). |
| `cli_version` | no | `"0.10"` | `@bunny.net/cli` version range to run (pin bumped per action release). |
| `force` | no | `"false"` | Redeploy even when content is unchanged. |

## Outputs

| Output | Description |
| ---------------- | ------------------------------------------------------------------ |
| `deploy-id` | The deploy ID (git short sha on clean checkouts). |
| `preview-url` | Preview URL for this deploy (empty when the site has no host yet). |
| `production-url` | Production URL (set when `production` input was `true`). |
| `unchanged` | `"true"` when the content was already deployed and nothing ran. |

## Setting up the API key

Store your bunny.net API key as a repository secret named `BUNNY_API_KEY`:

```bash
gh secret set BUNNY_API_KEY
```

Or via the GitHub UI: **Settings → Secrets and variables → Actions → New
repository secret**.
52 changes: 52 additions & 0 deletions deploy-site/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Deploy Site to Bunny
author: Bunny Devs
description: Deploy a static site to bunny.net with preview URLs per deploy.

inputs:
site:
description: Site name or storage zone ID.
required: true
directory:
description: Built output directory to deploy (e.g. dist).
required: true
api_key:
description: bunny.net API key (store it as a repository secret).
required: true
production:
description: Publish this deploy as the live site ("true"/"false", default preview only).
required: false
default: "false"
comment:
description: Upsert a sticky PR comment with the preview URL on pull_request events.
required: false
default: "true"
github_token:
description: Token for the PR comment (needs pull-requests write).
required: false
default: ${{ github.token }}
cli_version:
description: "@bunny.net/cli version range to run (pin bumped per action release)."
required: false
default: "0.10"
force:
description: Redeploy even when content is unchanged.
required: false
default: "false"

outputs:
deploy-id:
description: The deploy ID (git short sha on clean checkouts).
preview-url:
description: Preview URL for this deploy (empty when the site has no host yet).
production-url:
description: Production URL (set when production input was true).
unchanged:
description: '"true" when the content was already deployed and nothing ran.'

runs:
using: "node24"
main: ".lib-action/index.js"

branding:
color: "orange"
icon: "upload-cloud"
10 changes: 10 additions & 0 deletions deploy-site/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

export default [
{ files: ["**/*.{js,mjs,cjs,ts}"] },
{ languageOptions: { globals: globals.browser } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
9 changes: 9 additions & 0 deletions deploy-site/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ["js", "ts"],
testEnvironment: "node",
testMatch: ["**/*.test.ts"],
transform: {
"^.+\\.ts$": "ts-jest",
},
};
44 changes: 44 additions & 0 deletions deploy-site/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "deploy-site",
"version": "0.0.0",
"main": "lib/main.js",
"private": true,
"scripts": {
"lint": "eslint src",
"test": "jest --silent --coverage",
"build": "ncc build src/main.ts -o .lib-action/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/BunnyWay/actions.git"
},
"keywords": [
"actions",
"github",
"bunny",
"sites",
"deploy"
],
"author": "Bunny Devs",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@actions/github": "^6.0.1"
},
"devDependencies": {
"@eslint/js": "^9.39.4",
"@types/jest": "^29.5.14",
"@types/node": "^22.19.15",
"@typescript-eslint/eslint-plugin": "^8.57.2",
"@typescript-eslint/parser": "^8.57.2",
"@vercel/ncc": "^0.38.4",
"eslint": "^9.39.4",
"globals": "^15.15.0",
"jest": "^29.7.0",
"prettier": "^3.8.1",
"ts-jest": "^29.4.6",
"typescript": "^5.9.3",
"typescript-eslint": "^8.57.2"
}
}
Loading
Loading