-
Notifications
You must be signed in to change notification settings - Fork 33
208 lines (184 loc) · 8.52 KB
/
Copy pathci.yml
File metadata and controls
208 lines (184 loc) · 8.52 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
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
199
200
201
202
203
204
205
206
207
208
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
name: CI
on:
pull_request:
push:
branches:
- master
jobs:
build:
name: Auto Build CI
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macOS-latest ]
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Install Rust toolchain
run: |
rustup update stable
rustup default stable
rustup component add rustfmt clippy
- name: Cargo Clippy
run: cargo clippy -- -D warnings
- name: Cargo Fmt Check
run: cargo fmt --all -- --check
# Runs before any database is set up and with no DATABASE_URL, so it
# proves downstream crates can build the adapter offline for every driver.
- name: Cargo Build (offline, no database)
run: |
cargo build
cargo build --no-default-features --features postgres,runtime-tokio-native-tls
cargo build --no-default-features --features mysql,runtime-tokio-native-tls
cargo build --no-default-features --features sqlite,runtime-tokio-native-tls
- name: Setup PostgreSQL & MySQL & SQLite (for ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y libpq-dev postgresql libmysqlclient-dev mysql-client libsqlite3-dev sqlite3
# The runner's stock pg_hba.conf already allows password logins from
# 127.0.0.1, which is all the tests need.
sudo service postgresql restart && sleep 3
sudo -u postgres createuser casbin_rs
sudo -u postgres createdb casbin
sudo -u postgres psql -c "alter user casbin_rs with encrypted password 'casbin_rs'; grant all privileges on database casbin to casbin_rs;"
sudo -u postgres psql -c "GRANT USAGE, CREATE ON SCHEMA public TO casbin_rs;"
sudo -u postgres psql -c "GRANT ALL ON DATABASE casbin TO casbin_rs;"
sudo -u postgres psql -c "ALTER DATABASE casbin OWNER TO casbin_rs;"
sudo service postgresql restart && sleep 3
sudo systemctl start mysql.service
mysql -e "create user 'casbin_rs'@'localhost' identified by 'casbin_rs'; create database casbin; grant all on \`casbin\`.* to 'casbin_rs'@'localhost';" -uroot -proot
- name: Setup PostgreSQL & MySQL & SQLite (for macOS)
if: matrix.os == 'macOS-latest'
run: |
brew update
brew install postgresql mariadb
brew services start postgresql
# pg_ctl -D /usr/local/var/postgres start
sleep 3
createuser casbin_rs
createdb casbin
psql postgres -c "alter user casbin_rs with encrypted password 'casbin_rs'; grant all privileges on database casbin to casbin_rs;"
psql postgres -c "GRANT USAGE, CREATE ON SCHEMA public TO casbin_rs;"
psql postgres -c "GRANT ALL ON DATABASE casbin TO casbin_rs;"
psql postgres -c "ALTER DATABASE casbin OWNER TO casbin_rs;"
#echo "/usr/local/opt/mariadb@10.5/bin" >> $GITHUB_PATH
#/usr/local/opt/mariadb@10.5/bin/mysql_install_db
#/usr/local/opt/mariadb@10.5/bin/mysql.server start
brew services start mariadb
sleep 3
mysql -e "create user 'casbin_rs'@'localhost' identified by 'casbin_rs'; create database casbin; grant all on \`casbin\`.* to 'casbin_rs'@'localhost';" -urunner
#echo "MYSQLCLIENT_LIB_DIR=/usr/local/opt/mariadb@10.5/lib" >> $GITHUB_ENV
- name: Create SQLite DB
run: |
touch casbin.db
- name: Create PostgresSQL Table
run: psql -c "CREATE TABLE IF NOT EXISTS casbin_rule (
id SERIAL PRIMARY KEY,
ptype VARCHAR NOT NULL,
v0 VARCHAR NOT NULL,
v1 VARCHAR NOT NULL,
v2 VARCHAR NOT NULL,
v3 VARCHAR NOT NULL,
v4 VARCHAR NOT NULL,
v5 VARCHAR NOT NULL,
CONSTRAINT unique_key_sqlx_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
);" postgres://casbin_rs:casbin_rs@127.0.0.1:5432/casbin
- name: Create MySQL Table
run: |
mysql -ucasbin_rs -pcasbin_rs -e "USE casbin; CREATE TABLE IF NOT EXISTS casbin_rule (
id INT NOT NULL AUTO_INCREMENT,
ptype VARCHAR(12) NOT NULL,
v0 VARCHAR(128) NOT NULL,
v1 VARCHAR(128) NOT NULL,
v2 VARCHAR(128) NOT NULL,
v3 VARCHAR(128) NOT NULL,
v4 VARCHAR(128) NOT NULL,
v5 VARCHAR(128) NOT NULL,
PRIMARY KEY(id),
CONSTRAINT unique_key_sqlx_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"
- name: Create SQLite Table
run: |
sqlite3 casbin.db -cmd "CREATE TABLE IF NOT EXISTS casbin_rule (
id INTEGER PRIMARY KEY,
ptype VARCHAR(12) NOT NULL,
v0 VARCHAR(128) NOT NULL,
v1 VARCHAR(128) NOT NULL,
v2 VARCHAR(128) NOT NULL,
v3 VARCHAR(128) NOT NULL,
v4 VARCHAR(128) NOT NULL,
v5 VARCHAR(128) NOT NULL,
CONSTRAINT unique_key_sqlx_adapter UNIQUE(ptype, v0, v1, v2, v3, v4, v5)
);"
- name: Cargo Test For PostgreSQL
env:
DATABASE_URL: postgres://casbin_rs:casbin_rs@localhost:5432/casbin
run: |
cargo test --no-default-features --features postgres,runtime-async-std-native-tls
cargo test --no-default-features --features postgres,runtime-async-std-rustls
cargo test --no-default-features --features postgres,runtime-tokio-native-tls
cargo test --no-default-features --features postgres,runtime-tokio-rustls
- name: Cargo Test For MySQL
env:
DATABASE_URL: mysql://casbin_rs:casbin_rs@localhost:3306/casbin
run: |
cargo test --no-default-features --features mysql,runtime-async-std-native-tls
cargo test --no-default-features --features mysql,runtime-async-std-rustls
cargo test --no-default-features --features mysql,runtime-tokio-native-tls
cargo test --no-default-features --features mysql,runtime-tokio-rustls
- name: Cargo Test For SQLite
env:
DATABASE_URL: sqlite:casbin.db
run: |
cargo test --no-default-features --features sqlite,runtime-async-std-native-tls
cargo test --no-default-features --features sqlite,runtime-async-std-rustls
cargo test --no-default-features --features sqlite,runtime-tokio-native-tls
cargo test --no-default-features --features sqlite,runtime-tokio-rustls
release-scripts:
name: Release Scripts
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Test release.sh against a throwaway repo and a fake ASF dist area
run: .github/scripts/test-release.sh
license-headers:
name: License Headers (Apache RAT)
runs-on: ubuntu-latest
env:
RAT_VERSION: 0.16.1
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
- name: Download Apache RAT
run: curl -fsSL --retry 3 -o "$RUNNER_TEMP/rat.jar" "https://repo1.maven.org/maven2/org/apache/rat/apache-rat/$RAT_VERSION/apache-rat-$RAT_VERSION.jar"
# Audit exactly what a source release would contain: the tracked files.
- name: Check license headers
run: |
set -euo pipefail
mkdir "$RUNNER_TEMP/src"
git archive HEAD | tar -x -C "$RUNNER_TEMP/src"
java -jar "$RUNNER_TEMP/rat.jar" --scan-hidden-directories -d "$RUNNER_TEMP/src" -E .rat-excludes | tee "$RUNNER_TEMP/rat.txt"
grep -q '^0 Unknown Licenses' "$RUNNER_TEMP/rat.txt"