Skip to content

Commit 58f65a7

Browse files
authored
Merge pull request #1 from JamesIves/access
Access Token
2 parents 388ff8e + 0d6440b commit 58f65a7

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

.DS_Store

6 KB
Binary file not shown.

README.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ action "Deploy to GitHub Pages" {
2525
BUILD_SCRIPT = "npm install && npm run-script build"
2626
BRANCH = "gh-pages"
2727
FOLDER = "build"
28-
COMMIT_EMAIL = "github-pages-deployer@jives.dev"
29-
COMMIT_NAME = "GitHub Pages Deployer"
3028
}
3129
secrets = ["ACCESS_TOKEN"]
3230
}
3331
```
3432

3533
## Configuration 📁
3634

37-
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.
35+
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.
3836

39-
| Key | Value Information | Required |
40-
| ------------- | ------------- | ------------- |
41-
| `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** |
42-
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | **Yes** |
43-
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | **No** |
44-
| `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** |
45-
| `COMMIT_NAME` | Used to sign the commit, this should be your name. Defaults to `gh-pages-deploy@jives.dev` | **No** |
46-
| `COMMIT_EMAIL` | Used to sign the commit, this should be your email. Defaults to `GitHub Pages Deployer` | **No** |
37+
| Key | Value Information | Type | Required |
38+
| ------------- | ------------- | ------------- | ------------- |
39+
| `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** |
40+
| `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `env` | **Yes** |
41+
| `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** |
42+
| `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `env` | **No** |
43+
| `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** |
44+
| `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** |
45+
| `COMMIT_EMAIL` | Used to sign the commit, this should be your email. If not provided it will default to your username. | `env` | **No** |
4746

48-
With the action correctly configured you should see something similar to this in your GitHub action workflow editor.
47+
With the action correctly configured you should see something similar to this in your GitHub actions workflow editor.
4948

5049
![Example](screenshot.png)

entrypoint.sh

+26-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
#!/bin/sh -l
2+
3+
if [ -z "$ACCESS_TOKEN" ]
4+
then
5+
echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy."
6+
exit 1
7+
fi
8+
29
if [ -z "$BRANCH" ]
310
then
411
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
@@ -11,28 +18,39 @@ then
1118
exit 1
1219
fi
1320

14-
## Initializes Variables
21+
if [ -z "$COMMIT_EMAIL" ]
22+
then
23+
COMMIT_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com"
24+
fi
25+
26+
if [ -z "$COMMIT_NAME" ]
27+
then
28+
COMMIT_NAME="${GITHUB_ACTOR}"
29+
fi
30+
31+
## Initializes the repository path using the access token.
1532
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
1633

1734
# Installs Git.
1835
apt-get update && \
1936
apt-get install -y git && \
2037

21-
# Re-directs to the the Github workspace.
38+
# Directs the action to the the Github workspace.
2239
cd $GITHUB_WORKSPACE && \
2340

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

30-
# Builds the project if applicable.
47+
# Builds the project if a build script is provided.
3148
echo "Running build scripts... $BUILD_SCRIPT"
3249
eval "$BUILD_SCRIPT"
3350

3451
# Commits the data to Github.
52+
echo "Deploying to GitHub..." && \
3553
git add -f $FOLDER && \
36-
git commit -m "Deploying $(date +"%T")" && \
37-
git push --force $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH
38-
54+
git commit -m "Deploying to ${BRANCH} - $(date +"%T")" && \
55+
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH --force && \
56+
echo "Deployment Succesful!"

0 commit comments

Comments
 (0)