Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Mar 3, 2019
2 parents ed0a8d7 + e2ba67c commit aa23d8b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
Binary file added .DS_Store
Binary file not shown.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,25 @@ action "Deploy to GitHub Pages" {
BUILD_SCRIPT = "npm install && npm run-script build"
BRANCH = "gh-pages"
FOLDER = "build"
COMMIT_EMAIL = "github-pages-deployer@jives.dev"
COMMIT_NAME = "GitHub Pages Deployer"
}
secrets = ["ACCESS_TOKEN"]
}
```

## Configuration 📁

The `env` portion of the workflow **must** be configured before the action will work. Below you'll find a description of what each one does.
The `secrets` and `env` portion of the workflow **must** be configured before the action will work. Below you'll find a description of what each one does.

| Key | Value Information | Required |
| ------------- | ------------- | ------------- |
| `BUILD_SCRIPT` | If you require a build script to compile your code prior to pushing it you can add the script here. The Docker container which powers the action runs Node which means `npm` commands are valid. If you're using a static site generator such as Jekyll I'd suggest compiling the code prior to pushing it to your base branch. | **No** |
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | **Yes** |
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | **No** |
| `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. | **Yes** |
| `COMMIT_NAME` | Used to sign the commit, this should be your name. Defaults to `gh-pages-deploy@jives.dev` | **No** |
| `COMMIT_EMAIL` | Used to sign the commit, this should be your email. Defaults to `GitHub Pages Deployer` | **No** |
| Key | Value Information | Type | Required |
| ------------- | ------------- | ------------- | ------------- |
| `ACCESS_TOKEN` | In order for GitHub to trigger the rebuild of your page you must provide the action with a GitHub personal access token. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). This **should be stored as a secret.** | `secrets` | **Yes** |
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `env` | **Yes** |
| `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. | `env` | **Yes** |
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `env` | **No** |
| `BUILD_SCRIPT` | If you require a build script to compile your code prior to pushing it you can add the script here. The Docker container which powers the action runs Node which means `npm` commands are valid. If you're using a static site generator such as Jekyll I'd suggest compiling the code prior to pushing it to your base branch. | `env` | **No** |
| `COMMIT_NAME` | Used to sign the commit, this should be your name. If not provided it will default to `username@users.noreply.github.com` | `env` | **No** |
| `COMMIT_EMAIL` | Used to sign the commit, this should be your email. If not provided it will default to your username. | `env` | **No** |

With the action correctly configured you should see something similar to this in your GitHub action workflow editor.
With the action correctly configured you should see something similar to this in your GitHub actions workflow editor.

![Example](screenshot.png)
34 changes: 26 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/sh -l

if [ -z "$ACCESS_TOKEN" ]
then
echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy."
exit 1
fi

if [ -z "$BRANCH" ]
then
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
Expand All @@ -11,28 +18,39 @@ then
exit 1
fi

## Initializes Variables
if [ -z "$COMMIT_EMAIL" ]
then
COMMIT_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com"
fi

if [ -z "$COMMIT_NAME" ]
then
COMMIT_NAME="${GITHUB_ACTOR}"
fi

## Initializes the repository path using the access token.
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \

# Installs Git.
apt-get update && \
apt-get install -y git && \

# Re-directs to the the Github workspace.
# Directs the action to the the Github workspace.
cd $GITHUB_WORKSPACE && \

# Configures Git and checks out the base branch.
git init && \
git config --global user.email "${COMMIT_EMAIL:-gh-pages-deploy@jives.dev}" && \
git config --global user.name "${COMMIT_NAME:-Github Pages Deployer}" && \
git config --global user.email "${COMMIT_EMAIL}" && \
git config --global user.name "${COMMIT_NAME}" && \
git checkout "${BASE_BRANCH:-master}" && \

# Builds the project if applicable.
# Builds the project if a build script is provided.
echo "Running build scripts... $BUILD_SCRIPT"
eval "$BUILD_SCRIPT"

# Commits the data to Github.
echo "Deploying to GitHub..." && \
git add -f $FOLDER && \
git commit -m "Deploying $(date +"%T")" && \
git push --force $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH

git commit -m "Deploying to ${BRANCH} - $(date +"%T")" && \
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH --force && \
echo "Deployment Succesful!"

0 comments on commit aa23d8b

Please sign in to comment.