I am constructing a pipeline to deploy my Hugo blog hosted on GitHub Pages.
I do this using two repos, one is a private repo that hosts the Hugo source and the other is a public repo that contains the generated static site.
I use git submodules to attach the theme and public site repos to the private repo.
In CircleCI I am using the Orb circleci/hugo to test and build and a custom deploy job.
The Orb provides a feature to use workspace and I wanted to use it to attach the entire checkout directory to the deploy job so that i can use git commands to push the latest build (from the Orb) to the master branch of the static site submodule.
My config.yml
looks like this:
jobs:
deploy:
docker:
- image: cibuilds/base
working_directory: /home/circleci
steps:
- run: apk update && apk add git
- attach_workspace:
at: project
- run: git config --global user.email "noreply@github.com" && git config --global user.name "CircleCI"
- run: cd /home/circleci/project/public && git add --all && git commit -m "Automated build and publish site $(date)" && git push origin master
orbs:
hugo: circleci/hugo@0.6.0
version: 2.1
workflows:
main:
jobs:
- hugo/build:
hugo-extra-flags: -t my_theme
html-proofer: true
version: latest
- deploy:
filters:
branches:
only: master
requires:
- hugo/build
I got the working directory from the successful output of the hugo/build
job:
if [ -e /home/circleci/project/.git ]
then
cd /home/circleci/project
git remote set-url origin "$CIRCLE_REPOSITORY_URL" || true
else
mkdir -p /home/circleci/project
cd /home/circleci/project
git clone "$CIRCLE_REPOSITORY_URL" .
fi
The Orb docs contains some rather confusing instructions…
The Job source says:
- when:
condition: << parameters.persist-to-workspace >>
steps:
- persist_to_workspace:
paths:
- << parameters.destination >>
root: << parameters.source >>
But the docs says:
persist-to-workspace Whether to persist generated files to a CircleCI Workspace. This uses
parameters.source
as root andparameters.publishdir
as the path.
Also, I don’t know where to put the parameter in the config.yml
, is it in the very base structure, as indicated by the above?
But according to the docs:
Parameters are declared by name under a job, command, or executor.
I’ve tried putting it in a few places but I can’t get it working.
The error is in this run step in the deploy job:
#!/bin/bash -eo pipefail cd /home/circleci/project/public && git add --all && git commit -m "Automated build and publish site $(date)" && git push origin master
fatal: not a git repository: /home/circleci/project/public/../.git/modules/public Exited with code exit status 128
CircleCI received exit code 128
Any help or advice would be much appreciated.