Skip to content

Commit a0364dc

Browse files
authored
chore(ci): move to GitHub Actions (#291)
1 parent ea1757b commit a0364dc

4 files changed

Lines changed: 137 additions & 114 deletions

File tree

.github/workflows/ci.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
ci:
7+
runs-on: ubuntu-latest
8+
9+
env:
10+
CI: true
11+
TERM: xterm
12+
FORCE_COLOR: 1
13+
PGUSER: postgres
14+
PGPASSWORD: postgres
15+
PGHOST: localhost
16+
PGPORT: 5432
17+
18+
services:
19+
postgres:
20+
image: postgres:13
21+
env:
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: postgres
24+
POSTGRES_DB: postgres
25+
ports:
26+
- "0.0.0.0:5432:5432"
27+
# needed because the postgres container does not provide a healthcheck
28+
options:
29+
--health-cmd pg_isready --health-interval 10s --health-timeout 5s
30+
--health-retries 5 --name postgres
31+
32+
steps:
33+
- uses: actions/checkout@v2
34+
- name: 'Use Node.js 12'
35+
uses: actions/setup-node@v1
36+
with:
37+
node-version: 12
38+
- run: yarn
39+
- run: yarn clean
40+
- run: yarn format
41+
- run: yarn build
42+
- run: yarn test
43+

.github/workflows/deploy.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
CI: true
14+
TERM: xterm
15+
FORCE_COLOR: 1
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: 'Use Node.js 12'
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 12
23+
- run: git config credential.helper "store --file=.git/credentials"
24+
- run: 'echo "https://benjie:${GITHUB_TOKEN}@github.com" > .git/credentials'
25+
- run: yarn clean
26+
- run: yarn format
27+
- run: yarn build
28+
- run: scripts/ci

.travis.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

scripts/update-examples

Lines changed: 66 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const fs = require("fs");
66
const pg = require("pg");
77
const prettier = require("prettier");
88
const { graphql } = require("graphql");
9-
const child_process = require("child_process");
109
const {
1110
createPostGraphileSchema,
1211
withPostGraphileContext,
@@ -30,68 +29,6 @@ async function prettify(filepath, content) {
3029
});
3130
}
3231

