auto-cd(dev) #90
This file contains hidden or 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: auto-cd(dev) | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| dev_command: | |
| type: choice | |
| required: true | |
| description: 'dev command' | |
| options: | |
| - yarn dev | |
| - yarn dev:test | |
| env: | |
| SERVER_HOST: ${{ secrets.DEV_SERVER_HOST }} | |
| SERVER_USER: ${{ secrets.DEV_SERVER_USER }} | |
| SERVER_SSH_KEY: ${{ secrets.DEV_SERVER_SSH_KEY }} | |
| SERVER_SSH_PASSPHRASE: ${{ secrets.DEV_SERVER_SSH_PASSPHRASE }} | |
| DEPLOY_PATH: choose-tale/Backend | |
| BRANCH: ${{github.ref_name}} | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v3 | |
| - name: echo env | |
| run: | | |
| echo ${{ env.DEPLOY_PATH }} | |
| echo ${{ env.BRANCH }} | |
| - name: Set up SSH key with passphrase | |
| uses: webfactory/ssh-agent@v0.5.3 | |
| with: | |
| ssh-private-key: ${{ env.SERVER_SSH_KEY }} | |
| ssh-passphrase: ${{ env.SERVER_SSH_PASSPHRASE }} | |
| - name: 원격 서버에 배포 | |
| run: | | |
| ssh -o StrictHostKeyChecking=no ${{ env.SERVER_USER }}@${{ env.SERVER_HOST }} << 'EOF' | |
| curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # nvm을 현재 세션에서 사용하기 위해 로드 | |
| nvm install 18 | |
| nvm use 18 | |
| cd ${{ env.DEPLOY_PATH }} | |
| git fetch --all | |
| git pull origin ${{ env.BRANCH }} | |
| yarn install --frozen-lockfile | |
| if [ "${{ inputs.dev_command }}" = "yarn dev:test" ]; then | |
| lsof -ti:6001 | xargs kill -9 || true | |
| elif [ "${{ inputs.dev_command }}" = "yarn dev" ]; then | |
| lsof -ti:5001 | xargs kill -9 || true | |
| fi | |
| nohup ${{ inputs.dev_command }} > output.log 2>&1 & | |
| sleep 5 | |
| EOF | |
| - name: 슬랙 메시지 전송 | |
| env: | |
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_CI_CHANNEL_WEBHOOK }} | |
| run: | | |
| if [ "${{ inputs.dev_command }}" = "yarn dev:test" ]; then | |
| PORT=6001 | |
| elif [ "${{ inputs.dev_command }}" = "yarn dev" ]; then | |
| PORT=5001 | |
| else | |
| PORT="알 수 없음" | |
| fi | |
| curl -X POST -H 'Content-type: application/json' --data '{"text":"배포가 완료되었습니다. port: ${{ env.PORT }} , branch: ${{ env.BRANCH }}"}' $SLACK_WEBHOOK_URL | |
| - name: SSH 키 정리 | |
| run: rm -rf ~/.ssh |