Skip to content

Commit

Permalink
feat: setup tests in the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
dmeijboom committed Apr 17, 2024
1 parent 5575fe6 commit c75e70b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
28 changes: 28 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bazelbuild/setup-bazelisk@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build libpq
run: bazel build //:libpq
- name: Test C program
run: |
docker run --rm -d -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:16.2-alpine &&
while !</dev/tcp/127.0.0.1/5432; do sleep 1; done &&
gcc examples/c/main.c -o main -l:bazel-bin/libpq.a &&
./main
2 changes: 1 addition & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions examples/c/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <libpq-fe.h>

int main(int argc, char **argv)
{
PGconn *conn = PQconnectdb("dbname=postgres password=postgres user=postgres host=localhost port=5432");
if (PQstatus(conn) != CONNECTION_OK)
{
fprintf(stderr, "connection to database failed: %s", PQerrorMessage(conn));

PQfinish(conn);
exit(1);
}

printf("connected to database\n");
PQfinish(conn);
}

0 comments on commit c75e70b

Please sign in to comment.