Merge pull request #24 from miksrv/develop #42
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: Deploy Production | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
ssh-deploy: | |
name: Production | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
cache-dependency-path: yarn.lock | |
- name: Cache node modules | |
uses: actions/cache@v4 | |
id: cache-production-npm | |
with: | |
path: | | |
node_modules | |
~/.npm | |
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-production-modules- | |
${{ runner.os }}-production | |
- if: ${{ steps.cache-production-npm.outputs.cache-hit != 'true' }} | |
name: Install dependencies | |
run: yarn install | |
- name: Cache UI build | |
uses: actions/cache@v4 | |
id: cache-production-build | |
with: | |
path: build | |
key: ${{ runner.os }}-production-build-${{ hashFiles('**/*.ts', '**/*.tsx') }} | |
restore-keys: | | |
${{ runner.os }}-production-build- | |
${{ runner.os }}-production | |
- name: Build UI | |
run: | | |
export dateNow=$(date +"%d.%m.%Y %H:%M") | |
echo "export const update = '$dateNow'" > src/update.ts | |
echo "REACT_APP_API_HOST = '${{ secrets.REACT_APP_API_PRODUCTION_HOST }}' | |
GENERATE_SOURCEMAP = false" > .env | |
yarn build | |
- name: Build API | |
run: | | |
echo "<?php | |
const SMTP_HOST = '${{ secrets.SMTP_HOST }}'; | |
const SMTP_PORT = ${{ secrets.SMTP_PORT }}; | |
const SMTP_LOGIN = '${{ secrets.SMTP_LOGIN }}'; | |
const SMTP_PASS = '${{ secrets.SMTP_PASS }}'; | |
const EMAIL_SENDERS = [${{ secrets.EMAIL_SENDERS }}];" > api/config.php | |
- name: Find and Rename Files | |
run: | | |
js_file=$(find build/static/js -name 'main.*.js') | |
css_file=$(find build/static/css -name 'main.*.css') | |
mv "$js_file" build/static/js/main.js | |
mv "$css_file" build/static/css/main.css | |
# If for deployment we use SSH | |
#- name: Configure SSH | |
# env: | |
# SSH_HOST: ${{secrets.SSH_HOST}} | |
# SSH_PORT: ${{secrets.SSH_PORT}} | |
# SSH_USER: ${{secrets.SSH_USER}} | |
# SSH_KEY: ${{secrets.SSH_KEY}} | |
# run: | | |
# mkdir -p ~/.ssh/ | |
# echo "$SSH_KEY" > ~/.ssh/authorized_keys | |
# chmod 400 ~/.ssh/authorized_keys | |
# cat >>~/.ssh/config <<END | |
# Host vps | |
# HostName $SSH_HOST | |
# Port $SSH_PORT | |
# User $SSH_USER | |
# IdentityFile ~/.ssh/authorized_keys | |
# StrictHostKeyChecking no | |
# END | |
#- name: Send files | |
# run: rsync -avz -e ssh ./out/ vps:/var/www/asteroid.miksoft.pro | |
- name: Install LFTP | |
run: sudo apt install lftp | |
- name: Configure LFTP | |
run: mkdir ~/.lftp && echo "set ssl:verify-certificate false;" >> ~/.lftp/rc | |
- name: Load Secrets | |
run: echo "machine ${{ secrets.FTP_PRODUCTION_HOSTNAME }} login ${{ secrets.FTP_PRODUCTION_USERNAME }} password ${{ secrets.FTP_PRODUCTION_PASSWORD }}" > ~/.netrc | |
- name: Upload Files | |
run: | | |
lftp -e "rm /api/index.php" ${{ secrets.FTP_PRODUCTION_HOSTNAME }} | |
lftp -e "mirror --parallel=100 -R api/ api/" ${{ secrets.FTP_PRODUCTION_HOSTNAME }} | |
lftp -e "put -O / build/static/js/main.js" ${{ secrets.FTP_PRODUCTION_HOSTNAME }} | |
lftp -e "put -O / build/static/css/main.css" ${{ secrets.FTP_PRODUCTION_HOSTNAME }} |