Migrating to CircleCI
13 Feb 2023I spent a good portion of the last year freelancing at Plainspoken Digital, and although it was a thrilling experience, it left me without much time to keep the site updated. When I came back to it, Travis-CI had changed their prices and it was no longer economical free to run the build like I described in an early post.
After a really quick search I landed on Circle CI. I should have searched more, but truthfully all I need is a simple and well documented CI/CD tool to replace Travis, and allow my website to build before hosting to github pages (this allows you to take leverage non-Github-pages supported Jekyll plugins).
My use case was much simpler than what they outlined in their guide, so I pieced together a solution from the CircleCI guide on GitHub pages, and this Medium guide by Matthias Bruns, which was helpful. Below is a rough outline of my steps:
- Create an account with CircleCI and connect your account with GitHub. I don’t believe I needed to follow any additional authentication steps past the prompts.
- In your repository, create a new folder called
.circleci
in the root directory, and add two blank files:config.yml
anddeploy.sh
. CircleCI knows to look in this folder. - Follow the set up instructions within the CircleCI interface for your GitHub-pages repo. I clicked the
Fast:
option and relied on my existing config. - In the config.yml file I put the following code -
version: 2
jobs:
deploy:
docker:
- image: circleci/ruby:latest
environment:
USER_NAME: ${USER_NAME}
USER_EMAIL: ${USER_EMAIL}
steps:
- checkout
- run:
name: install dependencies
command: |
gem install bundler
bundle update --bundler
- run: bundle install --path=vendor/bundle && bundle clean
- run: JEKYLL_ENV=production bundle exec jekyll build
- deploy:
name: Deploy Release to GitHub
command: |
bash .circleci/deploy.sh
workflows:
version: 2
build:
jobs:
- deploy:
filters:
branches:
only:
- gh-pages
- In the deploy.sh script, I put the following code -
git config user.name "$USER_NAME"
git config user.email "$USER_EMAIL"
git checkout gh-pages
git pull origin gh-pages
find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' ! -name '.circleci' -exec rm -rf {} \;
mv _site/* .
rm -R _site/
git add -fA
git commit --allow-empty -m "$(git log source -1 --pretty=%B)"
git push -f origin master
echo "deployed successfully"
After that, I pushed to the gh-pages
branch that CircleCI and GitHub Pages both expect, with everything more or less working smoothly from there!