Skip to content

Commit

Permalink
Update remote git repo to newest deployed version, remote git pull (#55)
Browse files Browse the repository at this point in the history
* Add script for remotely git pull on server from GitHub Action

* Modify Github Action to use the remote git pull script
  • Loading branch information
ctmbl authored May 2, 2024
1 parent c157dfb commit cac3969
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions scripts/remote_git_pull.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cac3969

Please sign in to comment.