-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (116 loc) · 4.34 KB
/
elixir.yml
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Elixir CI
on:
push:
tags:
- "*"
branches:
- "main"
pull_request:
branches: ["main"]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
services:
db:
image: postgres:17
ports: ["5432:5432"]
env:
POSTGRES_USER: ${{ secrets.POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.POSTGRES_PASSWORD }}
POSTGRES_DB: ${{ secrets.POSTGRES_DB }}
name: Build and test
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v4
- name: Set up Elixir
uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0
with:
elixir-version: "1.15.2" # [Required] Define the Elixir version
otp-version: "26.0" # [Required] Define the Erlang/OTP version
- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Compile the project
run: mix compile
- name: Run tests
run: mix test
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Start EC2 instance
run: curl -X GET ${{ secrets.API_POINT }}
- name: Install Python
if: startsWith(github.ref, 'refs/tags/')
uses: actions/setup-python@v4
with:
python-version: "3.11"
architecture: "x64"
- name: Cache pip
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-ansible
- name: Install Ansible
run: |
python -m pip install --user ansible
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Create SSH key file
run: echo "${{ secrets.KEY }}" | tr -d '\r' > key.pem
- name: Set permissions for SSH key
run: chmod 600 key.pem
- name: Create Ansible inventory file
run: echo -e "[EC2]\n${{ secrets.HOSTS }}" > inventory.ini
- name: Display Ansible inventory file
run: cat inventory.ini
- name: Wait for SSH to be available
run: |
for i in {1..30}; do
ssh -o StrictHostKeyChecking=no -i key.pem ec2-user@${{ secrets.HOSTS }} 'echo SSH is available' && break
echo "Waiting for SSH to be available..."
sleep 10
done
- name: Run Ansible Playbook
run: |
ansible-playbook Playbook.yml -i inventory.ini --private-key key.pem --ssh-extra-args "-o StrictHostKeyChecking=no" --extra-vars "POSTGRES_USER=${{ secrets.POSTGRES_USER }} POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} POSTGRES_DB=${{ secrets.POSTGRES_DB }} DATABASE_HOSTNAME=${{ secrets.DATABASE_HOSTNAME }} PGADMIN_DEFAULT_EMAIL=${{ secrets.PGADMIN_DEFAULT_EMAIL }} PGADMIN_DEFAULT_PASSWORD=${{ secrets.PGADMIN_DEFAULT_PASSWORD }} FRONTEND_DNS=${{ secrets.FRONTEND_DNS }} BACKEND_DNS=${{ secrets.BACKEND_DNS }} PGADMIN_DNS=${{ secrets.PGADMIN_DNS }} kuramacert=${{ secrets.kuramacert }} kuramakey=${{ secrets.kuramakey }} CLIENT_ID_GOOGLE=${{ secrets.CLIENT_ID_GOOGLE }} CLIENT_SECRET_GOOGLE=${{ secrets.CLIENT_SECRET_GOOGLE }}"
mail:
name: Send mail
needs: deploy
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v4
- name: Read and filter email content
id: read_email_content
run: |
content=$(sed '/^---$/d;/^title:/d;/^description:/d' frontend/src/content/release-${{ github.ref_name }}.md)
echo "content<<EOF" >> $GITHUB_ENV
echo "$content" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Send mail
uses: dawidd6/action-send-mail@v2
with:
server_address: smtp.gmail.com
server_port: 465
username: ${{ secrets.SMTP_USER }}
password: ${{ secrets.SMTP_PASSWORD }}
subject: Time manager release ${{ github.ref_name }}
convert_markdown: true
body: ${{ env.content }}
from: Batman
content_type: text/html