diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e64b7f8 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.git +.github +LICENSE +README.md +images diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 0000000..032cfda --- /dev/null +++ b/.github/main.workflow @@ -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 ." +} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6f8b6bb --- /dev/null +++ b/Dockerfile @@ -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" ] diff --git a/LICENSE b/LICENSE index 82bff43..11c0769 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index ae983c2..fd1b903 100644 --- a/README.md +++ b/README.md @@ -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) + +GitHub Actions for deploying to GitHub Pages with Static Site Generators + + + +## 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 + +peaceiris - Patreon diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..c2cfe80 --- /dev/null +++ b/entrypoint.sh @@ -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 diff --git a/images/ogp.svg b/images/ogp.svg new file mode 100644 index 0000000..c8476c0 --- /dev/null +++ b/images/ogp.svg @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/images/patreon.jpg b/images/patreon.jpg new file mode 100644 index 0000000..1c68052 Binary files /dev/null and b/images/patreon.jpg differ