Skip to content

Commit

Permalink
add: action
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed May 21, 2019
1 parent 913ab49 commit 036c4a1
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
.github
LICENSE
README.md
images
9 changes: 9 additions & 0 deletions .github/main.workflow
Original file line number Diff line number Diff line change
@@ -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 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 "[email protected]" -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/[email protected]"
args = ["--gc", "--minify", "--cleanDestinationDir"]
}
action "deploy" {
needs = "build"
uses = "peaceiris/[email protected]"
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 changes: 33 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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="[email protected]:${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 changes: 20 additions & 0 deletions images/ogp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/patreon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 036c4a1

Please sign in to comment.