generated from AndreasAugustin/template
-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refact: 🧑💻 small restructure of the code (#491)
* docs: 📝 update docs * refact: 🧑💻 small restructur
- Loading branch information
1 parent
efe3793
commit d9e61fc
Showing
3 changed files
with
105 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ set -e | |
# shellcheck source=src/sync_common.sh | ||
source sync_common.sh | ||
|
||
########################################### | ||
# Precheks | ||
########################################## | ||
|
||
if [[ -z "${GITHUB_TOKEN}" ]]; then | ||
err "Missing input 'github_token: \${{ secrets.GITHUB_TOKEN }}'."; | ||
exit 1; | ||
|
@@ -16,6 +20,10 @@ if [[ -z "${SOURCE_REPO_PATH}" ]]; then | |
exit 1 | ||
fi | ||
|
||
############################################ | ||
# Variables | ||
############################################ | ||
|
||
DEFAULT_REPO_HOSTNAME="github.com" | ||
SOURCE_REPO_HOSTNAME="${HOSTNAME:-${DEFAULT_REPO_HOSTNAME}}" | ||
GIT_USER_NAME="${GIT_USER_NAME:-${GITHUB_ACTOR}}" | ||
|
@@ -24,6 +32,10 @@ GIT_USER_EMAIL="${GIT_USER_EMAIL:[email protected].${ | |
# In case of ssh template repository this will be overwritten | ||
SOURCE_REPO_PREFIX="https://${SOURCE_REPO_HOSTNAME}/" | ||
|
||
################################################ | ||
# Functions | ||
################################################ | ||
|
||
function ssh_setup() { | ||
echo "::group::ssh setup" | ||
|
||
|
@@ -53,18 +65,9 @@ function gpg_setup() { | |
git config --global gpg.program /bin/gpg_no_tty.sh | ||
|
||
info "done prepare gpg" | ||
echo "::endgroup::"for fpr in | ||
echo "::endgroup::" | ||
} | ||
|
||
# Forward to /dev/null to swallow the output of the private key | ||
if [[ -n "${SSH_PRIVATE_KEY_SRC}" ]] &>/dev/null; then | ||
ssh_setup | ||
elif [[ "${SOURCE_REPO_HOSTNAME}" != "${DEFAULT_REPO_HOSTNAME}" ]]; then | ||
gh auth login --git-protocol "https" --hostname "${SOURCE_REPO_HOSTNAME}" --with-token <<< "${GITHUB_TOKEN}" | ||
fi | ||
|
||
export SOURCE_REPO="${SOURCE_REPO_PREFIX}${SOURCE_REPO_PATH}" | ||
|
||
function git_init() { | ||
echo "::group::git init" | ||
info "set git global configuration" | ||
|
@@ -86,6 +89,19 @@ function git_init() { | |
echo "::endgroup::" | ||
} | ||
|
||
################################################### | ||
# Logic | ||
################################################### | ||
|
||
# Forward to /dev/null to swallow the output of the private key | ||
if [[ -n "${SSH_PRIVATE_KEY_SRC}" ]] &>/dev/null; then | ||
ssh_setup | ||
elif [[ "${SOURCE_REPO_HOSTNAME}" != "${DEFAULT_REPO_HOSTNAME}" ]]; then | ||
gh auth login --git-protocol "https" --hostname "${SOURCE_REPO_HOSTNAME}" --with-token <<< "${GITHUB_TOKEN}" | ||
fi | ||
|
||
export SOURCE_REPO="${SOURCE_REPO_PREFIX}${SOURCE_REPO_PATH}" | ||
|
||
git_init | ||
|
||
if [[ -n "${GPG_PRIVATE_KEY}" ]] &>/dev/null; then | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters