-
Notifications
You must be signed in to change notification settings - Fork 0
107 lines (95 loc) · 2.98 KB
/
main.yml
File metadata and controls
107 lines (95 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Auto test Online Voting Application
on:
push:
branches:
- develop
- main
pull_request: # Trigger the workflow on pull requests targeting the specified branches
branches:
- develop
- main
env:
PG_DATABASE: wd-voting-test
PG_USER: postgres
PG_PASSWORD: Drvl@123
jobs:
# Label of the container job
run-tests:
# Containers must run in Linux based operating systems
runs-on: ubuntu-latest
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:11.7
# Provide the password for postgres
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: Drvl@123
POSTGRES_DB: wd-voting-test
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
# Downloads a copy of the code in your repository before running CI tests
- name: Check out repository code
uses: actions/checkout@v3
# Performs a clean installation of all dependencies in the `package.json` file
# For more information, see https://docs.npmjs.com/cli/ci.html
- name: Install dependencies
run: npm install
- name: Run unit tests
run: npm test
- name: Run the app
id: run-app
run: |
npm install
npx sequelize-cli db:drop
npx sequelize-cli db:create
npx sequelize-cli db:migrate
PORT=3000 npm start &
sleep 5
push-to-docker-hub:
runs-on: ubuntu-latest
needs: run-tests
if: ${{ needs.run-tests.result == 'success' }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_HUB_LOGIN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/voting:latest
deploy-to-render:
runs-on: ubuntu-latest # Define the operating system for the job
needs: [run-tests, push-to-docker-hub]
if: ${{ needs.run-tests.result == 'success' }}
steps:
- name: Trigger Render deployment webhook #trigger deployment webhook
run: curl -X GET -d '{}' ${{ secrets.RENDER_DEPLOY_HOOK }}
send-slack-notification:
runs-on: ubuntu-latest
needs: [run-tests, deploy-to-render]
if: ${{ always() }}
steps:
- name: Send Slack notification
uses: rtCamp/action-slack-notify@v2
with:
status: ${{ job.status }}
mention: "here"
author_name: "GitHub Actions"
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_HOOK }}