Publish to Forgejo
Publishing methods
git-pages serves generated content from a repository named after the address. This allows users the flexibility in choosing where Antora runs:
-
Publish a pre-built site
Run Antora on another machine and commit the output to the site repository. -
Publish with Actions
Run Antora from a workflow in the source repository, which commits the output to the site repository.
Both methods share the pages server, the site repository, and the playbook settings.
Pages server
Both methods require a git-pages server with a wildcard entry for the Forgejo instance in its configuration file:
[[wildcard]]
domain = "<pages-domain>" (1)
clone-url = "https://<forgejo-host>/<user>/<project>.git" (2)
index-repo = "<user>.<pages-domain>" (3)
index-repo-branch = "main"
| 1 | git-pages serves <user>.<pages-domain> for each Forgejo user.
DNS MUST resolve the domain and its subdomains to the git-pages server. |
| 2 | git-pages clones from this URL template without credentials. |
| 3 | The site repository of each user carries the name of the site address. |
The Forgejo instance MUST meet these conditions in its app.ini file:
-
The
[service]section MUST NOT setREQUIRE_SIGNIN_VIEW = true. This setting denies the anonymous clone that git-pages performs. -
The
[webhook]section MUST list the git-pages host inALLOWED_HOST_LISTwhen the host has a private address. The default value,external, blocks delivery to private addresses.
The Forgejo host MUST trust the TLS certificate of the git-pages server. A server with a self-signed certificate requires its root certificate in the system trust store of the Forgejo host.
Site repository
Create a public repository named <user>.<pages-domain> with main as the default branch, then add a webhook that notifies git-pages of each push:
-
Open the site repository and select .
-
Select .
-
Set Target URL to
https://<user>.<pages-domain>/. -
Set POST content type to
application/json. -
Under Trigger on, select Push events.
-
Set Branch filter to
main. -
Select Add webhook.
Playbook settings
Both methods require the playbook to set these keys:
site:
url: https://<user>.<pages-domain> (1)
content:
sources:
- url: .
branches: HEAD
edit_url: https://<forgejo-host>/<user>/<source-repository>/src/branch/{refname}/{path} (2)
urls:
latest_version_segment: latest
latest_version_segment_strategy: replace (3)
redirect_facility: static (4)
| 1 | The site URL MUST be the git-pages address. |
| 2 | Antora derives the Edit this Page URL only for GitHub, GitLab, Bitbucket, and Pagure hosts.
A Forgejo content source requires an explicit edit_url. |
| 3 | A latest version URL requires the replace strategy.
With the static facility, Antora ignores redirect:from and treats redirect:to as replace, as the latest version segment strategy documentation describes. |
| 4 | The static facility writes an HTML redirect page for each page alias and for the site start page. |
Publish a pre-built site
This method allows a user to run Antora on any machine, such as a workstation or an external CI system, and commit the generated site to the site repository. The benefit of this method is that it requires no runner and no access token.
Requirements
Publishing a pre-built site requires push access to the site repository.
Push access requires either SSH or HTTPS access.
-
Add an SSH key by selecting from the user menu.
-
Add an HTTPS token by creating an access token limited to the site repository:
-
Select from the user menu, then select New access token.
-
Under Repository and organization access, select Specific repositories and add the site repository.
-
Under Select permissions, set repository to Read and write.
-
Select Generate token and copy the token value, which Forgejo displays only once.
-
Build and commit the site
Build the site and publish it from a clone of the site repository:
-
Run Antora with the
CIenvironment variable set:$ CI=true npx antora antora-playbook.yml
Without the CIvariable, Antora resolves Edit this Page links to afile://URL for any page sourced from the worktree, which exposes the local path of the build machine. See default edit URL for details. -
Clone the site repository with its SSH or HTTPS URL, which Forgejo shows on the repository page:
$ git clone <site-repository-url> site-repo
-
Replace the contents of the clone with the generated site. The
findcommand removes every entry except the .git directory. Files that the new build no longer produces disappear from the site.$ find site-repo -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + $ cp -R build/site/. site-repo/ -
Commit and push the site:
$ cd site-repo $ git add -A $ git commit -m "Deployed site" $ git push origin main
The push fires the webhook, and git-pages serves the new commit at https://<user>.<pages-domain>/.
Publish with Actions
This method allows Antora to run on a Forgejo Runner using a workflow in the source repository, which commits the generated site to the site repository.
Requirements
Publishing with Forgejo Actions requires:
-
A Forgejo Runner registered with the instance, the user, or the source repository. The runner MUST carry the label that the
runs-onkey of the workflow names. The example workflow namesdocker. -
Forgejo Actions enabled on the source repository. The setting is Enable integrated CI/CD pipelines with Forgejo Actions under .
Create the source repository
Create a second repository for the Antora playbook, the content sources, and the workflow file.
Create an access token
The workflow authenticates to the site repository with an access token. A token limited to specific repositories grants access only to those repositories. The token SHOULD be limited to the site repository.
-
Select from the user menu, then select New access token.
-
Under Repository and organization access, select Specific repositories and add the site repository.
-
Under Select permissions, set repository to Read and write.
-
Select Generate token and copy the token value, which Forgejo displays only once.
Store the token
The workflow reads the token from an Actions secret on the source repository.
-
Open the source repository and select .
-
Select Add secret.
-
Name the secret
SITE_REPO_TOKEN, paste the token as its value, and confirm.
Add the workflow
The .forgejo/workflows/publish.yml file in the source repository runs on every push to main.
Its job performs these actions:
-
Checks out the source repository with its full history.
-
Installs the locked dependencies.
-
Runs Antora.
-
Clones the site repository with the token as the password of the repository owner.
-
Replaces the contents of the clone with the generated site.
-
Commits and pushes the result.
on:
push:
branches:
- main
env:
PAGES_DOMAIN: pages.example.com
jobs:
publish:
runs-on: docker
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npm ci
- run: npx antora antora-playbook.yml
- name: Commit the site to the site repository
env:
SITE_REPO_TOKEN: ${{ secrets.SITE_REPO_TOKEN }}
run: |
OWNER="${{ forgejo.repository_owner }}"
SERVER="${{ forgejo.server_url }}"
SITE_REPO="${SERVER#*://}/${OWNER}/${OWNER}.${PAGES_DOMAIN}.git"
git clone --depth 1 \
"${SERVER%%://*}://${OWNER}:${SITE_REPO_TOKEN}@${SITE_REPO}" site-repo
find site-repo -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} +
cp -R build/site/. site-repo/
cd site-repo
git add -A
if git diff --cached --quiet; then echo "No site changes"; exit 0; fi
AUTHOR_NAME="$(git -C .. log -1 --format=%an)"
AUTHOR_EMAIL="$(git -C .. log -1 --format=%ae)"
git -c user.name="$AUTHOR_NAME" -c user.email="$AUTHOR_EMAIL" \
commit -m "Deployed: ${{ forgejo.sha }}"
git push origin HEAD:main
The PAGES_DOMAIN variable MUST match the domain key of the git-pages wildcard entry.
Deploy the site
Commit these files to the source repository and push to main:
-
The playbook.
-
The content.
-
package.json and package-lock.json.
-
.forgejo/workflows/publish.yml.
The push starts the workflow.
The workflow commits to the site repository, the commit fires the webhook, and git-pages serves the site at https://<user>.<pages-domain>/.
Hosting behavior
git-pages serves the files committed to the site repository and reads no server configuration from the playbook.
Visibility
git-pages clones the site repository without credentials. The site repository and the generated site are public to anyone who reaches the Forgejo instance and the git-pages server.
git-pages accepts the webhook without a shared secret.
It matches the request host against the wildcard entry and clones only the repository that the clone-url template names.
Server behavior
git-pages answers requests for the generated files as this table describes.
| Request | Response |
|---|---|
A path with uppercase letters |
The file as committed. Paths are case-sensitive. A request that differs only in case returns 404. |
A directory under |
The file with the correct content type. |
A directory without a trailing slash |
A 302 redirect to the same path with a trailing slash, then the directory’s |
A missing path |
A 404 response with the 404.html page that Antora generates. |
Any file |
A |