From 448be22c60be82cd49d1fe4c181f3af32943d655 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 08:38:45 -0500 Subject: [PATCH 01/11] Checks to see if the remote branch exists --- entrypoint.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 877d996b..17bd4b80 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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,12 +35,32 @@ 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}" && \ + +## Checks to see if the remote exists prior to deploying +REMOTE_BRANCH = `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" docs` + +# If the branch doesn't exist it gets created here as an orphan. +if [[ -z $REMOTE_BRANCH ]] +then + git checkout --orphan $BRANCH && \ + git rm -rf . && \ + touch README.md && \ + git add README.md && \ + git commit -m "Initial ${BRANCH} commit" && \ + git push origin $BRANCH +fi + +# Checks out the base branch to begin the deploy process. git checkout "${BASE_BRANCH:-master}" && \ +## Initializes the repository path using the access token. +REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \ + + # Builds the project if a build script is provided. echo "Running build scripts... $BUILD_SCRIPT" eval "$BUILD_SCRIPT" From a2c3f4b943d80eaf0c3e41ba10e491c7ef2f5854 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 08:39:18 -0500 Subject: [PATCH 02/11] Update entrypoint.sh --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 17bd4b80..75f86d56 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -62,8 +62,8 @@ REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && # 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..." && \ From 9599d53b6d140ef61068033fe246a86a99688291 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 08:41:33 -0500 Subject: [PATCH 03/11] Update entrypoint.sh --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 75f86d56..a8b67201 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -46,6 +46,7 @@ REMOTE_BRANCH = `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:James # If the branch doesn't exist it gets created here as an orphan. if [[ -z $REMOTE_BRANCH ]] then + echo "Creating remote branch ${BRANCH} as it doesn't exist..." git checkout --orphan $BRANCH && \ git rm -rf . && \ touch README.md && \ @@ -70,4 +71,4 @@ 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!" \ No newline at end of file +echo "Deployment succesful!" \ No newline at end of file From a2d05161e90f0e6d6dca440ab7bcabc5916db787 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 09:57:32 -0500 Subject: [PATCH 04/11] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index a8b67201..df3874aa 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,7 +41,7 @@ git config --global user.email "${COMMIT_EMAIL}" && \ git config --global user.name "${COMMIT_NAME}" && \ ## Checks to see if the remote exists prior to deploying -REMOTE_BRANCH = `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" docs` +REMOTE_BRANCH = eval `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" docs` # If the branch doesn't exist it gets created here as an orphan. if [[ -z $REMOTE_BRANCH ]] From 2f61184ad3a6d272f11c5817af0e1ed35b3f2b1c Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:07:24 -0500 Subject: [PATCH 05/11] Minor change --- entrypoint.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index df3874aa..1ee7602e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,11 +40,9 @@ git init && \ git config --global user.email "${COMMIT_EMAIL}" && \ git config --global user.name "${COMMIT_NAME}" && \ -## Checks to see if the remote exists prior to deploying -REMOTE_BRANCH = eval `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" docs` - +# Checks to see if the remote exists prior to deploying. # If the branch doesn't exist it gets created here as an orphan. -if [[ -z $REMOTE_BRANCH ]] +if [ `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" $BRANCH` ] then echo "Creating remote branch ${BRANCH} as it doesn't exist..." git checkout --orphan $BRANCH && \ From f8625bcad86e93055e237aabd49630b2687ccb92 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:10:49 -0500 Subject: [PATCH 06/11] Pipe to wc --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1ee7602e..8101a269 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -42,7 +42,7 @@ git config --global user.name "${COMMIT_NAME}" && \ # 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 "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" $BRANCH` ] +if [ `git ls-remote --heads "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" $BRANCH | wc -l` ] then echo "Creating remote branch ${BRANCH} as it doesn't exist..." git checkout --orphan $BRANCH && \ From 24bc61ee6d3e5b80adcd177549f9bac847dd3ec5 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:19:38 -0500 Subject: [PATCH 07/11] Changing order --- entrypoint.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8101a269..f9dfcb08 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,6 +40,9 @@ 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 "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" $BRANCH | wc -l` ] @@ -50,16 +53,12 @@ then touch README.md && \ git add README.md && \ git commit -m "Initial ${BRANCH} commit" && \ - git push origin $BRANCH + git push $REPOSITORY_PATH $BRANCH fi # Checks out the base branch to begin the deploy process. git checkout "${BASE_BRANCH:-master}" && \ -## Initializes the repository path using the access token. -REPOSITORY_PATH="https://${ACCESS_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" && \ - - # Builds the project if a build script is provided. echo "Running build scripts... $BUILD_SCRIPT" && \ eval "$BUILD_SCRIPT" && \ From 009a04cdd76a1428d6755a498362bd2794e25a96 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:26:02 -0500 Subject: [PATCH 08/11] Updating the README for the changes --- README.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 781bf483..b693b59d 100644 --- a/README.md +++ b/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" { From 752f33ab7d9ec22bcd6ae76cafc6f3466bf22130 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:28:36 -0500 Subject: [PATCH 09/11] Changing value --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index f9dfcb08..0dafb7c6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ 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 "https://${ACCESS_TOKEN}@github.com:JamesIves/reddit-viewer.git" $BRANCH | wc -l` ] +if [ `git ls-remote --heads $REPOSITORY_PATH $BRANCH | wc -l` ] then echo "Creating remote branch ${BRANCH} as it doesn't exist..." git checkout --orphan $BRANCH && \ From 92a59fd352c66532e437f49fb87c910980933bde Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:40:11 -0500 Subject: [PATCH 10/11] Only if false --- entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0dafb7c6..e36fb44e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,9 +45,10 @@ 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` ] +if [ `git ls-remote --heads $REPOSITORY_PATH $BRANCH | wc -l` = false ] 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 && \ From 3ea85cffd528865ca4287974042d9092790d6664 Mon Sep 17 00:00:00 2001 From: James Ives Date: Mon, 4 Mar 2019 10:54:21 -0500 Subject: [PATCH 11/11] Update entrypoint.sh --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index e36fb44e..c28953ae 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -45,7 +45,7 @@ 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` = false ] +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}" && \