-
Notifications
You must be signed in to change notification settings - Fork 3
96 lines (81 loc) · 2.64 KB
/
migrations.yml
File metadata and controls
96 lines (81 loc) · 2.64 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
name: "Database migrations"
on:
workflow_dispatch:
push:
paths:
- "src/database/migrations/*"
branches:
- develop
- main
defaults:
run:
shell: bash
jobs:
staging-migrations:
name: "Staging DB migrations"
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'develop' }}
environment:
name: staging
url: https://studio-api-staging.cheqd.net/swagger/
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20
cache: "npm"
- name: Install dependencies and build
run: |
npm ci --force
npm run build
- name: "Execute migrations"
run: |
npm run migrate
env:
EXTERNAL_DB_CONNECTION_URL: ${{ secrets.EXTERNAL_DB_CONNECTION_URL }}
EXTERNAL_DB_CERT: ${{ secrets.EXTERNAL_DB_CERT }}
EXTERNAL_DB_ENCRYPTION_KEY: ${{ secrets.EXTERNAL_DB_ENCRYPTION_KEY }}
ENABLE_EXTERNAL_DB: true
production-migrations:
name: "Production DB migrations"
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' }}
environment:
name: production
url: https://studio-api.cheqd.net/swagger/
env:
EXTERNAL_DB_CONNECTION_URL: ${{ secrets.EXTERNAL_DB_CONNECTION_URL }}
EXTERNAL_DB_CERT: ${{ secrets.EXTERNAL_DB_CERT }}
EXTERNAL_DB_ENCRYPTION_KEY: ${{ secrets.EXTERNAL_DB_ENCRYPTION_KEY }}
ENABLE_EXTERNAL_DB: true
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20
cache: "npm"
- name: "Install DigitalOcean CLI"
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: Install dependencies and build
run: |
npm ci --force
npm run build
- name: Get runner public IP
id: ip
run: echo "ip=$(curl -s https://ifconfig.me)" >> "$GITHUB_OUTPUT"
- name: Temporarily allow runner IP address
run: |
doctl databases firewalls append ${{ secrets.DATABASE_ID }} --rule "ip_addr:${{ steps.ip.outputs.ip }}/32"
- name: "Execute migrations"
id: migrations
run: |
npm run migrate
- name: Remove runner IP from DO DB firewall
if: always()
run: |
UUID=$(doctl databases firewalls list --output json ${{ secrets.DATABASE_ID }} | jq -r '.[] | select(.type == "ip_addr" and .value == "${{ steps.ip.outputs.ip }}") | .uuid')
if [ -n "$UUID" ]; then
doctl databases firewalls remove ${{ secrets.DATABASE_ID }} "$UUID"
fi