Skip to content

Commit 036c4a1

Browse files
committed
add: action
1 parent 913ab49 commit 036c4a1

File tree

8 files changed

+158
-3
lines changed

8 files changed

+158
-3
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.git
2+
.github
3+
LICENSE
4+
README.md
5+
images

.github/main.workflow

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
workflow "Main workflow" {
2+
on = "push"
3+
resolves = ["docker-build"]
4+
}
5+
6+
action "docker-build" {
7+
uses = "actions/docker/cli@master"
8+
args = "build -t peaceiris/actions-gh-deploy ."
9+
}

Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM alpine:3.9
2+
3+
LABEL "com.github.actions.name"="Deploy to GitHub Pages for Static Site Generator"
4+
LABEL "com.github.actions.description"="A GitHub Action to deploy your static site to GitHub Pages with Static Site Generator"
5+
LABEL "com.github.actions.icon"="upload-cloud"
6+
LABEL "com.github.actions.color"="blue"
7+
8+
LABEL "repository"="https://github.com/peaceiris/actions-gh-pages"
9+
LABEL "homepage"="https://github.com/peaceiris/actions-gh-pages"
10+
LABEL "maintainer"="peaceiris"
11+
12+
RUN apk add --no-cache \
13+
git \
14+
openssh-client
15+
16+
ADD entrypoint.sh /entrypoint.sh
17+
ENTRYPOINT [ "/entrypoint.sh" ]

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Shohei Ueda
3+
Copyright (c) 2019 Shohei Ueda (peaceiris)
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+73-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
1-
# actions-gh-deploy
2-
GitHub Actions for deploying to GitHub Pages with Static Site Generators
1+
[![license](https://img.shields.io/github/license/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE)
2+
[![release](https://img.shields.io/github/release/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases/latest)
3+
[![GitHub release date](https://img.shields.io/github/release-date/peaceiris/actions-gh-pages.svg)](https://github.com/peaceiris/actions-gh-pages/releases)
4+
5+
<img width="400" alt="GitHub Actions for deploying to GitHub Pages with Static Site Generators" src="./images/ogp.svg">
6+
7+
8+
9+
## GitHub Actions for deploying to GitHub Pages
10+
11+
A GitHub Action to deploy your static site to GitHub Pages with [Static Site Generators] (Hugo, MkDocs, Gatsby, GitBook, etc.)
12+
13+
[Static Site Generators]: https://www.staticgen.com/
14+
15+
16+
17+
## Getting started
18+
19+
### (1) Add deploy Key
20+
21+
1. Generate deploy key `ssh-keygen -t rsa -b 4096 -C "[email protected]" -f gh-pages -N ""`
22+
2. Go to "Settings > Deploy Keys" of repository.
23+
3. Add your public key within "Allow write access" option.
24+
4. Go to "Settings > Secrets" of repository.
25+
5. Add your private deploy key as `ACTIONS_DEPLOY_KEY`
26+
27+
### (2) Create `main.workflow`
28+
29+
An example with Hugo action.
30+
31+
- [peaceiris/actions-hugo: GitHub Actions for Hugo extended](https://github.com/peaceiris/actions-hugo)
32+
33+
```hcl
34+
workflow "GitHub Pages" {
35+
on = "push"
36+
resolves = ["deploy"]
37+
}
38+
39+
action "is-branch-master" {
40+
uses = "actions/bin/filter@master"
41+
args = "branch master"
42+
}
43+
44+
action "build" {
45+
needs = "is-branch-master"
46+
uses = "peaceiris/[email protected]"
47+
args = ["--gc", "--minify", "--cleanDestinationDir"]
48+
}
49+
50+
action "deploy" {
51+
needs = "build"
52+
uses = "peaceiris/[email protected]"
53+
env = {
54+
PUBLISH_DIR = "./public"
55+
PUBLISH_BRANCH = "gh-pages"
56+
}
57+
secrets = ["ACTIONS_DEPLOY_KEY"]
58+
}
59+
```
60+
61+
62+
63+
## License
64+
65+
[MIT License - peaceiris/actions-gh-pages]
66+
67+
[MIT License - peaceiris/actions-gh-pages]: https://github.com/peaceiris/actions-gh-pages/blob/master/LICENSE
68+
69+
70+
71+
## Supprt author
72+
73+
<a href="https://www.patreon.com/peaceiris"><img src="./images/patreon.jpg" alt="peaceiris - Patreon" width="150px"></a>

entrypoint.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
3+
# setup ssh
4+
if [[ -z "${ACTIONS_DEPLOY_KEY}" ]]; then
5+
echo "error: not found ACTIONS_DEPLOY_KEY"
6+
exit 1
7+
fi
8+
mkdir /root/.ssh
9+
ssh-keyscan -t rsa github.com > /root/.ssh/known_hosts
10+
echo "${ACTIONS_DEPLOY_KEY}" > /root/.ssh/id_rsa
11+
chmod 400 /root/.ssh/id_rsa
12+
13+
# push to gh-pages branch
14+
if [[ -z "${PUBLISH_DIR}" ]]; then
15+
echo "error: not found PUBLISH_DIR"
16+
exit 1
17+
fi
18+
cd ${PUBLISH_DIR}
19+
if [[ -z "${PUBLISH_BRANCH}" ]]; then
20+
echo "error: not found PUBLISH_BRANCH"
21+
exit 1
22+
fi
23+
remote_repo="[email protected]:${GITHUB_REPOSITORY}.git"
24+
remote_branch="${PUBLISH_BRANCH}"
25+
git init
26+
git config user.name "${GITHUB_ACTOR}"
27+
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
28+
git remote add origin "${remote_repo}"
29+
git checkout "${remote_branch}" || git checkout --orphan "${remote_branch}"
30+
git add --all
31+
timestamp=$(date -u)
32+
git commit -m "Automated deployment: ${timestamp} ${GITHUB_SHA}"
33+
git push origin "${remote_branch}" --force

images/ogp.svg

+20
Loading

images/patreon.jpg

3.45 KB
Loading

0 commit comments

Comments
 (0)