Skip to content

Commit b187cae

Browse files
committed
Add a ci workflow
1 parent 10d8a75 commit b187cae

File tree

1 file changed

+172
-0
lines changed

1 file changed

+172
-0
lines changed

.github/workflows/ci.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
on:
2+
pull_request:
3+
types: [opened, synchronize, reopened]
4+
push:
5+
branches:
6+
- master
7+
- "0.[0-9]+.x"
8+
- "1.[0-9]+.x"
9+
10+
name: CI Tests
11+
12+
# See: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency.
13+
# This will ensure that only one commit will be running tests at a time on each PR.
14+
concurrency:
15+
group: ${{ github.ref }}-${{ github.workflow }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
check_and_test:
20+
name: Check
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
rust: ["stable", "beta", "nightly"]
25+
backend: ["postgres", "mysql"]
26+
os: [ubuntu-latest, macos-latest, windows-latest]
27+
runs-on: ${{ matrix.os }}
28+
steps:
29+
- name: Checkout sources
30+
uses: actions/checkout@v2
31+
32+
- name: Cache cargo registry
33+
uses: actions/cache@v2
34+
with:
35+
path: |
36+
~/.cargo/registry
37+
~/.cargo/git
38+
key: ${{ runner.os }}-${{ matrix.backend }}-cargo-${{ hashFiles('**/Cargo.toml') }}
39+
40+
- name: Set environment variables
41+
shell: bash
42+
if: matrix.backend == 'mysql'
43+
run: |
44+
echo "RUST_TEST_THREADS=1" >> $GITHUB_ENV
45+
46+
- name: Set environment variables
47+
shell: bash
48+
if: matrix.rust == 'nightly'
49+
run: |
50+
echo "RUSTFLAGS=--cap-lints=warn" >> $GITHUB_ENV
51+
52+
- name: Install postgres (Linux)
53+
if: runner.os == 'Linux' && matrix.backend == 'postgres'
54+
run: |
55+
sudo apt-get update
56+
sudo apt-get install -y postgresql
57+
echo "host all all 127.0.0.1/32 md5" > sudo tee -a /etc/postgresql/10/main/pg_hba.conf
58+
sudo service postgresql restart && sleep 3
59+
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
60+
sudo service postgresql restart && sleep 3
61+
echo "PG_DATABASE_URL=postgres://postgres:postgres@localhost/" >> $GITHUB_ENV
62+
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres:postgres@localhost/diesel_example" >> $GITHUB_ENV
63+
64+
- name: Install mysql (Linux)
65+
if: runner.os == 'Linux' && matrix.backend == 'mysql'
66+
run: |
67+
sudo systemctl start mysql.service
68+
mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'root'@'localhost';" -uroot -proot
69+
echo "MYSQL_DATABASE_URL=mysql://root:root@localhost/diesel_test" >> $GITHUB_ENV
70+
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root:root@localhost/diesel_example" >> $GITHUB_ENV
71+
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root:root@localhost/diesel_unit_test" >> $GITHUB_ENV
72+
73+
- name: Install postgres (MacOS)
74+
if: runner.os == 'macOS' && matrix.backend == 'postgres'
75+
run: |
76+
/usr/local/opt/postgres/bin/pg_ctl -D /usr/local/var/postgres start
77+
sleep 3
78+
/usr/local/opt/postgres/bin/createuser -s postgres
79+
echo "PG_DATABASE_URL=postgres://postgres@localhost/" >> $GITHUB_ENV
80+
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres@localhost/diesel_example" >> $GITHUB_ENV
81+
82+
- name: Install mysql (MacOS)
83+
if: runner.os == 'macOS' && matrix.backend == 'mysql'
84+
run: |
85+
brew update
86+
brew install [email protected]
87+
/usr/local/opt/[email protected]/bin/mysql_install_db
88+
/usr/local/opt/[email protected]/bin/mysql.server start
89+
sleep 3
90+
/usr/local/opt/[email protected]/bin/mysql -e "create database diesel_test; create database diesel_unit_test; grant all on \`diesel_%\`.* to 'runner'@'localhost';" -urunner
91+
echo "MYSQL_DATABASE_URL=mysql://runner@localhost/diesel_test" >> $GITHUB_ENV
92+
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://runner@localhost/diesel_example" >> $GITHUB_ENV
93+
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://runner@localhost/diesel_unit_test" >> $GITHUB_ENV
94+
95+
- name: Install postgres (Windows)
96+
if: runner.os == 'Windows' && matrix.backend == 'postgres'
97+
shell: bash
98+
run: |
99+
choco install postgresql12 --force --params '/Password:root'
100+
echo "C:\Program Files\PostgreSQL\12\bin" >> $GITHUB_PATH
101+
echo "C:\Program Files\PostgreSQL\12\lib" >> $GITHUB_PATH
102+
echo "PG_DATABASE_URL=postgres://postgres:root@localhost/" >> $GITHUB_ENV
103+
echo "PG_EXAMPLE_DATABASE_URL=postgres://postgres:root@localhost/diesel_example" >> $GITHUB_ENV
104+
105+
- name: Install mysql (Windows)
106+
if: runner.os == 'Windows' && matrix.backend == 'mysql'
107+
shell: cmd
108+
run: |
109+
choco install mysql
110+
"C:\tools\mysql\current\bin\mysql" -e "create database diesel_test; create database diesel_unit_test; grant all on `diesel_%`.* to 'root'@'localhost';" -uroot
111+
112+
- name: Set variables for mysql (Windows)
113+
if: runner.os == 'Windows' && matrix.backend == 'mysql'
114+
shell: bash
115+
run: |
116+
echo "MYSQL_DATABASE_URL=mysql://root@localhost/diesel_test" >> $GITHUB_ENV
117+
echo "MYSQL_EXAMPLE_DATABASE_URL=mysql://root@localhost/diesel_example" >> $GITHUB_ENV
118+
echo "MYSQL_UNIT_TEST_DATABASE_URL=mysql://root@localhost/diesel_unit_test" >> $GITHUB_ENV
119+
120+
- name: Install rust toolchain
121+
uses: actions-rs/toolchain@v1
122+
with:
123+
profile: minimal
124+
toolchain: ${{ matrix.rust }}
125+
override: true
126+
- name: Rust version check
127+
uses: actions-rs/cargo@v1
128+
with:
129+
command: version
130+
131+
- name: Test diesel_async
132+
uses: actions-rs/cargo@v1
133+
with:
134+
command: test
135+
args: --manifest-path Cargo.toml --no-default-features --features "${{ matrix.backend }}"
136+
137+
rustfmt_and_clippy:
138+
name: Check rustfmt style && run clippy
139+
runs-on: ubuntu-latest
140+
steps:
141+
- uses: actions/checkout@v2
142+
- uses: actions-rs/toolchain@v1
143+
with:
144+
toolchain: 1.54.0
145+
profile: minimal
146+
components: clippy, rustfmt
147+
override: true
148+
- name: Cache cargo registry
149+
uses: actions/cache@v2
150+
with:
151+
path: |
152+
~/.cargo/registry
153+
~/.cargo/git
154+
key: clippy-cargo-${{ hashFiles('**/Cargo.toml') }}
155+
156+
- name: Remove potential newer clippy.toml from dependencies
157+
run: |
158+
cargo update
159+
cargo fetch
160+
find ~/.cargo/registry -iname "*clippy.toml" -delete
161+
162+
- name: Run clippy
163+
uses: actions-rs/cargo@v1
164+
with:
165+
command: clippy
166+
args: --all
167+
168+
- name: Check formating
169+
uses: actions-rs/cargo@v1
170+
with:
171+
command: fmt
172+
args: --all -- --check

0 commit comments

Comments
 (0)