33-
async function spawn(command, args, options = {}, stdin = null) {
34-
return new Promise((resolve, reject) => {
35-
console.log(command, ...args);
36-
const cp = child_process.spawn(command, args, {
37-
stdio: "pipe",
38-
...options,
39-
});
40-
let stdout = "";
41-
let stderr = "";
42-
cp.stdout.on("data", data => {
43-
stdout += data;
44-
});
45-
cp.stderr.on("data", data => {
46-
stderr += data;
47-
});
48-
cp.on("error", reject);
49-
function fail(e) {
50-
e.stdout = stdout;
51-
e.stderr = stderr;
52-
console.error(stderr);
53-
reject(e);
54-
}
55-
cp.on("close", code => {
56-
if (code === 0) {
57-
resolve({
58-
stdout,
59-
stderr,
60-
code,
61-
});
62-
} else {
63-
const e = new Error(`Failed with status code ${code}`);
64-
e.code = code;
65-
fail(e);
66-
}
67-
});
68-
if (stdin) {
69-
cp.stdin.on("error", fail);
70-
cp.stdin.write(stdin);
71-
cp.stdin.end();
72-
} else {
73-
cp.stdin.end();
74-
}
75-
});
76-
}
77-
78-
async function psql(flags, sql) {
79-
return spawn(
80-
"psql",
81-
["-X", "-1", "-v", "ON_ERROR_STOP=1", ...flags],
82-
{},
83-
sql
84-
);
85-
}
86-
87-
async function tryPsql(flags, sql) {
88-
try {
89-
return await psql(flags, sql);
90-
} catch (e) {
91-
// NOOP
92-
}
93-
}
94-
9532
async function main() {
9633
const schemaSql = fs.readFileSync(
9734
`${__dirname}/../examples/db/schema.sql`,
@@ -102,33 +39,67 @@ async function main() {
10239
"utf8"
10340
);
10441

105-
try {
106-
await spawn("dropdb", ["graphile_org_demo"]);
107-
} catch (e) {
108-
/* non-existence is fine */
42+
const password = String(Math.random());
43+
44+
{
45+
const rootPool = new pg.Pool({
46+
host: process.env.PGHOST,
47+
port: process.env.PGPORT,
48+
user: process.env.PGUSER,
49+
password: process.env.PGPASSWORD,
50+
database: "postgres",
51+
});
52+
53+
try {
54+
await rootPool.query("drop database graphile_org_demo");
55+
} catch (e) {
56+
/* non-existence is fine */
57+
}
58+
try {
59+
await rootPool.query("drop role graphiledemo");
60+
} catch (e) {
61+
/* non-existence is fine */
62+
}
63+
try {
64+
await rootPool.query("drop role graphiledemo_authenticator");
65+
} catch (e) {
66+
/* non-existence is fine */
67+
}
68+
try {
69+
await rootPool.query("drop role graphiledemo_visitor");
70+
} catch (e) {
71+
/* non-existence is fine */
72+
}
73+
74+
await rootPool.query(
75+
`CREATE ROLE graphiledemo WITH LOGIN PASSWORD '${password}' SUPERUSER`
76+
);
77+
await rootPool.query(
78+
`CREATE ROLE graphiledemo_authenticator WITH LOGIN PASSWORD '${password}' NOINHERIT;`
79+
);
80+
await rootPool.query(`CREATE ROLE graphiledemo_visitor;`);
81+
await rootPool.query(
82+
`GRANT graphiledemo_visitor TO graphiledemo_authenticator;`
83+
);
84+
await rootPool.query(
85+
`create database graphile_org_demo owner graphiledemo`
86+
);
87+
rootPool.end();
10988
}
11089

111-
const password = String(Math.random());
112-
await tryPsql(
113-
["template1"],
114-
`CREATE ROLE graphiledemo WITH LOGIN PASSWORD '${password}' SUPERUSER`
115-
);
116-
await tryPsql(
117-
["template1"],
118-
`CREATE ROLE graphiledemo_authenticator WITH LOGIN PASSWORD '${password}' NOINHERIT;`
119-
);
120-
await tryPsql(["template1"], `CREATE ROLE graphiledemo_visitor;`);
121-
await tryPsql(
122-
["template1"],
123-
`GRANT graphiledemo_visitor TO graphiledemo_authenticator;`
124-
);
90+
{
91+
const ownerPool = new pg.Pool({
92+
host: process.env.PGHOST,
93+
port: process.env.PGPORT,
94+
user: process.env.PGUSER,
95+
password: process.env.PGPASSWORD,
96+
database: "graphile_org_demo",
97+
});
12598

126-
await spawn("createdb", ["-O", "graphiledemo", "graphile_org_demo"]);
127-
await psql(["graphile_org_demo"], schemaSql);
128-
await psql(["graphile_org_demo"], dataSql);
129-
await psql(
130-
["graphile_org_demo"],
131-
`\
99+
await ownerPool.query(schemaSql);
100+
await ownerPool.query(dataSql);
101+
await ownerPool.query(
102+
`\
132103
set search_path to app_public, app_private, public;
133104
/**
134105
* These are the tables we're using in the insert-multiple-records example
@@ -171,9 +142,15 @@ insert into quiz_entry (user_id, quiz_id) values
171142
(4, 2),
172143
(5, 3);
173144
`
174-
);
145+
);
146+
}
147+
175148
const pgPool = new pg.Pool({
176-
connectionString: "postgres:///graphile_org_demo",
149+
host: process.env.PGHOST,
150+
port: process.env.PGPORT,
151+
user: process.env.PGUSER,
152+
password: process.env.PGPASSWORD,
153+
database: "graphile_org_demo",
177154
});
178155
const getPostGraphileSchemaWithOptions = (options = {}, client = pgPool) =>
179156
createPostGraphileSchema(client, ["app_public"], {

0 commit comments

Comments
 (0)