Skip to content

Instantly share code, notes, and snippets.

@mrkrstphr
Last active February 5, 2019 13:17
Show Gist options
  • Save mrkrstphr/2e79e55229b2ef7a343a to your computer and use it in GitHub Desktop.
Save mrkrstphr/2e79e55229b2ef7a343a to your computer and use it in GitHub Desktop.
Deploying Sculpin Sites to GitHub Pages

Deploying Sculpin Sites to GitHub Pages

I wanted to be able to use Sculpin to generate GitHub pages. Here's what I did...

  1. Created a super awesome Sculpin site from the Sculpin Blog Skeleton

  2. Make sure everything is under version control in my master branch (except things that shouldn't be. see the .gitignore)

  3. Updated publish.sh:

    #!/bin/bash
    
    if [ $# -ne 1 ]; then
        echo "usage: ./publish.sh \"commit message\""
        exit 1;
    fi
    
    sculpin generate --env=prod
    
    git stash
    git checkout gh-pages
    
    cp -R output_prod/* .
    rm -rf output_*
    
    git add *
    git commit -m "$1"
    git push origin --all
    
    git checkout master
    git stash pop
    
  4. Now, when I need to publish, I simply run ./publish.sh "commit message".

publish.sh will:

  1. generate the site using sculpin generate
  2. Stash the changes to master, if any
  3. Checkout the gh-pages branch
  4. Move the generated site to the root of the project
  5. git add -A to add all the files
  6. git commit -m "$1" which includes whatever commit message you passed to ./publish.sh
  7. git push origin --all to push changes to both master and gh-pages to GitHub
  8. Checkout master, and pop the stash to get any stashed changes to master back

It works pretty fantastically. You can checkout my sample project to see how it works.

Organization/User Pages

The process described above works for project sites, because project sites use a gh-pages branch for the website. Organization and user pages, however, use the master branch for the site of a repository named [organization].github.io.

In the case of my sample project, I actually use a branch called drafts to do the Sculpin work, which then "publishes" the changes to master, so that the website actually renders correctly.

The publish.sh looks like this:

#!/bin/bash

if [ $# -ne 1 ]; then
    echo "usage: ./publish.sh \"commit message\""
    exit 1;
fi

sculpin generate --env=prod

git stash
git checkout master

cp -R output_prod/* .
rm -rf output_*

git add *
git commit -m "$1"
git push origin --all

git checkout drafts
git stash pop

Slightly different, same concept.

Thanks to @beausimensen for the --env=prod suggestion.

@itsdarrylnorris
Copy link

You can checkout my sample project to see how it works.

Does not work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment