Skip to content

Commit

Permalink
feat(hostname): add hostname 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAugustin committed Mar 2, 2022
1 parent 022988a commit cb89c88
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v0.2.1-draft
uses: AndreasAugustin/actions-template-sync@v0.3.0-draft
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: <owner/repo>
Expand All @@ -59,7 +59,8 @@ You will receive a pull request within your repository if there are some changes
| source_repo_path | Repository path of the template | `true` | |
| upstream_branch | The target branch | `true` | `main` |
| source_repo_ssh_private_key | `[optional]` private ssh key for the source repository. E.q. useful if using a private template repository. [see](#private-template-repository)| `false` | |
| pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels] | `false` | `chore,template_sync` |
| pr_labels | `[optional]` comma separated list. [pull request labels][pr-labels]. Must be already created. | `false` | `chore,template_sync` |
| hostname | `[optional]` the hostname of the repository | `false` | `github.com` |

### Example

Expand Down Expand Up @@ -91,7 +92,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v0.2.1-draft
uses: AndreasAugustin/actions-template-sync@v0.3.0-draft
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # <owner/repo>, should be within secrets
Expand Down
8 changes: 6 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ inputs:
pr_labels:
description: '[optional] comma separated list of pull request labels'
default: 'chore,template-sync'
hostname:
description: '[optional] the hostname of the GitHub repository'
default: 'github.com'
runs:
using: 'docker'
image: 'src/Dockerfile'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
SOURCE_REPO_PATH: ${{ inputs.source_repo_path }}
UPSTREAM_BRANCH: ${{ inputs.upstream_branch }}
SSH_PRIVATE_KEY_SRC: ${{ inputs.source_repo_ssh_private_key}}
PR_LABELS: ${{inputs.pr_labels}}
SSH_PRIVATE_KEY_SRC: ${{ inputs.source_repo_ssh_private_key }}
PR_LABELS: ${{ inputs.pr_labels }}
HOSTNAME: ${{ inputs.hostname }}
8 changes: 5 additions & 3 deletions src/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ if [[ -z "${SOURCE_REPO_PATH}" ]]; then
exit 1
fi

SOURCE_REPO_HOSTNAME="${HOSTNAME:-github.com}"

# In case of private template repository this will be overwritten
SOURCE_REPO_PREFIX="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/"
SOURCE_REPO_PREFIX="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${SOURCE_REPO_HOSTNAME}/"

# Forward to /dev/null to swallow the output of the private key
if [[ -n "${SSH_PRIVATE_KEY_SRC}" ]] &>/dev/null; then
Expand All @@ -26,14 +28,14 @@ if [[ -n "${SSH_PRIVATE_KEY_SRC}" ]] &>/dev/null; then
# use cat <<< instead of echo to swallow output of the private key
cat <<< "${SSH_PRIVATE_KEY_SRC}" | sed 's/\\n/\n/g' > "${SRC_SSH_PRIVATEKEY_ABS_PATH}"
chmod 600 "${SRC_SSH_PRIVATEKEY_ABS_PATH}"
SOURCE_REPO_PREFIX="git@github.com:"
SOURCE_REPO_PREFIX="git@${SOURCE_REPO_HOSTNAME}:"
fi

export SOURCE_REPO="${SOURCE_REPO_PREFIX}${SOURCE_REPO_PATH}"

echo "::group::git init"
echo "set git global configuration"
git config --global user.email "github-action@actions-template-sync.noreply.github.com"
git config --global user.email "github-action@actions-template-sync.noreply.${SOURCE_REPO_HOSTNAME}"
git config --global user.name "${GITHUB_ACTOR}"
git config --global pull.rebase false
echo "::endgroup::"
Expand Down

0 comments on commit cb89c88

Please sign in to comment.