trigger-deploy #15
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 Web Project | |
on: | |
repository_dispatch: | |
types: [trigger-deploy] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code Repository | |
uses: actions/checkout@v2 | |
with: | |
repository: ${{ github.event.client_payload.repo_name }} | |
ref: ${{ github.event.client_payload.branch }} | |
- name: Install Dependencies | |
working-directory: . | |
run: npm install | |
- name: Ensure Config Directory Exists | |
run: mkdir -p ./src/config | |
- name: Decode Config Secret | |
id: decode-config | |
run: | | |
echo "${{ github.event.client_payload.config_secret }}" | base64 --decode > ./src/config/temp_config.json | |
cat ./src/config/temp_config.json | |
- name: Validate Config JSON | |
run: | | |
if ! jq empty ./src/config/temp_config.json; then | |
echo "Invalid JSON format in temp_config.json" | |
exit 1 | |
fi | |
- name: Set Config Json File | |
id: create-json | |
uses: jsdaniell/create-json@v1.2.2 | |
with: | |
name: "config.json" # 생성할 파일 이름 | |
json: ${{ steps.decode-config.outputs.result }} | |
dir: './src/config' # 파일이 생성될 디렉토리 | |
- name: Build Project | |
working-directory: . | |
run: npm run build | |
- name: Create Destination Directory If Not Exists | |
run: | | |
ssh -i ${{ secrets.SERVER_SSH_KEY }} ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} \ | |
"mkdir -p ${{ github.event.client_payload.destination_directory }}" | |
- name: Deploy Files to Server | |
run: | | |
rsync -avz -e "ssh -i ${{ secrets.SERVER_SSH_KEY }}" \ | |
./${{ github.event.client_payload.source_directory }}/ \ | |
${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }}:${{ github.event.client_payload.destination_directory }} |