Skip to content

Merge branch 'main' of https://github.com/to5ta/js_zero #4

Merge branch 'main' of https://github.com/to5ta/js_zero

Merge branch 'main' of https://github.com/to5ta/js_zero #4

name: Build and Deploy
on:
workflow_dispatch:
push:
branches: [ main ]
jobs:
Deploy-and-Build:
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- name: Install Dependencies 🔧
run: |
npm install
- name: Download assets 📦
run: |
chmod +x src/assets.py
scripts/assets.py --download
- name: Build Web Application 🔨
run: |
npm run build
env:
CI: true
- name: Add Key and Server to Known Hosts 🔑 # only if main
if: github.ref == 'refs/heads/main'
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo "${{ secrets.DEPLOY_KNOWN_HOST }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Deploy via SFTP 🚀
if: github.ref == 'refs/heads/main'
run: |
sftp -oPort=22 -i ~/.ssh/id_rsa ${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_SERVER }} <<EOF
cd public_html/games/js_zero
rm *
put -r dist/*
bye
EOF
- name: Cleanup SSH Key and Known Hosts 🧹
if: always() # Ensure this step runs even if previous steps fail
run: |
# Remove the SSH private key file
rm -f ~/.ssh/id_rsa
# Clear the known hosts file
> ~/.ssh/known_hosts