add: action

This commit is contained in:
peaceiris 2019-05-22 06:53:54 +09:00
parent 913ab499f6
commit 036c4a14e0
8 changed files with 158 additions and 3 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
.git
.github
LICENSE
README.md
images

9
.github/main.workflow vendored Normal file
View File

@ -0,0 +1,9 @@
workflow "Main workflow" {
on = "push"
resolves = ["docker-build"]
}
action "docker-build" {
uses = "actions/docker/cli@master"
args = "build -t peaceiris/actions-gh-deploy ."
}

17
Dockerfile Normal file
View File

@ -0,0 +1,17 @@
FROM alpine:3.9
LABEL "com.github.actions.name"="Deploy to GitHub Pages for Static Site Generator"
LABEL "com.github.actions.description"="A GitHub Action to deploy your static site to GitHub Pages with Static Site Generator"
LABEL "com.github.actions.icon"="upload-cloud"
LABEL "com.github.actions.color"="blue"
LABEL "repository"="https://github.com/peaceiris/actions-gh-pages"
LABEL "homepage"="https://github.com/peaceiris/actions-gh-pages"
LABEL "maintainer"="peaceiris"
RUN apk add --no-cache \
git \
openssh-client
ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2019 Shohei Ueda
Copyright (c) 2019 Shohei Ueda (peaceiris)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,2 +1,73 @@
# actions-gh-deploy
GitHub Actions for deploying to GitHub Pages with Static Site Generators
[![license](https://img.shields.io/github/license/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE)
[![release](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases/latest)
[![GitHub release date](https://img.shields.io/github/release-date/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases)
<img width="400" alt="GitHub Actions for deploying to GitHub Pages with Static Site Generators" src="./images/ogp.svg">
## GitHub Actions for deploying to GitHub Pages
A GitHub Action to deploy your static site to GitHub Pages with [Static Site Generators] (Hugo, MkDocs, Gatsby, GitBook, etc.)
[Static Site Generators]: https://www.staticgen.com/
## Getting started
### (1) Add deploy Key
1. Generate deploy key `ssh-keygen -t rsa -b 4096 -C "your@email.com" -f gh-pages -N ""`
2. Go to "Settings > Deploy Keys" of repository.
3. Add your public key within "Allow write access" option.
4. Go to "Settings > Secrets" of repository.
5. Add your private deploy key as `ACTIONS_DEPLOY_KEY`
### (2) Create `main.workflow`
An example with Hugo action.
- [peaceiris/actions-hugo: GitHub Actions for Hugo extended](https://github.com/peaceiris/actions-hugo)
```hcl
workflow "GitHub Pages" {
on = "push"
resolves = ["deploy"]
}
action "is-branch-master" {
uses = "actions/bin/filter@master"
args = "branch master"
}
action "build" {
needs = "is-branch-master"
uses = "peaceiris/actions-hugo@v0.55.6"
args = ["--gc", "--minify", "--cleanDestinationDir"]
}
action "deploy" {
needs = "build"
uses = "peaceiris/actions-gh-pages@v1.0.0"
env = {
PUBLISH_DIR = "./public"
PUBLISH_BRANCH = "gh-pages"
}
secrets = ["ACTIONS_DEPLOY_KEY"]
}
```
## License
[MIT License - peaceiris/actions-gh-pages]
[MIT License - peaceiris/actions-gh-pages]: https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE
## Supprt author
<a href="https://www.patreon.com/peaceiris"><img src="./images/patreon.jpg" alt="peaceiris - Patreon" width="150px"></a>

33
entrypoint.sh Executable file
View File

@ -0,0 +1,33 @@
#!/bin/sh
# setup ssh
if [[ -z "${ACTIONS_DEPLOY_KEY}" ]]; then
echo "error: not found ACTIONS_DEPLOY_KEY"
exit 1
fi
mkdir /root/.ssh
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa
chmod 400 /root/.ssh/id_rsa
# push to gh-pages branch
if [[ -z "${PUBLISH_DIR}" ]]; then
echo "error: not found PUBLISH_DIR"
exit 1
fi
cd ${PUBLISH_DIR}
if [[ -z "${PUBLISH_BRANCH}" ]]; then
echo "error: not found PUBLISH_BRANCH"
exit 1
fi
remote_repo="git@github.com:${GITHUB_REPOSITORY}.git"
remote_branch="${PUBLISH_BRANCH}"
git init
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git remote add origin "${remote_repo}"
git checkout "${remote_branch}" || git checkout --orphan "${remote_branch}"
git add --all
timestamp=$(date -u)
git commit -m "Automated deployment: ${timestamp} ${GITHUB_SHA}"
git push origin "${remote_branch}" --force

20
images/ogp.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 46 KiB

BIN
images/patreon.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB