Deploy to dev server #4080
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 to dev server | |
on: | |
workflow_dispatch: | |
inputs: | |
env_id: | |
description: 'Environment' | |
required: true | |
default: 'dev' | |
type: choice | |
options: | |
- dev | |
- dev2 | |
- dev3 | |
- stage | |
jobs: | |
deploy: | |
name: Deploy on ${{ inputs.env_id }} server | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set SSH credentials | |
run: | | |
echo "HOST=${{ secrets.DEV_HOST }}" >> $GITHUB_ENV | |
echo "USER=${{ secrets.DEV_USER }}" >> $GITHUB_ENV | |
echo "PASS=${{ secrets.DEV_PASS }}" >> $GITHUB_ENV | |
- name: Set dev target path | |
if: ${{ inputs.env_id == 'dev' }} | |
run: | | |
echo "TARGET_PATH=${{ secrets.DEV_TARGET_PATH }}" >> $GITHUB_ENV | |
- name: Set dev2 target path | |
if: ${{ inputs.env_id == 'dev2' }} | |
run: | | |
echo "TARGET_PATH=${{ secrets.DEV2_TARGET_PATH }}" >> $GITHUB_ENV | |
- name: Set dev3 target path | |
if: ${{ inputs.env_id == 'dev3' }} | |
run: | | |
echo "TARGET_PATH=${{ secrets.DEV3_TARGET_PATH }}" >> $GITHUB_ENV | |
- name: Set stage target path | |
if: ${{ inputs.env_id == 'stage' }} | |
run: | | |
echo "TARGET_PATH=${{ secrets.STAGE_TARGET_PATH }}" >> $GITHUB_ENV | |
- name: Install sshpass | |
run: | | |
sudo apt-get install sshpass | |
- name: Read .nvmrc | |
run: echo ::set-output name=NVMRC::$(cat .nvmrc) | |
id: nvm | |
- name: Set Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '${{ steps.nvm.outputs.NVMRC }}' | |
- name: Cache dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.npm | |
key: npm-${{ hashFiles('package-lock.json') }} | |
restore-keys: npm- | |
- name: Install dependencies | |
run: yarn --frozen-lockfile | |
- name: Run build | |
run: yarn run build:${{ inputs.env_id }} | |
- name: Deploy | |
run: | | |
sshpass -p "${{ env.PASS }}" ssh -o StrictHostKeyChecking=no -tt "${{ env.USER }}@${{ env.HOST }}" "sudo chmod 777 -R ${{ env.TARGET_PATH }}" | |
sshpass -p ${{ env.PASS }} rsync -e "ssh -o StrictHostKeyChecking=no" -rltzh -O --delete dist/rubic/ ${{ env.USER }}@${{ env.HOST }}:${{ env.TARGET_PATH }} | |
sshpass -p "${{ env.PASS }}" ssh -o StrictHostKeyChecking=no -tt "${{ env.USER }}@${{ env.HOST }}" "sudo chmod 777 -R ${{ env.TARGET_PATH }}" | |
- name: Get branch names | |
id: branch-names | |
uses: tj-actions/branch-names@v6 | |
- name: Notify bot | |
uses: fjogeleit/http-request-action@v1 | |
with: | |
url: '${{ secrets.deploy_url}}' | |
method: 'POST' | |
customHeaders: '{"Content-Type": "application/json"}' | |
data: | |
'{"targetServer": "${{ inputs.env_id }}", "initiator": "${{ github.actor }}", "feature": | |
"${{ steps.branch-names.outputs.current_branch }}"}' |