-
Notifications
You must be signed in to change notification settings - Fork 4
198 lines (174 loc) · 5.91 KB
/
feature-ci.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Feature CI
on:
pull_request:
branches:
- feature/*
jobs:
test:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379:6379
postgres:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: rustify_auth
POSTGRES_PASSWORD: password
POSTGRES_DB: rustify_auth_db
options: >-
--health-cmd "pg_isready -U rustify_auth"
--health-interval 10s
--health-timeout 5s
--health-retries 10 # Increased retries
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Wait for PostgreSQL to be ready
run: |
until pg_isready -h localhost -p 5432 -U rustify_auth; do
echo "Waiting for PostgreSQL to be ready..."
sleep 2
done
echo "PostgreSQL is ready!"
sleep 15 # Additional sleep to ensure PostgreSQL readiness
- name: Verify PostgreSQL Connection
run: |
echo "PostgreSQL Connection Info:"
psql -h localhost -p 5432 -U rustify_auth -c '\conninfo'
- name: Run migrations with schema setup
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
run: |
echo "Running migrations with schema setup..."
psql $DATABASE_URL <<-EOF
DROP TABLE IF EXISTS tokens CASCADE;
DROP TABLE IF EXISTS clients CASCADE;
CREATE TABLE IF NOT EXISTS clients (
client_id VARCHAR PRIMARY KEY,
secret VARCHAR NOT NULL,
redirect_uris JSONB NOT NULL,
grant_types JSONB,
response_types JSONB,
software_statement TEXT
);
CREATE TABLE IF NOT EXISTS tokens (
access_token VARCHAR PRIMARY KEY,
refresh_token VARCHAR,
expires_at TIMESTAMP,
scope VARCHAR,
client_id VARCHAR REFERENCES clients(client_id) ON DELETE CASCADE,
token_type VARCHAR DEFAULT 'Bearer'
);
EOF
- name: Verify Database Schema
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
run: |
echo "Listing tables and columns:"
psql $DATABASE_URL -c "\dt"
psql $DATABASE_URL -c "\d tokens"
psql $DATABASE_URL -c "\d clients"
- name: Verify tables and sample data
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
run: |
echo "Verifying tables and displaying sample data..."
psql $DATABASE_URL -c "\dt"
psql $DATABASE_URL -c "SELECT * FROM clients LIMIT 1;" || echo "No data in clients table"
psql $DATABASE_URL -c "SELECT * FROM tokens LIMIT 1;" || echo "No data in tokens table"
- name: Grant all privileges to ensure permissions
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
run: |
echo "Granting all privileges to ensure permissions..."
psql $DATABASE_URL -c "GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO rustify_auth;"
- name: Verify Permissions
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
run: |
echo "Verifying database permissions..."
psql $DATABASE_URL -c "SELECT table_catalog, table_schema, table_name, privilege_type FROM information_schema.role_table_grants WHERE grantee = 'rustify_auth';"
- name: Run cargo test with backtrace enabled
env:
DATABASE_URL: postgres://rustify_auth:password@localhost:5432/rustify_auth_db
REDIS_URL: redis://localhost:6379
JWT_SECRET: test_secret
RUST_BACKTRACE: full
RUST_LOG: debug
run: cargo test -- --test-threads=1
format:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Check code formatting
run: cargo fmt --check
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Cache cargo registry
uses: actions/cache@v3
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Run linter
run: cargo clippy -- -D warnings