Deploys for static sites or web apps made easy with GitHub Actions
A generic but elegant CI flow for deploying a site to Github Pages - this is triggered on a push to master and runs on Github Actions - docs.
This workflow is targeted at a static site like Hexo or a single-page applciation like React project. It doesn't matter what the language is as long as your build steps results in a public directory which can be served on Github Pages.
Skip ahead to the main.yml workflow file.
The flow here is a generic but eleganic build and deploy flow. It doesn't even mention Hexo specifically.
It works great - see it here in action:
- Hexo
- michaelcurrin.github.io/hexo-quickstart repo with workflow file as in this gist.
- React project
- MichaelCurrin/react-create-app-quickstart repo with workflow file.
Note that all edits must be done on your master
branch and the site will be committed to the gh-pages
branch for you.
- Copy the YAML file content to your project at this path. Please keep the reference linking back to this repo.
.github/workflows/main.yml
- Customize the build steps.
- Such as change
yarn
tonpm
. Or usepip
or usemake
commands.
- Such as change
- Optionally add a test step.
- For example:
- name: Test 🚨 run: yarn test
- For example:
- Change the
publish_dir
value to match the location of your output directory. e.g.public
,dist
orbuild
. - Commit the workflow file.
- Check your Actions tab to see that it runs and is successful.
- Setup GH Pages
- Go to your Github repo's Settings and enable to Github Pages on your site. You need to switch to another setting and back to
gh-pages
, then your GH Pages URL will be shown.
- Go to your Github repo's Settings and enable to Github Pages on your site. You need to switch to another setting and back to
Your GH Pages site is published and will be rebuilt whenever a commit is made to master
.
No local deploy step needed! 🎉