ci-examples/NodeJS/.woodpecker.yaml
2024-11-21 13:57:15 +00:00

66 lines
2.1 KiB
YAML

# NodeJS / 11ty on Woodpecker to codeberg pages
#
# https://cjerrington.codeberg.page/eleventy-base-blog-site/blog/codebergpagesbuild/
#
# This file would typically be .woodpecker.yml in the root of your repository.
#
# Takes a repository with 11ty source, generates the static site and
# pushes the result to codeberg pages
#
#
# SECRETS
# https://woodpecker-ci.org/docs/usage/secrets
# CBTOKEN needs a codeberg access token as secret in woodpecker config
# CBMAIL with email address for git config
# SOURCEREPO must be replaced with the source repo
# DESTREPO must be replaced with the target codeberg pages repo
# CBUSERNAME must be replaced with the user/org
#
#
# We also assume a domains file in the source repo that gets copied to
# .domains in the target repo so codeberg pages works for custom domains
#
steps:
build:
when:
event: [push, pull_request]
# Use the official jekyll build container
image: node
environment:
# secrets must be set in Woodpecker configuration
CBTOKEN:
from_secret: cbtoken
CBMAIL:
from_secret: cbmail
CBUSERNAME:
from_secret: cbusername
SOURCEREPO:
from_secret: sourcerepo
DESTREPO:
from_secret: destrepo
commands:
# Avoid permission denied errors
- chmod -R a+w .
# Set up git in a working way
- git config --global --add safe.directory /woodpecker/src/codeberg.org/$CBUSERNAME/$SOURCEREPO/_site
- git config --global user.email "$CBMAIL"
- git config --global user.name "CI Builder"
# clone and move the target repo
- git clone -b pages https://codeberg.org/$CBUSERNAME/$DESTREPO.git _site
- chmod -R a+w _site
- cd _site
# Prepare for push
- git remote set-url origin https://$CBTOKEN@codeberg.org/$CBUSERNAME/$DESTREPO.git
- cd ..
# Run 11ty build stage
- npm install
- npm run build
# Only needed for custom domains
#- cp domains _site/.domains
# Push to target
- cd _site
- git add --all
- git commit -m "Woodpecker CI 11ty Build at $( env TZ=America/Chicago date +"%Y-%m-%d %X %Z" )"
- git push -u origin pages