Skip to content

Commit

Permalink
Enforce target_branch by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ayr-ton committed Apr 11, 2022
1 parent f3c7211 commit f0ebf11
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ jobs:
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- uses: ./
with:
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
target_repo_url: [email protected]:ayr-ton/git-deploy-action-test.git
target_branch: gh-pages-test
target_branch: main
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ Be sure to run the [`actions/checkout`](https://github.com/actions/checkout) act
this action so that the git repository is initialized.

```yaml
# File: .github/workflows/mirror.yml
- uses: ayr-ton/git-deploy-action@v1
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: main
- uses: ayr-ton/[email protected]
with:
# The SSH private key for SSH connection to the target repository.
# We strongly recommend saving this value as a GitHub Secret and using deploy
# keys within the target repository
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
# The SSH-based URL to the target repository
target_repo_url: [email protected]:ayr-ton/git-deploy-action-test.git
# The branch to push to the target repository, defaults to the current branch
# The branch to push to the target repository, mandatory
target_branch: main
```
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ inputs:
description: Target git repository URL
required: true
target_branch:
description: Target git branch name, if any
required: false
description: Target git branch name
required: true
runs:
using: 'docker'
image: 'Dockerfile'
9 changes: 3 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ mkdir -p /root/.ssh
echo "$INPUT_SSH_PRIVATE_KEY" > /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa

git remote add destination "$INPUT_TARGET_REPO_URL"

if [ -n "${INPUT_TARGET_BRANCH+set}" ];
then
git checkout $INPUT_TARGET_BRANCH
git remote add destination "$INPUT_TARGET_REPO_URL"
git push destination "$INPUT_TARGET_BRANCH" -f
echo "Pushed to branch $INPUT_TARGET_BRANCH"
echo "Synced with $INPUT_TARGET_BRANCH"
else
git push destination "$GITHUB_REF" -f
echo "Pushed to branch $GITHUB_REF"
echo "You need to set a target_branch"
fi

0 comments on commit f0ebf11

Please sign in to comment.