43 lines
1.4 KiB
YAML
43 lines
1.4 KiB
YAML
on:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
types:
|
|
- closed
|
|
push:
|
|
branches:
|
|
- dev
|
|
jobs:
|
|
deploy:
|
|
# Trigger deploy workflow if
|
|
# ...I clicked on "Run workflow" in Github actions, thus deploy main to production env (main)
|
|
# or
|
|
# ...I merged a PR or pushed on the dev branch, thus deploy to the test env (dev)
|
|
if: |
|
|
(github.event_name == 'workflow_dispatch' && github.ref_name == 'main') ||
|
|
((github.event.pull_request.merged == true || github.event.push == true) && github.ref_name == 'dev')
|
|
runs-on: ubuntu-latest
|
|
environment: ${{ github.ref_name }}
|
|
steps:
|
|
- name: Checkout repositorypu
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up SSH key
|
|
run: |
|
|
env
|
|
mkdir -p ~/.ssh
|
|
echo "${{ secrets.ARTIFACT_SSH_KEY }}" > /home/runner/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
ssh-keyscan -p ${{ secrets.ARTIFACT_PORT }} ${{ secrets.ARTIFACT_HOST }} >> ~/.ssh/known_hosts
|
|
sudo apt-get install sshpass python3 python3-pip
|
|
|
|
- name: Deploy to server
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: ${{ secrets.ARTIFACT_HOST }}
|
|
username: ${{ secrets.USER }}
|
|
port: ${{ secrets.ARTIFACT_PORT }}
|
|
key: ${{ secrets.ARTIFACT_SSH_KEY }}
|
|
passphrase: ${{ secrets.SSH_PSWD }}
|
|
command_timeout: 5m
|
|
script: ${{ secrets.APP_PATH }}/deploy.sh
|