feat: implement fetch customers list #40
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 Production | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Set Golang | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.22.1" | |
- name: Build the application | |
run: go build -o production_app | |
test: | |
runs-on: ubuntu-latest | |
needs: build | |
env: | |
TEST_USERNAME: postgres | |
TEST_PASSWORD: password | |
TEST_DB_NAME: db_name | |
TEST_DB_HOST: localhost | |
TEST_DB_PORT: 5432 | |
TEST_DB_CONNECTION: pgsql | |
TEST_TIMEZONE: Africa/Lagos | |
TEST_SSLMODE: disable | |
TEST_MIGRATE: true | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_USER: ${{ env.TEST_USERNAME }} | |
POSTGRES_PASSWORD: ${{ env.TEST_PASSWORD }} | |
POSTGRES_DB: ${{ env.TEST_DB_NAME }} | |
ports: | |
- 5432:5432 | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Create app config file | |
run: cp app-sample.env app.env | |
- name: Run All Tests | |
run: go test ./... -timeout 99999s | |
deploy: | |
runs-on: ubuntu-latest | |
needs: test | |
env: | |
SSH_USERNAME: ${{ secrets.SSH_USERNAME }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
SSH_PORT: ${{ secrets.SSH_PORT }} | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
SERVER_PORT: 9000 | |
DB_NAME: "production_db" | |
USERNAME: "production_user" | |
APP_NAME: "production" | |
APP_URL: "http://localhost:9000" | |
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: | | |
export APPROOT=~/deployments/production | |
mkdir -p $APPROOT | |
cd $APPROOT | |
if [ -d "$APPROOT/.git" ]; then | |
# Navigate to the repository directory and pull changes | |
cd $APPROOT || { echo "Failed to navigate to web root directory"; exit 1; } | |
git reset --hard HEAD || { echo "Failed to reset local changes"; exit 1; } | |
git pull origin main || { echo "Failed to pull latest changes"; exit 1; } | |
else | |
git clone -b main https://github.com/${{ github.repository}} . || { echo "Failed to clone repository"; exit 1; } | |
fi | |
bash ./scripts/deploy_app.sh production https://github.com/${{ github.repository}} SERVER_PORT=${{ env.SERVER_PORT }} DB_NAME=${{ env.DB_NAME }} USERNAME=${{ env.USERNAME }} APP_NAME=${{ env.APP_NAME }} APP_URL=${{ env.APP_URL }} |