Merge pull request #116 from wesionaryTEAM/fix/sentry-env-missing #92
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 API. | |
on: | |
push: | |
branches: | |
- develop | |
- main | |
tags: | |
- v* | |
pull_request: | |
types: [review_requested, edited, synchronize] | |
#For manual trigger of workflow. | |
workflow_dispatch: | |
jobs: | |
setup_environment: | |
runs-on: ubuntu-latest | |
outputs: | |
env_name: ${{ steps.get_env.outputs.env }} | |
env: | |
GITHUB_REF: ${{ github.ref }} | |
steps: | |
- id: get_env | |
run: | | |
if grep -q "refs/tags/v" <<< ${{github.ref}} || grep -q "refs/heads/main" <<< ${{github.ref}}; then | |
echo "env=PROD" >> $GITHUB_OUTPUT | |
else | |
echo "env=DEV" >> $GITHUB_OUTPUT | |
fi | |
- id: print_env | |
name: Print environment | |
run: echo "Environment :- ${{ steps.get_env.outputs.env }}" | |
deploy: | |
name: Build and Deploy Go | |
runs-on: ubuntu-latest | |
needs: setup_environment | |
environment: ${{needs.setup_environment.outputs.env_name}} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
- name: Use golang ${{matrix.go-version}} | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "^1.22" | |
- run: go version | |
- name: Set up MySQL | |
run: | | |
sudo /etc/init.d/mysql start | |
mysql -e 'CREATE DATABASE root;' -uroot -proot | |
mysql -e "show databases;" -uroot -proot | |
- name: Initialize the environment variables | |
run: | | |
echo 'ENVIRONMENT=workflow | |
SERVER_PORT=8080 | |
DB_HOST=localhost | |
DB_NAME=root | |
DB_PASS=root | |
DB_PORT=3306 | |
DB_TYPE=local | |
DB_USER=root | |
DB_FORWARD_PORT=3306 | |
LOG_LEVEL=info' > .env | |
- name: Build the repository | |
run: | | |
go build main.go | |
curl -sSf https://atlasgo.sh | sh | |
- name: Run migration | |
run: | | |
make migrate-apply | |
- name: Start the service | |
run: | |
./main app:serve & | |
- name: Validate if the service is working or not via health check api | |
run: | | |
sleep 5 | |
curl http://localhost:8080/health-check | |
- name: Slack Notification on SUCCESS | |
if: success() | |
uses: tokorom/action-slack-incoming-webhook@main | |
env: | |
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
with: | |
text: A development deployment job for api has succeeded :tada:. | |
attachments: | | |
[ | |
{ | |
"color": "good", | |
"author_name": "${{ github.actor }}", | |
"author_icon": "${{ github.event.sender.avatar_url }}", | |
"fields": [ | |
{ | |
"title": "Commit Message", | |
"value": "${{ github.event.head_commit.message }}" | |
}, | |
{ | |
"title": "GitHub Actions URL", | |
"value": "${{ github.event.repository.url }}/actions/runs/${{ github.run_id }}" | |
}, | |
{ | |
"title": "Compare URL", | |
"value": "${{ github.event.compare }}" | |
}, | |
{ | |
"title": "ENV", | |
"value": "${{needs.setup_environment.outputs.env_name}}" | |
} | |
] | |
} | |
] | |
- name: Slack Notification on FAILURE | |
if: failure() | |
uses: tokorom/action-slack-incoming-webhook@main | |
env: | |
INCOMING_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | |
with: | |
text: A development deployment job for api has failed :crying_cat_face:. | |
attachments: | | |
[ | |
{ | |
"color": "danger", | |
"author_name": "${{ github.actor }}", | |
"author_icon": "${{ github.event.sender.avatar_url }}", | |
"fields": [ | |
{ | |
"title": "Commit Message", | |
"value": "${{ github.event.head_commit.message }}" | |
}, | |
{ | |
"title": "GitHub Actions URL", | |
"value": "${{ github.event.repository.url }}/actions/runs/${{ github.run_id }}" | |
}, | |
{ | |
"title": "Compare URL", | |
"value": "${{ github.event.compare }}" | |
}, | |
{ | |
"title": "ENV", | |
"value": "${{needs.setup_environment.outputs.env_name}}" | |
} | |
] | |
} | |
] |