Skip to content

Workflow file for this run

name: Lint and Deploy to Hosted server
on:
push:
branches: [ main ]
workflow_dispatch:
permissions: write-all
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Declare commit sha variables
id: vars
shell: bash
run: echo "::set-output name=sha::$(echo ${GITHUB_SHA})"
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Node v16
uses: actions/setup-node@v2
with:
node-version: 16
cache: npm
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Check if changes were made
id: check-changes
run: |
if [ -z "$(git diff --name-only HEAD)" ]; \
then echo '::set-output name=changed::false'; \
else echo '::set-output name=changed::true'; fi
- name: Commit files
if: steps.check-changes.outputs.changed == 'true'
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -am ":rotating_light: Lint - ${{ steps.vars.outputs.sha }}"
- name: Push changes
if: steps.check-changes.outputs.changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.gh_token }}
branch: ${{ github.ref }}
- name: Deploy
if: steps.check-changes.outputs.changed == 'false'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }}
password: ${{ secrets.SERVER_PASS }}
port: ${{ secrets.SERVER_PORT }}
script_stop: true
script: |
cd ${{ secrets.SERVER_PATH }}
git checkout .
git pull
docker compose down --remove-orphans
docker compose build
docker compose -f docker-compose.yml up -d --force-recreate