| 1 |
--- |
| 2 |
title: Host on Codeberg Pages |
| 3 |
description: Host your project on Codeberg Pages. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
--- |
| 7 |
|
| 8 |
Use these instructions to enable continuous deployment from a Codeberg repository to Codeberg Pages. |
| 9 |
|
| 10 |
{{% include "/_common/gitignore-public.md" %}} |
| 11 |
|
| 12 |
## Prerequisites |
| 13 |
|
| 14 |
Please complete the following tasks before continuing: |
| 15 |
|
| 16 |
1. [Create](https://codeberg.org/user/sign_up) a Codeberg account. |
| 17 |
1. [Log in](https://codeberg.org/user/login) to your Codeberg account. |
| 18 |
1. [Create](https://codeberg.org/repo/create) a Codeberg repository for your project. |
| 19 |
1. [Create](https://git-scm.com/docs/git-init) a local Git repository for your project with a [remote][] reference to your Codeberg repository. |
| 20 |
1. Create a Hugo project within your local Git repository and test it with the `hugo server` command. |
| 21 |
1. Commit the changes to your local Git repository and push to your Codeberg repository. |
| 22 |
|
| 23 |
## Procedure |
| 24 |
|
| 25 |
Step 1 |
| 26 |
: Visit your Codeberg repository. Go to **Settings** > **Units** > **Overview**. Enable **Actions** and press the **Save Settings** button. |
| 27 |
|
| 28 |
 |
| 29 |
|
| 30 |
Step 2 |
| 31 |
: Create a `hugo.yaml` file in the `.forgejo/workflows` directory, adjusting the tool versions and time zone as needed. |
| 32 |
|
| 33 |
```yaml {file=".forgejo/workflows/hugo.yaml" copy=true} |
| 34 |
name: Build and deploy |
| 35 |
on: |
| 36 |
push: |
| 37 |
branches: |
| 38 |
- main |
| 39 |
workflow_dispatch: |
| 40 |
concurrency: |
| 41 |
group: ${{ forgejo.workflow }}-${{ forgejo.ref }} |
| 42 |
cancel-in-progress: true |
| 43 |
jobs: |
| 44 |
build_and_deploy: |
| 45 |
name: Build and deploy |
| 46 |
runs-on: codeberg-small |
| 47 |
env: |
| 48 |
# Define tool versions |
| 49 |
DART_SASS_VERSION: 1.104.0 |
| 50 |
GO_VERSION: 1.27.0 |
| 51 |
HUGO_VERSION: 0.166.0 |
| 52 |
NODE_VERSION: 24.20.0 |
| 53 |
|
| 54 |
# Set the build time zone |
| 55 |
TZ: Europe/Oslo |
| 56 |
|
| 57 |
# Set the Hugo base URL |
| 58 |
HUGO_BASEURL: https://${{ forgejo.event.repository.owner.username }}.codeberg.page/${{ forgejo.event.repository.name }}/ |
| 59 |
steps: |
| 60 |
- name: Checkout |
| 61 |
uses: actions/checkout@v7 |
| 62 |
with: |
| 63 |
submodules: recursive |
| 64 |
fetch-depth: 0 |
| 65 |
lfs: false |
| 66 |
|
| 67 |
- name: Create a local tools directory |
| 68 |
run: | |
| 69 |
mkdir -p "${HOME}/.local" |
| 70 |
|
| 71 |
- name: Install Dart Sass |
| 72 |
run: | |
| 73 |
echo "Installing Dart Sass ${DART_SASS_VERSION}..." |
| 74 |
curl -sfL --output-dir "${{ runner.temp }}" -O "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 75 |
tar -C "${HOME}/.local" -xf "${{ runner.temp }}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 76 |
echo "${HOME}/.local/dart-sass" >> "${FORGEJO_PATH}" |
| 77 |
|
| 78 |
- name: Install Go |
| 79 |
run: | |
| 80 |
if [[ -f "go.mod" ]]; then |
| 81 |
echo "Installing Go ${GO_VERSION}..." |
| 82 |
curl -sfL --output-dir "${{ runner.temp }}" -O "https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz" |
| 83 |
tar -C "${HOME}/.local" -xf "${{ runner.temp }}/go${GO_VERSION}.linux-amd64.tar.gz" |
| 84 |
echo "${HOME}/.local/go/bin" >> "${FORGEJO_PATH}" |
| 85 |
fi |
| 86 |
|
| 87 |
- name: Install Hugo |
| 88 |
run: | |
| 89 |
echo "Installing Hugo ${HUGO_VERSION}..." |
| 90 |
curl -sfL --output-dir "${{ runner.temp }}" -O "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 91 |
mkdir "${HOME}/.local/hugo" |
| 92 |
tar -C "${HOME}/.local/hugo" -xf "${{ runner.temp }}/hugo_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 93 |
echo "${HOME}/.local/hugo" >> "${FORGEJO_PATH}" |
| 94 |
|
| 95 |
- name: Install Node.js |
| 96 |
run: | |
| 97 |
if [[ -f "package-lock.json" ]]; then |
| 98 |
echo "Installing Node.js ${NODE_VERSION}..." |
| 99 |
curl -sfL --output-dir "${{ runner.temp }}" -O "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz" |
| 100 |
tar -C "${HOME}/.local" -xf "${{ runner.temp }}/node-v${NODE_VERSION}-linux-x64.tar.gz" |
| 101 |
echo "${HOME}/.local/node-v${NODE_VERSION}-linux-x64/bin" >> "${FORGEJO_PATH}" |
| 102 |
fi |
| 103 |
|
| 104 |
- name: Log tool versions |
| 105 |
run: | |
| 106 |
echo "Logging tool versions..." |
| 107 |
command -v sass &> /dev/null && echo "Dart Sass: $(sass --version)" || echo "Dart Sass: not installed" |
| 108 |
command -v go &> /dev/null && echo "Go: $(go version)" || echo "Go: not installed" |
| 109 |
command -v hugo &> /dev/null && echo "Hugo: $(hugo version)" || echo "Hugo: not installed" |
| 110 |
command -v node &> /dev/null && echo "Node.js: $(node --version)" || echo "Node.js: not installed" |
| 111 |
|
| 112 |
- name: Configure Git |
| 113 |
run: | |
| 114 |
echo "Configuring Git..." |
| 115 |
git config --global core.quotepath false |
| 116 |
|
| 117 |
- name: Fetch full Git history |
| 118 |
run: | |
| 119 |
if [[ $(git rev-parse --is-shallow-repository) == true ]]; then |
| 120 |
echo "Fetching full Git history..." |
| 121 |
git fetch --unshallow |
| 122 |
fi |
| 123 |
|
| 124 |
- name: Initialize Git submodules |
| 125 |
run: | |
| 126 |
if [[ -f .gitmodules ]]; then |
| 127 |
echo "Initializing Git submodules..." |
| 128 |
git submodule update --init --recursive |
| 129 |
fi |
| 130 |
|
| 131 |
- name: Install Node.js dependencies |
| 132 |
run: | |
| 133 |
if [[ -f package-lock.json ]]; then |
| 134 |
echo "Installing Node.js dependencies..." |
| 135 |
npm ci |
| 136 |
fi |
| 137 |
|
| 138 |
- name: Cache restore |
| 139 |
id: cache-restore |
| 140 |
uses: actions/cache/restore@v6 |
| 141 |
with: |
| 142 |
path: ${{ runner.temp }}/.cache/hugo |
| 143 |
key: hugo-${{ forgejo.run_id }} |
| 144 |
restore-keys: hugo- |
| 145 |
|
| 146 |
- name: Build |
| 147 |
run: | |
| 148 |
echo "Building the project..." |
| 149 |
hugo build \ |
| 150 |
--gc \ |
| 151 |
--minify \ |
| 152 |
--cacheDir "${{ runner.temp }}/.cache/hugo" |
| 153 |
|
| 154 |
- name: Cache save |
| 155 |
uses: actions/cache/save@v6 |
| 156 |
with: |
| 157 |
path: ${{ runner.temp }}/.cache/hugo |
| 158 |
key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 159 |
|
| 160 |
- name: Deploy |
| 161 |
uses: actions/git-pages@v2 |
| 162 |
with: |
| 163 |
site: ${{ env.HUGO_BASEURL }} |
| 164 |
token: ${{ forgejo.token }} |
| 165 |
source: public/ |
| 166 |
|
| 167 |
- name: Print base URL |
| 168 |
run: | |
| 169 |
echo "Base URL: ${HUGO_BASEURL}" |
| 170 |
``` |
| 171 |
|
| 172 |
Step 3 |
| 173 |
: In the project configuration file in the root of your local Git repository, set the location of the image cache to the [`cacheDir`][] as shown below. |
| 174 |
|
| 175 |
{{< code-toggle file=hugo copy=true >}} |
| 176 |
[caches.images] |
| 177 |
dir = ':cacheDir/images' |
| 178 |
{{< /code-toggle >}} |
| 179 |
|
| 180 |
See [configure file caches][] for more information. |
| 181 |
|
| 182 |
Step 4 |
| 183 |
: Commit the changes to your local Git repository and push to your Codeberg repository. |
| 184 |
|
| 185 |
Step 5 |
| 186 |
: From Codeberg's main menu, choose **Actions**. You will see something like this: |
| 187 |
|
| 188 |
 |
| 189 |
|
| 190 |
Step 6 |
| 191 |
: When Codeberg has finished building and deploying your site, the color of the status indicator will change to green. |
| 192 |
|
| 193 |
 |
| 194 |
|
| 195 |
Step 7 |
| 196 |
: Click on the commit message as shown above. Under the "Print base URL" step, you will see a link to your live site. |
| 197 |
|
| 198 |
 |
| 199 |
|
| 200 |
In the future, whenever you push a change from your local Git repository, Codeberg Pages will rebuild and deploy your site. |
| 201 |
|
| 202 |
## Base URL |
| 203 |
|
| 204 |
Codeberg Pages site URLs take one of three forms: |
| 205 |
|
| 206 |
Site type|URL|Notes |
| 207 |
:--|:--|:-- |
| 208 |
Project site|`https://owner.codeberg.page/repo/`|Default; no workflow changes needed |
| 209 |
User/organization site|`https://owner.codeberg.page/`|Repository must be named `pages` |
| 210 |
Custom domain|`https://custom-domain.org/`|Requires additional workflow changes; see below |
| 211 |
|
| 212 |
The `HUGO_BASEURL` environment variable in the example workflow targets a project site, automatically computing the URL from the repository owner's username and repository name. For other configurations, adjust the workflow as described below. |
| 213 |
|
| 214 |
For a user/organization site, set `HUGO_BASEURL` to: |
| 215 |
|
| 216 |
```text |
| 217 |
https://${{ forgejo.event.repository.owner.username }}.codeberg.page/ |
| 218 |
``` |
| 219 |
|
| 220 |
For a custom domain, set `HUGO_BASEURL` to: |
| 221 |
|
| 222 |
```text |
| 223 |
https://custom-domain.org/ |
| 224 |
``` |
| 225 |
|
| 226 |
And add the `server` parameter to the Deploy step: |
| 227 |
|
| 228 |
```yaml |
| 229 |
- name: Deploy |
| 230 |
uses: actions/git-pages@v2 |
| 231 |
with: |
| 232 |
site: ${{ env.HUGO_BASEURL }} |
| 233 |
server: codeberg.page |
| 234 |
token: ${{ forgejo.token }} |
| 235 |
source: public/ |
| 236 |
``` |
| 237 |
|
| 238 |
See the [Codeberg documentation][] for more information. |
| 239 |
|
| 240 |
## Choosing a runner |
| 241 |
|
| 242 |
Codeberg offers three [hosted runners][], each with a corresponding `-lazy` variant that may have longer queue times but helps balance load on shared infrastructure. The example workflow above uses `codeberg-small` for these reasons: |
| 243 |
|
| 244 |
Runner|Notes |
| 245 |
:--|:-- |
| 246 |
`codeberg-tiny`|The 2-minute maximum runtime is insufficient for image processing. Hugo caches processed images, but the initial run to prime that cache can exceed this limit. |
| 247 |
`codeberg-small`|A reasonable middle ground for projects with a moderate amount of image processing. Queue times can exceed 30 minutes under heavy load. If your deployment is not time-sensitive, consider using `codeberg-small-lazy` instead. |
| 248 |
`codeberg-medium`|Demand for these runners is high, making queue times impractical for routine deployments. |
| 249 |
|
| 250 |
## Related resources |
| 251 |
|
| 252 |
For more information on hosting and managing your site with Codeberg Pages, consult the official documentation: |
| 253 |
|
| 254 |
- [General documentation][] |
| 255 |
- [Custom domain setup][] |
| 256 |
|
| 257 |
[Codeberg documentation]: https://docs.codeberg.org/codeberg-pages/forgejo-actions/ |
| 258 |
[Custom domain setup]: https://docs.codeberg.org/codeberg-pages/using-custom-domain/ |
| 259 |
[General documentation]: https://docs.codeberg.org/codeberg-pages/ |
| 260 |
[`cacheDir`]: /configuration/all/#cachedir |
| 261 |
[configure file caches]: /configuration/caches/ |
| 262 |
[hosted runners]: https://codeberg.org/actions/meta#available-runners |
| 263 |
[remote]: https://git-scm.com/docs/git-remote |