From 969c9ffc2357b792575f482025cb24f516d4e698 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Thu, 15 Jul 2021 12:29:14 +0200 Subject: [PATCH] Moved to octoleo. Adds option to pass config via url. --- .github/workflows/joomla4.0-dev-lang.yml | 13 ++++++------ .github/workflows/keep-active.yml | 12 +++++------ .github/workflows/lang-joomla4.0-dev.yml | 14 ++++++------- .github/workflows/test.yml | 15 +++++++------- .gitignore | 1 + README.md | 17 ++++++++++++---- src/sync.sh | 26 ++++++++++++++++-------- 7 files changed, 59 insertions(+), 39 deletions(-) diff --git a/.github/workflows/joomla4.0-dev-lang.yml b/.github/workflows/joomla4.0-dev-lang.yml index be69c91..550ca1c 100644 --- a/.github/workflows/joomla4.0-dev-lang.yml +++ b/.github/workflows/joomla4.0-dev-lang.yml @@ -15,7 +15,7 @@ jobs: # We use this approach to sign all commits # Also to use basic git commands in the sync script # with no further authentication needed - # see: https://github.com/vdm-io/github-user + # see: https://github.com/octoleo/github-user - name: Setup gitHub User Details # how to set secrets? # see: https://docs.github.com/en/actions/reference/encrypted-secrets @@ -38,11 +38,10 @@ jobs: # A id_ed25519.pub ssh public key liked to the github user account SSH_PUB: ${{ secrets.SSH_PUB }} run: | - /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/vdm-io/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" - - name: Clone Sync Bot Repo - # this is the repo that does the work - run: | - /bin/git clone -b master --single-branch git@github.com:vdm-io/github-sync-bot.git bot + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" - name: Sync The Repo Files + # you can pass your config by url + # this means you can get your config file from anywhere + # we have --dry added here since we are still in development stage once in production we will remove --dry run: | - /bin/bash ./bot/src/sync.sh --conf=bot/conf/joomla4.0-dev-lang --dry + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/octoleo/master/src/sync.sh) --conf=https://raw.githubusercontent.com/octoleo/octoleo/master/conf/joomla4.0-dev-lang --dry diff --git a/.github/workflows/keep-active.yml b/.github/workflows/keep-active.yml index 0d1226d..f4579aa 100644 --- a/.github/workflows/keep-active.yml +++ b/.github/workflows/keep-active.yml @@ -14,7 +14,7 @@ jobs: # We use this approach to sign all commits # Also to use basic git commands in the sync script # with no further authentication needed - # see: https://github.com/vdm-io/github-user + # see: https://github.com/octoleo/github-user - name: Setup gitHub User Details # how to set secrets? # see: https://docs.github.com/en/actions/reference/encrypted-secrets @@ -35,11 +35,11 @@ jobs: # A id_ed25519.pub ssh public key liked to the github user account SSH_PUB: ${{ secrets.SSH_PUB }} run: | - /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/vdm-io/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" - - name: Clone Bot Repo - # this is the repo that does the work - run: | - /bin/git clone -b master --single-branch git@github.com:vdm-io/github-sync-bot.git bot + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" + - name: Clone Octoleo Repo + # this is the repo that does the work + run: | + /bin/git clone -b master --single-branch git@github.com:octoleo/octoleo.git octoleo - name: Set Active run: | cd bot diff --git a/.github/workflows/lang-joomla4.0-dev.yml b/.github/workflows/lang-joomla4.0-dev.yml index 40016de..e887445 100644 --- a/.github/workflows/lang-joomla4.0-dev.yml +++ b/.github/workflows/lang-joomla4.0-dev.yml @@ -15,7 +15,7 @@ jobs: # We use this approach to sign all commits # Also to use basic git commands in the sync script # with no further authentication needed - # see: https://github.com/vdm-io/github-user + # see: https://github.com/octoleo/github-user - name: Setup gitHub User Details # how to set secrets? # see: https://docs.github.com/en/actions/reference/encrypted-secrets @@ -38,11 +38,11 @@ jobs: # A id_ed25519.pub ssh public key liked to the github user account SSH_PUB: ${{ secrets.SSH_PUB }} run: | - /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/vdm-io/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" - - name: Clone Sync Bot Repo - # this is the repo that does the work - run: | - /bin/git clone -b master --single-branch git@github.com:vdm-io/github-sync-bot.git bot + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" - name: Sync The Repo Files + # you can pass your config by url + # this means you can get your config file from anywhere + # we have --dry added here since we are still in development stage once in production we will remove --dry run: | - /bin/bash ./bot/src/sync.sh --conf=bot/conf/lang-joomla4.0-dev --dry + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/octoleo/master/src/sync.sh) --conf=https://raw.githubusercontent.com/octoleo/octoleo/master/conf/lang-joomla4.0-dev --dry + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 171c454..5009321 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,6 @@ name: "Test Sync Bot" +on: # so we can manually run a sync test workflow_dispatch: @@ -10,7 +11,7 @@ jobs: # We use this approach to sign all commits # Also to use basic git commands in the sync script # with no further authentication needed - # see: https://github.com/vdm-io/github-user + # see: https://github.com/octoleo/github-user - name: Setup gitHub User Details # how to set secrets? # see: https://docs.github.com/en/actions/reference/encrypted-secrets @@ -33,12 +34,12 @@ jobs: # A id_ed25519.pub ssh public key liked to the github user account SSH_PUB: ${{ secrets.SSH_PUB }} run: | - /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/vdm-io/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" + /bin/bash <(/bin/curl -s https://raw.githubusercontent.com/octoleo/github-user/master/src/setup.sh) --gpg-key "$GPG_KEY" --gpg-user "$GPG_USER" --ssh-key "$SSH_KEY" --ssh-pub "$SSH_PUB" --git-user "$GIT_USER" --git-email "$GIT_EMAIL" --git-token "$GIT_TOKEN" - name: Clone Sync Bot Repo - # this is the repo that does the work - run: | - /bin/git clone -b master --single-branch git@github.com:vdm-io/github-sync-bot.git bot + # this is the repo that does the work + run: | + /bin/git clone -b master --single-branch git@github.com:octoleo/octoleo.git octoleo - name: Sync The Repo Files run: | - /bin/bash ./bot/src/sync.sh --conf=bot/conf/joomla4.0-dev-lang --test - /bin/bash ./bot/src/sync.sh --conf=bot/conf/lang-joomla4.0-dev --test \ No newline at end of file + /bin/bash ./octoleo/src/sync.sh --conf=octoleo/conf/joomla4.0-dev-lang --test + /bin/bash ./octoleo/src/sync.sh --conf=octoleo/conf/lang-joomla4.0-dev --test \ No newline at end of file diff --git a/.gitignore b/.gitignore index e15921d..21c0fd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea source_repo target_repo +config_file_from_url diff --git a/README.md b/README.md index 539fb2d..a756ea2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,17 @@ -## Github Sync Bot Setup +# OCTOLEO -- We use this script to setup a github user on the Ubuntu systems in the Github Actions Workflows. See setup instructions below. -- Then the sync of each set of repositories are manage with a config file found in the conf folder. -- So we have to setup multiple workflows for each set repositories (config) you would like to sync. +The option to move files or whole folders from repository to another is what Octoleo does. You can with [configurations](https://github.com/octoleo/octoleo/blob/master/conf/example) setup multiple syncing relationships which you can run in multiple [workflow actions](https://github.com/octoleo/octoleo/blob/master/.github/workflows/test.yml). + +## Octoleo Sync Bot Setup + +- We use this script to setup a github user on the Ubuntu systems in the Github Actions Workflows. [See setup instructions below](https://github.com/octoleo/octoleo#how-to-setup-github-user). +- Then the sync of each set of repositories are managed with a [config file](https://github.com/octoleo/octoleo/blob/master/conf/example) found in the [conf folder](https://github.com/octoleo/octoleo/blob/master/conf). +- So we can then setup [multiple workflows](https://github.com/octoleo/octoleo/blob/master/.github/workflows) for each set repositories (config) you would like to sync. + +Examples: +```yml + +``` ### How To SETUP gitHub User diff --git a/src/sync.sh b/src/sync.sh index b8830c5..9f8714b 100755 --- a/src/sync.sh +++ b/src/sync.sh @@ -5,18 +5,17 @@ command -v git >/dev/null 2>&1 || { echo >&2 "We require git for this script to run, but it's not installed. Aborting." exit 1 } -# command -v gh >/dev/null 2>&1 || { -# echo >&2 "We require github CLI for this script to run, but it's not installed. Aborting." -# exit 1 -# } -# will still add some github toke check (that it exist) +command -v curl >/dev/null 2>&1 || { + echo >&2 "We require curl for this script to run, but it's not installed. Aborting." + exit 1 +} # get start time STARTBUILD=$(date +"%s") # use UTC+00:00 time also called zulu STARTDATE=$(TZ=":ZULU" date +"%m/%d/%Y @ %R (UTC)") # BOT name -BOT_NAME="Github Sync Bot v1.0" +BOT_NAME="Octoleo v1.0" # main function ˘Ô≈ôﺣ function main() { @@ -166,7 +165,7 @@ function rebaseWithUpstream() { # just a random remote name local git_upstream="stroomOp" # go into repo folder - cd ${git_folder} + cd ${git_folder} || exit 23 # check out the upstream repository git checkout -b "${git_upstream}" "$git_branch" git pull ${git_repo_upstream} "$git_branch" @@ -200,7 +199,8 @@ function rebaseWithUpstream() { fi fi # return to original folder - cd "${current_folder}" + cd "${current_folder}" || exit 24 + return 0 } # move the source folders and files to the target folders @@ -605,6 +605,16 @@ while :; do shift done +# check if the config is passed via a URL +if [[ "${CONFIG_FILE}" =~ ^"http:" ]] || [[ "${CONFIG_FILE}" =~ ^"https:" ]]; then + if [[ $(wget -S --spider "${CONFIG_FILE}" 2>&1 | grep 'HTTP/1.1 200 OK') ]]; then + wget --quiet "${CONFIG_FILE}" -O config_file_from_url + CONFIG_FILE="config_file_from_url" + else + echo >&2 "The config:${CONFIG_FILE} is not a valid URL. Aborting." + exit 18 + fi +fi # We must have a config file [ ! -f "${CONFIG_FILE}" ] && echo >&2 "The config:${CONFIG_FILE} is not set or found. Aborting." && exit 18