Skip to content

Commit 7bcfd2a

Browse files
authored
End to end test pipeline and fix install script to be sh compatible (#218)
* hrm * hrm * hrm * strate * hrm * z * fail test * run happy test * test * test bash * test * fix install.sh
1 parent 4c79f9f commit 7bcfd2a

File tree

2 files changed

+140
-8
lines changed

2 files changed

+140
-8
lines changed

.github/workflows/end-to-end.yaml

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: End to end tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
node-install:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node: [ 12, 14, 15, 16, 17, 18, 19, 20 ]
15+
defaults:
16+
run:
17+
working-directory: ./node
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Use Node.js
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: ${{ matrix.node }}
25+
26+
- name: Install sqlx-ts
27+
run: npm install
28+
29+
- name: Run sqlx-ts version
30+
run: ./sqlx-ts --version
31+
32+
- name: run sqlx-ts help
33+
run: ./sqlx-ts --help
34+
35+
e2e:
36+
runs-on: ubuntu-latest
37+
strategy:
38+
matrix:
39+
db:
40+
- mysql: 8
41+
- mysql: 5.7
42+
- mysql: 5.6
43+
- postgres: 16
44+
- postgres: 15
45+
- postgres: 14
46+
- postgres: 13
47+
- postgres: 12
48+
49+
steps:
50+
- name: Checkout sources
51+
uses: actions/checkout@v3
52+
53+
- name: Install stable toolchain
54+
uses: actions-rs/toolchain@v1
55+
with:
56+
profile: minimal
57+
toolchain: stable
58+
override: true
59+
60+
- run: rustup toolchain install stable --profile minimal
61+
62+
- uses: Swatinem/rust-cache@v2
63+
with:
64+
# To only cache runs from `master`:
65+
save-if: ${{ github.ref == 'refs/heads/master' }}
66+
# Specifies what to use as the backend providing cache
67+
# Can be set to either "github" or "buildjet"
68+
# default: "github"
69+
cache-provider: "github"
70+
71+
72+
- name: build docker-compose services for integration tests
73+
run: docker compose -f docker-compose.yml up -d
74+
env:
75+
MYSQL_VERSION: ${{ matrix.db.mysql }}
76+
PG_VERSION: ${{ matrix.db.postgres }}
77+
MYSQL_MIGRATION_FILE: "${{ matrix.db.mysql == '5.6' && 'mysql_migration_5_6.sql' || 'mysql_migration.sql' }}"
78+
79+
- uses: GuillaumeFalourd/wait-sleep-action@v1
80+
with:
81+
time: '10' # for 10 seconds
82+
83+
- name: Check the docker-compose services running
84+
run: docker ps -a
85+
86+
- name: build
87+
run: cargo build
88+
89+
- name: Add failure.ts test file
90+
run: |
91+
mkdir -p tests/staging
92+
cat << 'EOF' > tests/staging/failure.ts
93+
import { sql } from 'sqlx-ts'
94+
95+
const selectSql4 = sql`
96+
SELECT itemz.*
97+
FROM items;
98+
`
99+
EOF
100+
101+
- name: Run failure test
102+
run: |
103+
set +e
104+
./target/debug/sqlx-ts --config=.sqlxrc.sample.json tests/staging
105+
if [ $? -eq 0 ]; then
106+
echo "Expected failure, but command succeeded."
107+
exit 1
108+
fi
109+
echo "Command failed as expected."
110+
111+
rm -f tests/staging/failure.ts
112+
113+
- name: Add happy.ts test file
114+
run: |
115+
mkdir -p tests/staging
116+
cat << 'EOF' > tests/staging/happy.ts
117+
import { sql } from 'sqlx-ts'
118+
119+
const selectSql4 = sql`
120+
SELECT items.*
121+
FROM items;
122+
`
123+
EOF
124+
125+
- name: Run happy test
126+
run: ./target/debug/sqlx-ts --config=.sqlxrc.sample.json tests/staging

scripts/install.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
set -e
44

@@ -27,8 +27,8 @@ say_err() {
2727
}
2828

2929
err() {
30-
if [ ! -z $td ]; then
31-
rm -rf $td
30+
if [ -n "$td" ]; then
31+
rm -rf "$td"
3232
fi
3333

3434
say_err "ERROR $1"
@@ -119,17 +119,23 @@ say_err "GitHub repository: $url"
119119
url="$url/releases"
120120

121121
if [ -z $tag ]; then
122-
if [ ! -z $artifact ]; then
122+
if [ -n $artifact ]; then
123123
echo "artifact was given, it will override tag - artifact: $artifact, tag: $tag"
124124
fi
125125

126126
tag=$(curl --silent "https://api.github.com/repos/jasonshin/sqlx-ts/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
127127
say_err "Tag: latest ($tag)"
128128
else
129-
if [[ $tag != v* ]]; then
130-
echo "received tag does not start with v, it will be prefixed with v - tag: $tag"
131-
tag="v$tag"
132-
fi
129+
case $tag in
130+
v*)
131+
# Tag already starts with v
132+
;;
133+
*)
134+
# Tag doesn't start with v, add it
135+
echo "received tag does not start with v, it will be prefixed with v - tag: $tag"
136+
tag="v$tag"
137+
;;
138+
esac
133139

134140
say_err "Tag: $tag"
135141
fi

0 commit comments

Comments
 (0)