Skip to content

Commit

Permalink
Merge pull request #4 from JamesIves/check-exists
Browse files Browse the repository at this point in the history
Checks if remote exists
  • Loading branch information
JamesIves authored Mar 4, 2019
2 parents 7e7e6c8 + 3ea85cf commit b113d69
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
15 changes: 2 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand All @@ -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" {
Expand Down
30 changes: 23 additions & 7 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,45 @@ 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 && \

# 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!"

0 comments on commit b113d69

Please sign in to comment.