mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Merge pull request #4 from JamesIves/check-exists
Checks if remote exists
This commit is contained in:
commit
b113d69cdb
15
README.md
15
README.md
@ -5,18 +5,7 @@
|
||||
This [GitHub action](https://github.com/features/actions) will handle the building and deploying process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production ready code into any branch you'd like, including `gh-pages` and `docs`.
|
||||
|
||||
## Getting Started :airplane:
|
||||
Before you get started you must first create a fresh branch where the action will deploy the files to. You can replace `gh-pages` with whatever branch you'd like to use in the example below.
|
||||
|
||||
```git
|
||||
git checkout --orphan gh-pages
|
||||
git rm -rf .
|
||||
touch README.md
|
||||
git add README.md
|
||||
git commit -m 'Initial gh-pages commit'
|
||||
git push origin gh-pages
|
||||
```
|
||||
|
||||
Once setup you can then include the action in your workflow to trigger on any event that [GitHub actions](https://github.com/features/actions) supports.
|
||||
You can include the action in your workflow to trigger on any event that [GitHub actions](https://github.com/features/actions) supports. If the remote branch that you wish to deploy to doesn't already exist the action will create it for you.
|
||||
|
||||
```workflow
|
||||
action "Deploy to GitHub Pages" {
|
||||
@ -30,7 +19,7 @@ action "Deploy to GitHub Pages" {
|
||||
}
|
||||
```
|
||||
|
||||
If you'd like to filter the action so it only triggers on a specific branch you can combine it with the filter action. You can find an example of this below.
|
||||
If you'd like you can combine it with the filter action so it only triggers deploys on a specific branch. You can find an example of this below.
|
||||
|
||||
```workflow
|
||||
workflow "Deploy to Github Pages" {
|
||||
|
@ -28,9 +28,6 @@ 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 && \
|
||||
@ -38,19 +35,38 @@ apt-get install -y git && \
|
||||
# Directs the action to the the Github workspace.
|
||||
cd $GITHUB_WORKSPACE && \
|
||||
|
||||
# Configures Git and checks out the base branch.
|
||||
# Configures Git.
|
||||
git init && \
|
||||
git config --global user.email "${COMMIT_EMAIL}" && \
|
||||
git config --global user.name "${COMMIT_NAME}" && \
|
||||
|
||||
## Initializes the repository path using the access token.
|
||||
REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \
|
||||
|
||||
# Checks to see if the remote exists prior to deploying.
|
||||
# If the branch doesn't exist it gets created here as an orphan.
|
||||
if [ "$(git ls-remote --heads "$REPOSITORY_PATH" "$BRANCH" | wc -l)" -eq 0 ];
|
||||
then
|
||||
echo "Creating remote branch ${BRANCH} as it doesn't exist..."
|
||||
git checkout "${BASE_BRANCH:-master}" && \
|
||||
git checkout --orphan $BRANCH && \
|
||||
git rm -rf . && \
|
||||
touch README.md && \
|
||||
git add README.md && \
|
||||
git commit -m "Initial ${BRANCH} commit" && \
|
||||
git push $REPOSITORY_PATH $BRANCH
|
||||
fi
|
||||
|
||||
# Checks out the base branch to begin the deploy process.
|
||||
git checkout "${BASE_BRANCH:-master}" && \
|
||||
|
||||
# Builds the project if a build script is provided.
|
||||
echo "Running build scripts... $BUILD_SCRIPT"
|
||||
eval "$BUILD_SCRIPT"
|
||||
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 to ${BRANCH} - $(date +"%T")" && \
|
||||
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