From cac3969010e4d5f17b9f566b12ba778d087bd85f Mon Sep 17 00:00:00 2001 From: ClementMabileau Date: Fri, 3 May 2024 01:42:27 +0200 Subject: [PATCH] Update remote git repo to newest deployed version, remote git pull (#55) * Add script for remotely git pull on server from GitHub Action * Modify Github Action to use the remote git pull script --- .github/workflows/build_and_deploy.yml | 8 ++++-- scripts/remote_git_pull.sh | 40 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 scripts/remote_git_pull.sh diff --git a/.github/workflows/build_and_deploy.yml b/.github/workflows/build_and_deploy.yml index 6e4ed21..a4f3aaf 100644 --- a/.github/workflows/build_and_deploy.yml +++ b/.github/workflows/build_and_deploy.yml @@ -44,7 +44,7 @@ jobs: # - SSH_KNOWN_HOSTS # - PRIVATE_SSH_KEY # - CI_USER_NAME - # - STATIC_WEBSITE_PATH + # - REPO_PATH_ON_REMOTE deploy: needs: [build] # DISCLAIMER: @@ -83,7 +83,11 @@ jobs: # Upload the build to the remote server location: the volume shared by the nginx container serving http requests - name: 🚀 Upload run: | - rsync --archive --stats --verbose --delete ./build/blog/* ${{ secrets.CI_USER_NAME }}@iscsc.fr:${{ secrets.STATIC_WEBSITE_PATH}} + rsync --archive --stats --verbose --delete ./build/blog/* ${{ secrets.CI_USER_NAME }}@iscsc.fr:${{ secrets.REPO_PATH_ON_REMOTE }}/build/blog + + - name: ⏬ Remote git pull + run: | + ssh ${{ secrets.CI_USER_NAME }}@iscsc.fr /usr/bin/bash ${{ secrets.REPO_PATH_ON_REMOTE }}/scripts/remote_git_pull.sh ${{ secrets.REPO_PATH_ON_REMOTE }} # Finally notify of the new article (if any) on the iScsc discord server # action jitterbit/get-changed-files@v1 doesn't support 'workflow_dispatch' events: https://github.com/jitterbit/get-changed-files/issues/38 diff --git a/scripts/remote_git_pull.sh b/scripts/remote_git_pull.sh new file mode 100644 index 0000000..4ce72a8 --- /dev/null +++ b/scripts/remote_git_pull.sh @@ -0,0 +1,40 @@ +#!/usr/bin/bash + +PATH=$(/usr/bin/getconf PATH || /bin/kill $$) + +die() { + echo "[!] Something went wrong, exiting..." + exit 1 +} + +echo "[+] Connected to iscsc.fr" + +if [ $# -ne 1 ]; then + echo "[!] Must provide one and only one argument: repo path on remote"; + die; +fi +REPO_PATH="$1"; shift + +echo "[+] Change directory" +cd ${REPO_PATH} || die + +REMOTE_URL="iscsc/blog.iscsc.fr" +REMOTE_NAME=$(git remote -v | grep --ignore-case "${REMOTE_URL}" | grep "(fetch)" | awk '{print $1}') +MAIN_BRANCH_NAME=main + +echo "[+] iScsc remote name is '${REMOTE_NAME}'" +echo "[+] Fetch '${MAIN_BRANCH_NAME}' from '${REMOTE_NAME}'" +git fetch "${REMOTE_NAME}" "${MAIN_BRANCH_NAME}" || die + +echo "[+] Checkout on '${MAIN_BRANCH_NAME}'" +git checkout "${MAIN_BRANCH_NAME}" || die + +REMOTE_MAIN_REF_NAME="${REMOTE_NAME}/${MAIN_BRANCH_NAME}" + +echo "[+] Remote ref is '${REMOTE_MAIN_REF_NAME}'" +echo "[+] Rebase on '${REMOTE_MAIN_REF_NAME}'" +git rebase "${REMOTE_MAIN_REF_NAME}" || die + +echo "[+] git log from here:" +git log --color --decorate --oneline --max-count=20 main +