From f0ebf116f74edf7ee5e13b973129c988690d7f25 Mon Sep 17 00:00:00 2001 From: Ayrton Date: Mon, 11 Apr 2022 15:34:52 -0300 Subject: [PATCH] Enforce target_branch by default --- .github/workflows/test.yml | 5 +++-- README.md | 9 ++++++--- action.yml | 4 ++-- entrypoint.sh | 9 +++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9c46c3f..ba776c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: git@github.com:ayr-ton/git-deploy-action-test.git - target_branch: gh-pages-test + target_branch: main diff --git a/README.md b/README.md index 4ea8cdd..48b4593 100644 --- a/README.md +++ b/README.md @@ -16,8 +16,11 @@ 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/git-deploy-action@v1.1 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 @@ -25,7 +28,7 @@ this action so that the git repository is initialized. ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} # The SSH-based URL to the target repository target_repo_url: git@github.com: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 ``` diff --git a/action.yml b/action.yml index 758ec0c..4d1a6e0 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh index 70cfefa..282a0ab 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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