From ed05614e1d378c5b2f25ee06135de02ad75999d8 Mon Sep 17 00:00:00 2001 From: Peter Prumbach Date: Mon, 1 Aug 2022 14:56:40 +0200 Subject: [PATCH] Add example for hugo and codeberg pages (#5) An example to publish pages built with Hugo on Codeberg Pages. Thanks to [jwildeboer](https://codeberg.org/jwildeboer) for the inspiration and the explanation. Co-authored-by: Peter Prumbach Reviewed-on: https://codeberg.org/Codeberg-CI/examples/pulls/5 Co-authored-by: Peter Prumbach Co-committed-by: Peter Prumbach --- Hugo/hugo.yml | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + 2 files changed, 58 insertions(+) create mode 100644 Hugo/hugo.yml diff --git a/Hugo/hugo.yml b/Hugo/hugo.yml new file mode 100644 index 0000000..6219fad --- /dev/null +++ b/Hugo/hugo.yml @@ -0,0 +1,57 @@ +# hugo.yml +# +# Takes a repository with hugo source, generates the static site and +# pushes the result to codeberg pages +# +# Needs a codeberg access token (cbtoken) as secret in woodpecker config +# Also uses another secret (cbmail) with email address for git config +# +# 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 +# +# USERNAME must be replaced with your Codeberg username +# REPO_NAME must be replaced with your source code repository +# HUGO_OUTPUT must be replace with your static files output folder configured in Hugo +# + +# Recursive cloning is used to fully clone the themes given as Git submodules +clone: + git: + image: woodpeckerci/plugin-git + settings: + recursive: true + +pipeline: + # Build hugo static files + build: + image: klakegg/hugo + when: + event: [pull_request, push] + + publish: + image: bitnami/git + # Must be set in woodpecker configuration + secrets: [ cbmail, cbtoken ] + commands: + # Git configuration + - git config --global --add safe.directory /woodpecker/src/codeberg.org/USERNAME/REPO_NAME/HUGO_OUTPUT + - git config --global user.email "$CBMAIL" + - git config --global user.name "Woodpecker CI" + - git config --global init.defaultBranch pages + - git clone -b pages https://codeberg.org/USERNAME/REPO_NAME.git + # Avoid permission denied errors + - chmod -R a+w REPO_NAME + # Copy build step output to repository folder + - cp -a HUGO_OUTPUT/* REPO_NAME/ + ### Only needed for custom domains + - cp domains REPO_NAME/.domains + ### + - cd REPO_NAME + - git remote set-url origin https://$CBTOKEN@codeberg.org/USERNAME/REPO_NAME.git + - git add --all + # Commit all static files with pipeline started timestamp + - git commit -m "Woodpecker CI ${CI_BUILD_CREATED}" + - git push + when: + event: push + branch: main \ No newline at end of file diff --git a/README.md b/README.md index 16cafcb..7b05062 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Pull requests are accepted/welcome. | [C/make.yml](C/make.yml) | C | Make | Simple ci for building a Make based C project | | [golang/build.yml](golang/build.yml) | golang | golang | Simple ci for building and test a Go project | | [golang/build-docker.yml](golang/build-docker.yml) | golang | golang / kaniko | CI to build golang project and build various docker container and publish them on DockerHub | +| [Hugo/hugo.yml](Hugo/hugo.yml) | Markdown | Hugo | CI step to build static website files and publish them to Codeberg Pages with Hugo | # More: https://codeberg.org/explore/repos?q=woodpecker-ci&topic=1