Update README.md #125
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 PROD | |
env: | |
JWT_SIGNATURE: ${{ vars.JWT_SIGNATURE }} | |
CORS_ALLOW_URL: ${{ vars.CORS_ALLOW_URL }} | |
API_PORT: ${{ vars.API_PORT }} | |
CLIENT_ID: ${{ vars.CLIENT_ID }} | |
CLIENT_SECRET: ${{ vars.CLIENT_SECRET }} | |
on: | |
push: | |
branches: | |
- dev | |
- main | |
workflow_dispatch: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set ENV | |
run: | | |
if [ "${{ github.ref }}" == "refs/heads/main" ]; then | |
echo "SERVER_HOST=${{ vars.PROD_SERVER_HOST }}" >> $GITHUB_ENV | |
echo "SERVER_USERNAME=${{ vars.PROD_SERVER_USERNAME }}" >> $GITHUB_ENV | |
elif [ "${{ github.ref }}" == "refs/heads/dev" ]; then | |
echo "SERVER_HOST=${{ vars.DEV_SERVER_HOST }}" >> $GITHUB_ENV | |
echo "SERVER_USERNAME=${{ vars.DEV_SERVER_USERNAME }}" >> $GITHUB_ENV | |
fi | |
- name: Deploy to Server | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ env.SERVER_HOST }} | |
username: ${{ env.SERVER_USERNAME }} | |
key: ${{ vars.SSH_PRIVATE_KEY }} | |
port: ${{ vars.SSH_PORT }} | |
script: | | |
echo "--------" | |
echo "### CMD: cd BikeHub" | |
cd BikeHub | |
echo "Done!" | |
echo "--------" | |
echo "### CMD: git reset --hard" | |
git reset --hard | |
echo "Done!" | |
echo "--------" | |
echo "### CMD: find . -name 'package-lock.json' -exec rm -f {} +" | |
find . -name 'package-lock.json' -exec rm -f {} + | |
echo "### CMD: find . -name 'yarn.lock' -exec rm -f {} +" | |
find . -name 'yarn.lock' -exec rm -f {} + | |
echo "Done!" | |
echo "--------" | |
branch_name=$(basename "${{ github.ref }}") | |
echo "### CMD: git switch $branch_name" | |
git switch "$branch_name" | |
echo "Done!" | |
echo "--------" | |
echo "### CMD: git pull origin $branch_name" | |
git pull origin $branch_name | |
echo "Done!" | |
echo "--------" | |
echo "### CMD: npm install &deploy.txt& yarn install" | |
npm install && yarn install | |
echo "Done!" | |
echo "--------" | |
echo "### CMD: cd ~/BikeHub/api && cp .env.example .env" | |
cd ~/BikeHub/api && cp .env.example .env | |
echo "Done!" | |
echo "--------" | |
if [ "${{ github.ref }}" = "refs/heads/main" ]; then | |
echo "start deploying in ${{ github.ref }}" | |
echo "### CMD: change VITE_MODE to prod" | |
sed -i 's/^VITE_MODE=.*/VITE_MODE=prod/' ~/BikeHub/frontend/.env | |
echo "Done!" | |
echo "### CMD: change DB_MODE/NODE_ENV to local" | |
sed -i 's/^NODE_ENV=.*/NODE_ENV=prod/' ~/BikeHub/api/.env | |
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env | |
echo "Done!" | |
echo "### CMD: cd ~/BikeHub/api && yarn build" | |
cd ~/BikeHub/api && yarn build | |
echo "### CMD: pm2 reload startapi --update-env" | |
pm2 reload startapi --update-env | |
echo "### CMD: cd ~/BikeHub/frontend && yarn build" | |
cd ~/BikeHub/frontend && yarn build | |
echo "### CMD: pm2 reload startfrontend --update-env" | |
pm2 reload startfrontend --update-env | |
echo "### CMD: pm2 reload prisma --update-env" | |
pm2 reload prisma --update-env | |
echo "### CMD: update deploy.txt" | |
echo "---------------------------" >> deploy.txt | |
echo "Date: $(date)" >> deploy.txt | |
echo "Branch: ${{ github.ref }}" >> deploy.txt | |
echo "Last Commit Message: ${{ github.event.head_commit.message }}" >> deploy.txt | |
echo "Last Commit Author: ${{ github.event.head_commit.author.name }}" >> deploy.txt | |
echo "Pusher: ${{ github.actor }}" >> deploy.txt | |
if [ "${{ github.event_name }}" = "pull_request" ]; then | |
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}" >> deploy.txt | |
echo "Merged By: ${{ github.event.pull_request.merged_by.login }}" >> deploy.txt | |
fi | |
echo "### CMD: cp deploy.txt dist/deploy.txt" | |
cp deploy.txt dist/deploy.txt | |
echo "Done!" | |
fi | |
if [ "${{ github.ref }}" = "refs/heads/dev" ]; then | |
echo "start deploying in ${{ github.ref }}" | |
echo "### CMD: change VITE_MODE to dev" | |
sed -i 's/^VITE_MODE=.*/VITE_MODE=dev/' ~/BikeHub/frontend/.env | |
echo "Done!" | |
echo "### CMD: change DB_MODE/NODE_ENV to local" | |
sed -i 's/^NODE_ENV=.*/NODE_ENV=dev/' ~/BikeHub/api/.env | |
sed -i 's/^DB_MODE=.*/DB_MODE=local/' ~/BikeHub/api/.env | |
echo "Done!" | |
echo "### CMD: cd ~/BikeHub/api && yarn build" | |
cd ~/BikeHub/api && yarn build | |
echo "### CMD: pm2 reload startapi --update-env" | |
pm2 reload startapi --update-env | |
echo "### CMD: cd ~/BikeHub/frontend && yarn build" | |
cd ~/BikeHub/frontend && yarn build | |
echo "### CMD: pm2 reload startfrontend --update-env" | |
pm2 reload startfrontend --update-env | |
echo "### CMD: pm2 reload prisma --update-env" | |
pm2 reload prisma --update-env | |
echo "### CMD: update deploy.txt" | |
echo "---------------------------" >> deploy.txt | |
echo "Date: $(date)" >> deploy.txt | |
echo "Branch: ${{ github.ref }}" >> deploy.txt | |
echo "Last Commit Message: ${{ github.event.head_commit.message }}" >> deploy.txt | |
echo "Last Commit Author: ${{ github.event.head_commit.author.name }}" >> deploy.txt | |
echo "Pusher: ${{ github.actor }}" >> deploy.txt | |
if [ "${{ github.event_name }}" = "pull_request" ]; then | |
echo "Pull Request Author: ${{ github.event.pull_request.user.login }}" >> deploy.txt | |
echo "Merged By: ${{ github.event.pull_request.merged_by.login }}" >> deploy.txt | |
fi | |
echo "### CMD: cp deploy.txt dist/deploy.txt" | |
cp deploy.txt dist/deploy.txt | |
echo "Done!" | |
fi | |
echo "--------" |