Skip to content

Commit 5c0e9aa

Browse files
committed
add cd tutorial for deploying hugo site
1 parent 488a653 commit 5c0e9aa

File tree

8 files changed

+124
-0
lines changed

8 files changed

+124
-0
lines changed

action/deploy_hugo/Dockerfile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM klakegg/hugo:0.83.1-debian
2+
3+
RUN apt-get update && apt-get install -y git
4+
5+
COPY action.sh /action.sh
6+
7+
RUN chmod +x /action.sh
8+
9+
ENTRYPOINT ["/action.sh"]

action/deploy_hugo/action.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
6+
if [ -n "${GITHUB_TOKEN}" ]; then
7+
remote_repo="https://x-access-token:${GITHUB_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_REPOSITORY}.git"
8+
elif [ -n "${PERSONAL_TOKEN}" ]; then
9+
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@${GITHUB_DOMAIN:-"github.com"}/${GITHUB_REPOSITORY}.git"
10+
fi
11+
12+
if ! git config --get user.name; then
13+
git config --global user.name "${GITHUB_ACTOR}"
14+
fi
15+
16+
if ! git config --get user.email; then
17+
git config --global user.email "${GITHUB_ACTOR}@users.noreply.${GITHUB_DOMAIN:-"github.com"}"
18+
fi
19+
20+
21+
git checkout --orphan gh-pages
22+
23+
cd static_hugo_site
24+
hugo --destination ../docs
25+
cd ..
26+
git reset
27+
git add docs/**
28+
29+
git remote add github "${remote_repo}"
30+
31+
git commit -m "publish site"
32+
git push --set-upstream github gh-pages

action/deploy_hugo/action.yml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: 'Deploy hugo site'
2+
description: 'Deploys hugo site'
3+
author: 'Charly Castro charlywazzap [email protected]'
4+
branding:
5+
icon: 'arrow-up-circle'
6+
color: 'orange'
7+
runs:
8+
using: 'docker'
9+
image: 'Dockerfile'

references/yamls/gh-hugo-deploy.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Deploy hugo site to gihubpages
2+
on:
3+
workflow_dispatch:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
hugo-github-pages:
10+
name: hugo-github-pages
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [10.x]
15+
steps:
16+
- name: Checkout base branch
17+
uses: actions/checkout@v2
18+
with:
19+
token: ${{ secrets.MY_GITHUB_TOKEN }}
20+
21+
- name: build hugo
22+
uses: ./action/deploy_hugo/
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

tutorials/04-sample-cd/deploy_hugo.md

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Traditional CI GitHub Actions
2+
3+
## Introduction
4+
5+
The following example shows you how GitHub Actions jobs help you setup a CI workflow
6+
7+
## Creating your first CI workflow
8+
9+
1. Fork this repo from [here](https://github.com/wizelineacademy/github-actions-tutorial) or create a new repo from [here](https://github.com/new)
10+
11+
1. Start the web editor by pressing "." in your repo `https://github.com/<yourusername>/github-actions-tutorial`
12+
13+
1. Create a `.github/workflows` directory in your repository in GitHub if this directory does not already exist.
14+
15+
1. In the `.github/workflows` directory, create a file named gh-hugo-deploy.yml
16+
17+
1. Copy the following YAML contents into the `gh-hugo-deploy.yml` file:
18+
19+
```yaml{:copy}
20+
name: Deploy hugo site to gihubpages
21+
on:
22+
workflow_dispatch:
23+
push:
24+
branches:
25+
- main
26+
27+
jobs:
28+
hugo-github-pages:
29+
name: hugo-github-pages
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
node-version: [10.x]
34+
steps:
35+
- name: Checkout base branch
36+
uses: actions/checkout@v2
37+
with:
38+
token: ${{ secrets.MY_GITHUB_TOKEN }}
39+
40+
- name: build hugo
41+
uses: ./action/deploy_hugo/
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
44+
45+
```
46+
47+
1. Create Dev token [here](https://github.com/settings/tokens)
48+
49+
1. Create Secret `MY_GITHUB_TOKEN` in https://github.com/<username>/github-actions-tutorial/settings/secrets/actions/new
50+

0 commit comments

Comments
 (0)