Initial version

This commit is contained in:
CrazyMax 2019-08-31 22:23:41 +02:00
commit 203e6cb74c
No known key found for this signature in database
GPG Key ID: 3248E46B6BB8C7F7
9 changed files with 180 additions and 0 deletions

1
.dockerignore Normal file
View File

@ -0,0 +1 @@
.github

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Jetbrains
/.idea
/*.iml

BIN
.res/patreon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

BIN
.res/paypal-donate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

14
Dockerfile Normal file
View File

@ -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" ]

21
LICENSE Normal file
View File

@ -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.

79
README.md Normal file
View File

@ -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 <<EOL
<!doctype html>
<html>
<head>
<title>GitHub Pages deployed!</title>
</head>
<body>
<p>GitHub Pages with <strong>${{ github.sha }}</strong> commit ID has been deployed through <a href="">GitHub Pages action</a> successfully.</p>
</body>
</html>
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:!<br />
The most basic way to show your support is to star :star2: the project, or to raise issues :speech_balloon:<br />
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.

20
action.yml Normal file
View File

@ -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'

42
entrypoint.sh Normal file
View File

@ -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."