Deployment with GitHub Actions & GitHub Pages
Set up a CICD pipeline for your 11ty, DecapCMS, and TailwindCSS template
Setting up GitHub Pages
Now that your repository is created, we can enable GitHub Pages. Go to the page of the repository you've just created and click on the Settings button on the top right.
Click on the Pages button on the sidebar menu and select your default branch in the dropdown, this is probably
mainormaster, leave/(root)as the selected folder. Click on save .
Build your website with GitHub Actions
By default, GitHub pages uses Jekyll to generate websites. In our case, we're using 11ty, so we want to inform GitHub Pages. To do so, create an empty file called
.nojekylland put it in the root directory.Create
.githubfolder in therootdirectory, and inside that folder, create another folder calledworkflows. In this folder, we put the workflows which GitHub Actions execute.We're going to create two workflows:
Create a file with the namebuild.yml
This workflow performs a build when a pull request is created. If your default branch is something other thanmainmake sure to change this in thebranchesarray.
This workflow only performs a build and doesn't deploy your changes.
build.yml
name: Build on PR
on:
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['14.17.6']
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install packages
run: npm ci
- name: Run development build
run: npm run build:dev
Next create build-and-deploy.yml.
This workflow builds and deploys our website to GitHub Pages when a push is done on the main branch, for example merging a pull request.
name: Build & Deploy
on:
push:
branches: ['main']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['14.17.6']
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install packages
run: npm ci
- name: Run production build
run: npm run build:prod
- name: Deploy to gh-pages
uses: peaceiris/actions-gh-pages@v3
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
publish_dir: _site
- Before we can use this workflow we'll need to create an ACTIONS_DEPLOY_KEY. This key is needed to be able to deploy our generated code to GitHub Pages. Follow the steps in these docs to create an ACTIONS_DEPLOY_KEY .
Once that is done we can push all the changes to our repository
Now head over to your repository on GitHub and click on the Actions tab. You should see the
Build & Deployworkflow being executed, once that is done another workflow calledpages-build-deploymentis triggered and deploys the generated website to GitHub Pages.After the
Build & Deployworkflow is executed a new branch calledgh-pagesis auto-created. In this branch the generated output of your 11ty site will be stored. To be able to host the website properly we need to inform GitHub Pages about this.
Navigate to the Settings tab and select Pages in the list on the left. Change the branch from which your GitHub Pages site is currently being built togh-pagesandrootand hit save.The
pages-build-deploymentworkflow will be automatically triggered again and after it has finished you can navigate to the URL where your website is published to see the final result.
Additional Resources:
How to Deploy your Eleventy Website to GitHub Pages with GitHub Actions