Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytse committed Jul 17, 2023
1 parent d90a835 commit 535cf24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
token:
description: 'The deploy token'
required: false
ssh_private_key:
description: 'The SSH private key for deployment'
required: false
repository:
description: 'The deploy repository'
required: false
Expand Down
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ WORKING_DIR=${PWD}
# Initial default value
PROVIDER=${INPUT_PROVIDER:=github}
TOKEN=${INPUT_TOKEN}
SSH_PRIVATE_KEY=${INPUT_SSH_PRIVATE_KEY}
ACTOR=${INPUT_ACTOR}
REPOSITORY=${INPUT_REPOSITORY}
BRANCH=${INPUT_BRANCH}
Expand Down Expand Up @@ -121,6 +122,12 @@ build_jekyll || {
build_jekyll
}

# Pre-handle SSH private key
if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
SSH_PRIVATE_KEY_PATH=${WORKING_DIR}/ssh_private_key
cat ""${SSH_PRIVATE_KEY}"" > ${SSH_PRIVATE_KEY_PATH}
fi

cd ${WORKING_DIR}/build

# Check if deploy on the same repository branch
Expand Down
25 changes: 16 additions & 9 deletions providers/github.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
#!/bin/sh
#!/bin/bash
set -e

# Check if deploy to same branch
if [ "${REPOSITORY}" = "${GITHUB_REPOSITORY}" ]; then
if [ "${GITHUB_REF}" = "refs/heads/${BRANCH}" ]; then
if [[ "${REPOSITORY}" = "${GITHUB_REPOSITORY}" ]]; then
if [[ "${GITHUB_REF}" = "refs/heads/${BRANCH}" ]]; then
echo "It's conflicted to deploy on same branch ${BRANCH}"
exit 1
fi
fi

# Tell GitHub Pages not to run Jekyll
touch .nojekyll
[ -n "$INPUT_CNAME" ] && echo "$INPUT_CNAME" > CNAME
[[ -n "$INPUT_CNAME" ]] && echo "$INPUT_CNAME" > CNAME

# Prefer to use SSH approach when SSH private key is provided
if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
REMOTE_REPO="ssh://[email protected]:${REPOSITORY}.git"
echo SSH KEY PATH, ${SSH_PRIVATE_KEY_PATH}
git config --add --local core.sshCommand "ssh -i ${SSH_PRIVATE_KEY_PATH}"
else
REMOTE_REPO="https://${ACTOR}:${TOKEN}@github.com/${REPOSITORY}.git"
fi

echo "Deploying to ${REPOSITORY} on branch ${BRANCH}"
echo "Deploying to https://${ACTOR}:${TOKEN}@github.com/${REPOSITORY}.git"
echo "Deploying to ${REMOTE_REPO}"

REMOTE_REPO="https://${ACTOR}:${TOKEN}@github.com/${REPOSITORY}.git" && \
git config --global http.postBuffer 524288000 && \
git config --global init.defaultBranch main && \
git config --global init.defaultBranch main && \
git init && \
git config user.name "${ACTOR}" && \
git config user.email "${ACTOR}@users.noreply.github.com" && \
git add . && \
git commit -m "jekyll build from Action ${GITHUB_SHA}" && \
git push --force $REMOTE_REPO main:$BRANCH && \
fuser -k .git || rm -rf .git && \
(fuser -k .git || rm -rf .git) && \
cd ..

exit $?

0 comments on commit 535cf24

Please sign in to comment.