Skip to content

deploy main on production #4

deploy main on production

deploy main on production #4

name: deploy main on production
on:
workflow_run:
workflows: ["merge dev to main"]
types: [completed]
jobs:
deploy:
name: deploy
runs-on: ubuntu-latest
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
- name: Setup .env file
run: |
echo "
MODE=prod
RELEASE=$(git rev-parse --short HEAD)
RELEASED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
PORT=${{ secrets.POSTFOO_HOST_PORT }}
DATABASE_URL=\"${{ secrets.POSTFOO_DB_URL }}\"
SEND_PULSE_API_USER_ID=${{ secrets.POSTFOO_SEND_PULSE_API_USER_ID }}
SEND_PULSE_API_USER_SECRET=${{ secrets.POSTFOO_SEND_PULSE_API_USER_SECRET }}
AUTH_PRIVATE_KEY=\"${{ secrets.POSTFOO_AUTH_PRIVATE_KEY }}\"
AUTH_PUBLIC_KEY=\"${{ secrets.POSTFOO_AUTH_PUBLIC_KEY }}\"
" > .env
cat .env
- name: Add environment variables to Github
run: |
stage=$(git rev-parse --abbrev-ref HEAD)
echo "STAGE=$stage" >> $GITHUB_ENV
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Install Node.js dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Build
run: npm run build
- name: Stop the Server
uses: garygrossgarten/github-action-ssh@release
with:
host: ${{ secrets.POSTFOO_SSH_HOST }}
port: ${{ secrets.POSTFOO_SSH_PORT }}
username: ${{ secrets.POSTFOO_SSH_USERNAME }}
privateKey: ${{ secrets.POSTFOO_SSH_PKEY }}
command: cd /root/spiderman/postfoo-server; pm2 stop spiderman; pm2 delete spiderman; mkdir -p /root/spiderman/postfoo-server
- name: Deploy to DigitalOcean
uses: burnett01/rsync-deployments@7.0.1
with:
switches: -avzr --delete --checksum
remote_path: /root/spiderman/postfoo-server
remote_host: ${{ secrets.POSTFOO_SSH_HOST }}
remote_port: ${{ secrets.POSTFOO_SSH_PORT }}
remote_user: ${{ secrets.POSTFOO_SSH_USERNAME }}
remote_key: ${{ secrets.POSTFOO_SSH_PKEY }}
- name: Start the Server
uses: garygrossgarten/github-action-ssh@release
with:
host: ${{ secrets.POSTFOO_SSH_HOST }}
port: ${{ secrets.POSTFOO_SSH_PORT }}
username: ${{ secrets.POSTFOO_SSH_USERNAME }}
privateKey: ${{ secrets.POSTFOO_SSH_PKEY }}
command: cd /root/spiderman/postfoo-server; pm2 start npm --name "spiderman" -- start