-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a3ed59d
Showing
7 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Container image that runs your code | ||
FROM node:12 | ||
|
||
RUN apt update && apt install -y \ | ||
curl git jq \ | ||
npm install postcss-cli autoprefixer | ||
|
||
# Copies your code file from your action repository to the filesystem path `/` of the container | ||
COPY action.sh /action.sh | ||
|
||
# Code file to execute when the docker container starts up (`action.sh`) | ||
ENTRYPOINT ["/action.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020 Victoria Drake | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# GitHub Action to build and deploy a Hugo site to a remote repository 🚀 | ||
|
||
If you've ever wanted to keep your Hugo site source repository private, but deploy the site to your public GitHub Pages repository, you're in the right place. | ||
|
||
This action cleans and rebuilds your [Hugo site](https://gohugo.io/), and pushes the new build to a remote repository you define. | ||
|
||
It always uses the latest extended version from [Hugo releases](https://github.com/gohugoio/hugo/releases). The extended version [enables the processing](https://gohugo.io/troubleshooting/faq/#i-get-tocss--this-feature-is-not-available-in-your-current-hugo-version) of SCSS and Sass files to CSS. | ||
|
||
Your site will build in the `DEST` directory you specify (Hugo's usual default is `public`). The contents of this directory will then be pushed to `master` of your remote public repository. | ||
|
||
## Use this in your workflow | ||
|
||
Here's how to use this action in your workflow file. | ||
|
||
### 1. Add a Personal Access Token as a Secret called `TOKEN` in your repository | ||
|
||
See [Creating a token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line#creating-a-token) to set up a Personal Access Token. See [Creating and storing encrypted secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) for instructions to add this to your repository. | ||
|
||
When you're finished, your repository's Secrets tab will look like this: | ||
|
||
![Secrets tab showing saved TOKEN encrypted variable](secret.png) | ||
|
||
### 2. Set your environment variables and add this action in a workflow | ||
|
||
Here is an example workflow file that uses this action on any `push` event to the `master` branch: | ||
|
||
```yml | ||
name: hugo-remote | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
env: | ||
REMOTE: username/username.github.io.git | ||
DEST: public | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 🛎 Check out master | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
- name: 🚀 Build and deploy | ||
uses: victoriadrake/hugo-remote@master | ||
``` | ||
See full instructions for [Configuring and managing workflows](https://help.github.com/en/actions/configuring-and-managing-workflows). | ||
## Use the workflow YAML file directly | ||
If you prefer to place this action's YAML file in your repository directly, simply copy the included `hugo-remote.yml` into your repository's `.github/workflows/` directory. | ||
|
||
For help editing the YAML file, see [Workflow syntax for GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Fail if variables are unset | ||
set -eu -o pipefail | ||
|
||
echo '🤵 Install Hugo' | ||
HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.tag_name') | ||
mkdir tmp/ && cd tmp/ | ||
curl -sSL https://github.com/gohugoio/hugo/releases/download/${HUGO_VERSION}/hugo_extended_${HUGO_VERSION: -6}_Linux-64bit.tar.gz | tar -xvzf- | ||
mv hugo /usr/local/bin/ | ||
cd .. && rm -rf tmp/ | ||
cd ${GITHUB_WORKSPACE} | ||
hugo version || exit 1 | ||
|
||
echo '👯 Clone remote repository' | ||
git clone https://github.com/${REMOTE} ${DEST} | ||
|
||
echo '🧹 Clean site' | ||
if [ -d "${DEST}" ]; then | ||
rm -rf ${DEST}/* | ||
fi | ||
|
||
echo '🍳 Build site' | ||
hugo -d ${DEST} | ||
|
||
echo '🎁 Publish to remote repository' | ||
cd ${DEST} | ||
git config user.name "${GITHUB_ACTOR}" | ||
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
git add . | ||
git commit -am "🚀 Deploy with ${GITHUB_WORKFLOW}" | ||
git push --all -f -q https://${{ secrets.TOKEN }}@github.com/${REMOTE} master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: 'Deploy Hugo to Remote' | ||
description: '🚀 Build and deploy a Hugo site to a remote repository with latest extended Hugo.' | ||
author: 'victoriadrake' | ||
branding: | ||
icon: 'send' | ||
color: 'blue' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: hugo-remote | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
|
||
# Don't forget to set these! | ||
env: | ||
REMOTE: # username/username.github.io.git | ||
DEST: # public | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: 🛎 Check out master | ||
uses: actions/checkout@master | ||
with: | ||
fetch-depth: 1 | ||
- name: 🔨 Set up Node | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
- name: 🔧 Install tools | ||
run: | | ||
sudo apt install curl jq | ||
npm install postcss-cli autoprefixer | ||
- name: 🤵 Install latest Hugo | ||
run: | | ||
HUGO_VERSION=$(curl -s https://api.github.com/repos/gohugoio/hugo/releases/latest | jq -r '.tag_name') | ||
mkdir tmp/ && cd tmp/ | ||
curl -sSL https://github.com/gohugoio/hugo/releases/download/${HUGO_VERSION}/hugo_extended_${HUGO_VERSION: -6}_Linux-64bit.tar.gz | tar -xvzf- | ||
sudo mv hugo /usr/local/bin/ | ||
cd .. && rm -rf tmp/ | ||
hugo version | ||
- name: 👯 Clone remote repository | ||
run: git clone https://github.com/${REMOTE} ${DEST} | ||
- name: 🧹 Clean site | ||
run: | | ||
if [ -d "${DEST}" ]; then | ||
rm -rf ${DEST}/* | ||
fi | ||
- name: 🍳 Build site | ||
run: hugo -d ${DEST} | ||
- name: 🎁 Publish to remote repository | ||
env: | ||
TOKEN: ${{ secrets.TOKEN }} | ||
run: | | ||
cd ${DEST} | ||
git config user.name "${GITHUB_ACTOR}" | ||
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" | ||
git add . | ||
git status | ||
git commit -am "🚀 Deploy with ${GITHUB_WORKFLOW}" | ||
git push --all -f -q https://${{ secrets.TOKEN }}@github.com/${REMOTE} master |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.