Skip to content

Commit

Permalink
Merge pull request #16 from weierophinney/hotfix/allow-usage-with-act…
Browse files Browse the repository at this point in the history
…ions-checkout

Update entrypoint to allow usage with actions/checkout
  • Loading branch information
weierophinney authored Mar 5, 2021
2 parents fde2c44 + 78ac7da commit 9e113da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ jobs:
Generally, you will use this as a dependency of a job that uses [laminas/laminas-continuous-integration-action](https://github.com/laminas/laminas-continuous-integration-action), as demonstrated in the above configuration.
> ### DO NOT use actions/checkout
> ### actions/checkout not required
>
> **DO NOT** use the `actions/checkout` action in a step prior to using this action.
> Doing so will lead to errors, as this action performs git checkouts into the WORKDIR, and a non-empty WORKDIR causes that operation to fail.
> An actions/checkout step prior to this action is not required, as it will perform a checkout into the WORKDIR on its own if none has been performed previously.
> We recommend using actions/checkout only if you need to access QA artifacts in a later step.
## Outputs
Expand Down
23 changes: 21 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ function checkout {
local REF=
local LOCAL_BRANCH=
local BASE_BRANCH=

if [[ ! $GITHUB_EVENT_NAME || ! $GITHUB_REPOSITORY || ! $GITHUB_REF ]];then
return
fi

case $GITHUB_EVENT_NAME in
pull_request)
REF=$GITHUB_REF
LOCAL_BRANCH=$GITHUB_HEAD_REF
BASE_BRANCH=$GITHUB_BASE_REF

if [[ ! $LOCAL_BRANCH || ! $BASE_BRANCH ]]; then
echo "Missing head or base ref env variables; aborting"
exit 1
fi
;;
push)
REF=${GITHUB_REF/refs\/heads\//}
Expand All @@ -25,8 +35,17 @@ function checkout {
exit 1
esac

echo "Cloning repository"
git clone https://github.com/"${GITHUB_REPOSITORY}" .
if [ -d ".git" ];then
echo "Updating and fetching from canonical repository"
if [[ $(git remote) =~ origin ]];then
git remote remove origin
fi
git remote add origin https://github.com/"${GITHUB_REPOSITORY}"
git fetch origin
else
echo "Cloning repository"
git clone https://github.com/"${GITHUB_REPOSITORY}" .
fi

if [[ "$REF" == "$LOCAL_BRANCH" ]];then
echo "Checking out ref ${REF}"
Expand Down

0 comments on commit 9e113da

Please sign in to comment.