Skip to content

Merge branch 'master' of https://github.com/Yancey-Blog/beg-monorepo #29

Merge branch 'master' of https://github.com/Yancey-Blog/beg-monorepo

Merge branch 'master' of https://github.com/Yancey-Blog/beg-monorepo #29

name: backend
on:
push:
paths:
- 'apps/backend/**'
branches:
- '**'
pull_request:
paths:
- 'apps/backend/**'
branches:
- '**'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.2
- name: Install dependencies
run: pnpm install
- name: Pre compilation
run: pnpm run build --filter backend
# テスト成功時はこちらのステップが実行される
- name: Slack Notification on Success at Testing Stage
if: success()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOKS }}
SLACK_CHANNEL: github-actions
SLACK_TITLE: Test Success
SLACK_COLOR: good
SLACK_FOOTER: 'Powered by Yancey Inc. and its affiliates.'
# テスト失敗時はこちらのステップが実行される
- name: Slack Notification on Failure at Testing Stage
uses: rtCamp/action-slack-notify@v2
if: failure()
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOKS }}
SLACK_CHANNEL: github-actions
SLACK_TITLE: Test Failure
SLACK_COLOR: danger
SLACK_FOOTER: 'Powered by Yancey Inc. and its affiliates.'
deployment:
runs-on: ubuntu-latest
continue-on-error: true
needs: test
if: github.ref == 'refs/heads/master'
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install Pnpm
uses: pnpm/action-setup@v4
with:
version: 9.14.2
- name: Install dependencies
run: pnpm install
- name: Compilation
run: pnpm run build --filter backend
- name: Prepare files for deployment
run: |
mkdir -p dist
cp -r apps/backend/dist/* dist/
- name: Copy file via ssh key
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.SSH_KEY }}
source: 'dist/*'
target: '/var/www/beg-monorepo/apps/backend'
overwrite: true
- name: SSH to Server and Run Command
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: ${{ secrets.PORT }}
key: ${{ secrets.SSH_KEY }}
script: |
cd /var/www/beg-monorepo/apps/backend
/home/${{ secrets.USERNAME }}/.local/share/pnpm/pm2 reload ecosystem.config.js
# テスト成功時はこちらのステップが実行される
- name: Slack Notification on Success at Deployment Stage
if: success()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOKS }}
SLACK_CHANNEL: github-actions
SLACK_TITLE: Deploy Success
SLACK_COLOR: good
SLACK_FOOTER: 'Powered by Yancey Inc. and its affiliates.'
# テスト失敗時はこちらのステップが実行される
- name: Slack Notification on Failure at Deployment Stage
uses: rtCamp/action-slack-notify@v2
if: failure()
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOKS }}
SLACK_CHANNEL: github-actions
SLACK_TITLE: Deploy Failure
SLACK_COLOR: danger
SLACK_FOOTER: 'Powered by Yancey Inc. and its affiliates.'