mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Defaults
This commit is contained in:
parent
b70dd2b2ec
commit
2dd0d93bb0
@ -38,7 +38,7 @@ The `secrets` and `env` portion of the workflow **must** be configured before th
|
|||||||
| ------------- | ------------- | ------------- | ------------- |
|
| ------------- | ------------- | ------------- | ------------- |
|
||||||
| `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** |
|
| `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** |
|
| `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. You can instruct the action to deploy from the root directory by placing `/` in this field. | `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** |
|
| `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** |
|
| `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_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** |
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
#!/bin/sh -l
|
#!/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" ]
|
if [ -z "$BRANCH" ]
|
||||||
then
|
then
|
||||||
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
|
echo "You must provide the action with a branch name it should deploy to, for example gh-pages or docs."
|
||||||
@ -11,39 +18,40 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$ACCESS_TOKEN" ]
|
if [ -z "$COMMIT_EMAIL" ]
|
||||||
then
|
then
|
||||||
echo "You must provide the action with a GitHub Personal Access Token secret in order to deploy."
|
COMMIT_EMAIL="${GITHUB_ACTOR}@users.noreply.github.com"
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$FOLDER" == "/" ]]; then
|
if [ -z "$COMMIT_NAME" ]
|
||||||
FOLDER=":/"
|
then
|
||||||
|
COMMIT_NAME="${GITHUB_ACTOR}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## Initializes Variables
|
## Initializes the repository path using the access token.
|
||||||
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
|
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
|
||||||
|
|
||||||
|
|
||||||
# Installs Git.
|
# Installs Git.
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y git && \
|
apt-get install -y git && \
|
||||||
|
|
||||||
# Re-directs to the the Github workspace.
|
# Directs the action to the the Github workspace.
|
||||||
cd $GITHUB_WORKSPACE && \
|
cd $GITHUB_WORKSPACE && \
|
||||||
|
|
||||||
# Configures Git and checks out the base branch.
|
# Configures Git and checks out the base branch.
|
||||||
git init && \
|
git init && \
|
||||||
git config --global user.email "${COMMIT_EMAIL:-GITHUB_ACTOR@users.noreply.github.com}" && \
|
git config --global user.email "${COMMIT_EMAIL}" && \
|
||||||
git config --global user.name "${COMMIT_NAME:-GITHUB_ACTOR}" && \
|
git config --global user.name "${COMMIT_NAME}" && \
|
||||||
git checkout "${BASE_BRANCH:-master}" && \
|
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"
|
echo "Running build scripts... $BUILD_SCRIPT"
|
||||||
eval "$BUILD_SCRIPT"
|
eval "$BUILD_SCRIPT"
|
||||||
|
|
||||||
# Commits the data to Github.
|
# Commits the data to Github.
|
||||||
|
echo "Deploying to GitHub..." && \
|
||||||
git add -f $FOLDER && \
|
git add -f $FOLDER && \
|
||||||
git commit -m "Deploying to ${FOLDER} - $(date +"%T")" && \
|
git commit -m "Deploying to ${BRANCH} - $(date +"%T")" && \
|
||||||
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH --force && \
|
git push $REPOSITORY_PATH `git subtree split --prefix $FOLDER master`:$BRANCH --force && \
|
||||||
echo "Deployment Succesful!"
|
echo "Deployment Succesful!"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user