LIVE - Update and Restart the NutriLog
App
#10
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
name: LIVE - Update and Restart the `NutriLog` App | |
# Trigger action manually | |
on: workflow_dispatch | |
env: | |
APP_DIR: /home/${{vars.USER}}/inst/app/nutrilog/ # Directory of the application | |
PRJ: nutrilog # The name of the project | |
SERVICE: appNutriLog.service # The name of the service to manage | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out the repository on the GitHub environment. | |
uses: actions/checkout@v3 | |
- name: Install dependencies and build the project. | |
run: | | |
npm install --omit=optional --omit=dev | |
- name: Add application files to the archive. | |
uses: montudor/action-zip@v1 | |
with: | |
args: zip -qq --exclude=*.git* -r ${{env.PRJ}}.zip ./ | |
- name: Validate the existence of the archive. | |
run: | | |
pwd | |
ls -lh | |
- name: Validate SSH connection. | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{vars.HOST}} | |
username: ${{vars.USER}} | |
key: ${{secrets.SSH_KEY}} | |
script: | | |
pwd | |
whoami | |
- name: Copy files to Remote Server. | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{vars.HOST}} | |
username: ${{vars.USER}} | |
key: ${{secrets.SSH_KEY}} | |
source: ${{env.PRJ}}.zip | |
target: ${{env.APP_DIR}} | |
- name: Extract files on Remote Server and switch site to the new instance. | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{vars.HOST}} | |
username: ${{vars.USER}} | |
key: ${{secrets.SSH_KEY}} | |
script: | | |
cd "${{env.APP_DIR}}/" | |
rm -fr prod.old | |
mkdir prod.new | |
unzip ${{env.PRJ}}.zip -d ./prod.new/ &> /dev/null | |
echo sudo /bin/systemctl stop ${{env.SERVICE}} | |
mv ./prod ./prod.old | |
mv ./prod.new ./prod | |
echo cp ./prod.old/cfg/local* ./prod/cfg/ | |
echo sudo /bin/systemctl start ${{env.SERVICE}} | |
TIMESTAMP=$(date +%Y%m%d-%H%M%S) | |
mv ${{env.PRJ}}.zip ${{env.PRJ}}-${TIMESTAMP}.zip | |
echo "Archive renamed to: ${{env.PRJ}}-${TIMESTAMP}.zip" | |
ls -lh ${{env.APP_DIR}} |