-
Notifications
You must be signed in to change notification settings - Fork 117
Description
I have tested the steps below but would like to check with others to ensure it works for all. Also if you do it on a test repo, it would be great if you could add me as collaborator so that I can try to trigger an update (without having set up the secrets myself) and check that that works too (sorry I'm still a bit new to this Github actions business).
Thanks a lot!
(cross ref: #379)
Below I assume you already have a local folder that works with Franklin.
Project website
This is for a repo username/repo which will lead to the page username.github.io/repo/.
1 Generate a key
In your terminal
ssh-keygen -N "" -f franklin
This will create two files franklin and franklin.pub.
2 Github settings
- go to
github.com/username/repo/settings/keys - click on Add deploy key and name it
FRANKLIN(it doesn't matter) - copy the content of the
franklin.pubfile created earlier, one way to do so in your terminal:cat franklin.puband copy the result without whitespaces- on mac,
cat franklin.pub | pbcopycopies the content directly to your clipboard
- paste that in the appropriate box of the deploy key page on github
- go to
github.com/username/repo/settings/secrets - click on Add a new secret and name it
DEPLOY_KEY(it does matter) - copy the content of the
franklinfile created earlier and paste it in the box
You can now remove the two files created:
rm franklin
rm franklin.pub
3 Deploy action
Edit your .github/workflows/deploy.yml file (or create one if you don't have one already) to the following:
name: Build and Deploy
on:
push:
# NOTE: For a **project** site (username.github.io/project/), push things
# to the **master** branch and make sure to set the line below to
# `- master`; also, at the end of the file, change to `BRANCH: gh-pages`
# For a **personal** site (username.github.io/), push things to a **dev**
# branch and make sure to set the line below to `- dev` this is because
# for user pages GitHub pages **requires** the deployment to be on the
# master branch; also, at the end of the file, change to `BRANCH: master`
branches:
- master
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Install SSH Client
uses: webfactory/ssh-agent@v0.2.0
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
# Python is necessary for pre-rendering steps as well as to install
# matplotlib which is necessary if you intend to use PyPlot. If you do
# not, then you can remove the `run: pip install matplotlib` line.
- name: Install python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install matplotlib # if you use PyPlot this is needed
- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.3.0
# This ensures that NodeJS and Franklin are loaded then it installs
# highlight.js which is needed for the prerendering step.
# Then the environment is activated and instantiated to install all
# Julia packages which may be required to successfully build your site.
# NOTE: the last line should be `optimize()`, you may want to give it
# specific arguments, see the documentation or ?optimize in the REPL.
- run: julia -e '
using Pkg; Pkg.add(["NodeJS", "Franklin"]);
using NodeJS; run(`$(npm_cmd()) install highlight.js`);
using Franklin;
Pkg.activate("."); Pkg.instantiate();
optimize()'
- name: Build and Deploy
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
SSH: true
# Set this to `BRANCH: gh-pages` for a **project** page and to
# `BRANCH: master` for a **personal** page
BRANCH: gh-pages
FOLDER: __siteyou can also edit your .gitignore and add __site/ to it.
Now push all this (on master). Your site should appear in a couple of minutes.
Personal website
This is for a repo username/username.github.io which will lead to the page username.github.io/.
The steps (1) and (2) are the same as for the project pages.
(2b) Setting up the branches
For a personal page, your source files must be on a dev branch, the master branch is only used for deployment. To do this:
git checkout -b dev
git add -A && git commit -am "moving files" && git push -u origin dev
git checkout master
Clear everything apart from the .git folder, either manually or for instance with rm -r !(.git) and push that cleared branch.
git add -A && git commit -am "cleaning up" && git push
Then get back to the dev branch and use only that one.
git checkout dev
3 Deploy action
Edit your .github/workflows/deploy.yml file (or create one if you don't have one already) to the following; there are two differences:
- trigger on push to
dev - deploy to
master
name: Build and Deploy
on:
push:
# NOTE: For a **project** site (username.github.io/project/), push things
# to the **master** branch and make sure to set the line below to
# `- master`; also, at the end of the file, change to `BRANCH: gh-pages`
# For a **personal** site (username.github.io/), push things to a **dev**
# branch and make sure to set the line below to `- dev` this is because
# for user pages GitHub pages **requires** the deployment to be on the
# master branch; also, at the end of the file, change to `BRANCH: master`
branches:
- dev
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
persist-credentials: false
- name: Install SSH Client
uses: webfactory/ssh-agent@v0.2.0
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
# Python is necessary for pre-rendering steps as well as to install
# matplotlib which is necessary if you intend to use PyPlot. If you do
# not, then you can remove the `run: pip install matplotlib` line.
- name: Install python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install matplotlib # if you use PyPlot this is needed
- name: Install Julia
uses: julia-actions/setup-julia@v1
with:
version: 1.3.0
# This ensures that NodeJS and Franklin are loaded then it installs
# highlight.js which is needed for the prerendering step.
# Then the environment is activated and instantiated to install all
# Julia packages which may be required to successfully build your site.
# NOTE: the last line should be `optimize()`, you may want to give it
# specific arguments, see the documentation or ?optimize in the REPL.
- run: julia -e '
using Pkg; Pkg.add(["NodeJS", "Franklin"]);
using NodeJS; run(`$(npm_cmd()) install highlight.js`);
using Franklin;
Pkg.activate("."); Pkg.instantiate();
optimize()'
- name: Build and Deploy
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
SSH: true
# Set this to `BRANCH: gh-pages` for a **project** page and to
# `BRANCH: master` for a **personal** page
BRANCH: master
FOLDER: __siteyou can also edit your .gitignore and add __site/ to it.
Now push all this (on dev). Your site should appear in a couple of minutes.
Finally
It's helpful to change the default branch for the repo on Github by doing: Settings > Branches, pick dev and Update.
Feedback
Let me know if it works for you, if you think some steps can be simplified / better explained etc.
Thanks!
Edit: notes to self:
lunrhook is missing, basically it should not beoptimizethe last step but rather something likepublish(maybe nameddeploy) without the git operations.- removed
node-setupsinceNodeJS.jlinstalls its own version (thanks to Eric Hanson)