Merge pull request #363 from hngprojects/test/add_golang_be_postman_c… #3
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: Build, Test, and Deploy for Development | |
on: | |
push: | |
branches: | |
- dev | |
jobs: | |
build_and_upload_artifact: | |
runs-on: ubuntu-latest | |
if: github.event.repository.fork == false | |
environment: development | |
env: | |
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_PORT: ${{ secrets.SSH_PORT }} | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set Golang | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22.1" | |
- name: Create app config file | |
run: cp app-sample.env app.env | |
- name: Build the application | |
run: go build -o development_app | |
- name: Create app.env file | |
uses: vicradon/[email protected] | |
with: | |
action_input_file: "app-sample.env" | |
action_output_file: "app.env" | |
action_true_string_variables: | | |
MAIL_PASSWORD | |
SERVER_PORT: ${{ secrets.SERVER_PORT }} | |
DB_NAME: ${{ secrets.DB_NAME }} | |
USERNAME: ${{ secrets.USERNAME }} | |
APP_NAME: "development" | |
APP_URL: ${{ vars.URL}} | |
REDIS_PORT: ${{ secrets.REDIS_PORT }} | |
MAIL_SERVER: ${{ secrets.MAIL_SERVER }} | |
MAIL_USERNAME: ${{ secrets.MAIL_USERNAME }} | |
MAIL_PASSWORD: ${{ secrets.MAIL_PASSWORD }} | |
MAIL_PORT: ${{ secrets.MAIL_PORT }} | |
MIGRATE: "true" | |
- name: Copy artifacts to server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ env.SSH_HOST }} | |
username: ${{ env.SSH_USERNAME }} | |
password: ${{ env.SSH_PASSWORD }} | |
port: ${{ env.SSH_PORT }} | |
source: "app.env,development_app" | |
target: ~/deployments/development | |
restart_app: | |
runs-on: ubuntu-latest | |
needs: build_and_upload_artifact | |
environment: development | |
env: | |
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_PORT: ${{ secrets.SSH_PORT }} | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
steps: | |
- name: SSH into server and deploy | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ env.SSH_HOST }} | |
username: ${{ env.SSH_USERNAME }} | |
password: ${{ env.SSH_PASSWORD }} | |
port: ${{ env.SSH_PORT }} | |
script: | | |
mkdir -p ~/deployments/development | |
cd ~/deployments/development | |
git reset --hard | |
git pull origin dev | |
pm2 restart development_app |