commit 203e6cb74c39e85839a7b3bfb9cb1f5d3739d655 Author: CrazyMax Date: Sat Aug 31 22:23:41 2019 +0200 Initial version diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..26f5c15 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.github diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7e49040 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# Jetbrains +/.idea +/*.iml diff --git a/.res/patreon.png b/.res/patreon.png new file mode 100644 index 0000000..6848a1f Binary files /dev/null and b/.res/patreon.png differ diff --git a/.res/paypal-donate.png b/.res/paypal-donate.png new file mode 100644 index 0000000..76842ea Binary files /dev/null and b/.res/paypal-donate.png differ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5eba377 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine/git:latest + +# https://help.github.com/en/articles/metadata-syntax-for-github-actions#about-yaml-syntax-for-github-actions +LABEL version="0.1.0" \ + repository="https://github.com/crazy-max/ghaction-github-pages" \ + homepage="https://github.com/crazy-max/ghaction-github-pages" \ + maintainer="CrazyMax" \ + "com.github.actions.name"="GitHub Pages" \ + "com.github.actions.description"="Github Action for deploying Github Pages" \ + "com.github.actions.icon"="package" \ + "com.github.actions.color"="green" + +COPY entrypoint.sh LICENSE README.md / +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..89a92d2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 CrazyMax + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cfc5beb --- /dev/null +++ b/README.md @@ -0,0 +1,79 @@ +[![Support me on Patreon](https://img.shields.io/badge/donate-patreon-f96854.svg?logo=patreon&style=flat-square)](https://www.patreon.com/crazymax) +[![Paypal Donate](https://img.shields.io/badge/donate-paypal-00457c.svg?logo=paypal&style=flat-square)](https://www.paypal.me/crazyws) + +## ✨ About + +A GitHub Action for deploying GitHub Pages + +> **:warning: Note:** To use this action, you must have access to the [GitHub Actions](https://github.com/features/actions) feature. GitHub Actions are currently only available in public beta. You can [apply for the GitHub Actions beta here](https://github.com/features/actions/signup/). + +## 🚀 Usage + +Below is a simple to deploy to GitHub Pages: + +```yaml +name: website + +on: push + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@master + - + name: Build + run: | + mkdir public + cat > public/index.html < + + + GitHub Pages deployed! + + +

GitHub Pages with ${{ github.sha }} commit ID has been deployed through GitHub Pages action successfully.

+ + + EOL + - + name: Deploy + uses: crazy-max/ghaction-github-pages@master + with: + build_dir: public + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +``` + +## 💅 Customizing + +### inputs + +The following are **required** as `step.with` keys + +| Name | Type | Description | +|-------------|---------|-----------------------------------------------------------------| +| `build_dir` | String | Path to build directory to deploy | + +### environment variables + +The following are *required* as `step.env` keys + +| Name | Description | +|----------------|--------------------------------------| +| `GITHUB_TOKEN` | GITHUB_TOKEN as provided by `secrets`| + +## 🤝 How can I help ? + +All kinds of contributions are welcome :raised_hands:!
+The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:
+But we're not gonna lie to each other, I'd rather you buy me a beer or two :beers:! + +[![Support me on Patreon](.res/patreon.png)](https://www.patreon.com/crazymax) +[![Paypal Donate](.res/paypal-donate.png)](https://www.paypal.me/crazyws) + +## 📝 License + +MIT. See `LICENSE` for more details. diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..a29773c --- /dev/null +++ b/action.yml @@ -0,0 +1,20 @@ +# https://help.github.com/en/articles/metadata-syntax-for-github-actions +name: 'GitHub Pages' +description: 'GitHub Action for deploying GitHub Pages' +author: 'crazy-max' +branding: + color: 'green' + icon: 'git-branch' + +inputs: + build_dir: + description: 'Path to build directory to deploy' + required: true + +runs: + using: 'docker' + image: 'Dockerfile' + args: + - ${{ inputs.build_dir }} + env: + GITHUB_TOKEN: 'As provided by GitHub Actions' diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..8c2e234 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,42 @@ +#!/bin/sh +set -e + +BUILD_DIR=$1 +if [ ! -d "$BUILD_DIR" ]; then + echo "⛔️ Build dir does not exist" + exit 1 +fi +echo "cd $BUILD_DIR" +cd "$BUILD_DIR" + +REPO="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" +OWNER="$(echo $GITHUB_REPOSITORY | cut -d'/' -f 1)" +REPONAME="$(echo $GITHUB_REPOSITORY | cut -d'/' -f 2)" +PAGES_REPO="${OWNER}.github.io" + +if [[ "$REPONAME" == "$PAGES_REPO" ]]; then + TARGET_BRANCH="master" +else + TARGET_BRANCH="gh-pages" +fi + +: "${REMOTE_BRANCH:=$TARGET_BRANCH}" + +git init +git config user.name "${GITHUB_ACTOR}" +git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" + +if [ -z "$(git status --porcelain)" ]; then + echo "⚠️ Nothing to publish" + exit 0 +fi + +git remote rm origin || true +git remote add origin "${REPO}" +git add . +git commit --allow-empty -m 'Deploy to GitHub pages' +git push --force --quiet "$REPO" $REMOTE_BRANCH +rm -rf .git + +cd "$GITHUB_WORKSPACE" +echo "🎉 Content of $BUILD_DIR has been deployed to GitHub Pages."