Skip to content

Commit 6282d8f

Browse files
committed
generated workflows for windows and no-windows
1 parent c5418ef commit 6282d8f

19 files changed

+251
-19
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Generated Build libpg-query no windows 🛠
2+
'on':
3+
workflow_dispatch: null
4+
jobs:
5+
build-artifacts:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
matrix:
9+
os:
10+
- macos-latest
11+
- ubuntu-latest
12+
steps:
13+
- name: Checkout Repository 📥
14+
uses: actions/checkout@v4
15+
- name: Setup Node.js 🌐
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: 20.x
19+
cache: yarn
20+
- name: Configure Git 🛠
21+
run: |
22+
git config user.name "Cosmology"
23+
git config user.email "[email protected]"
24+
- name: Install and Build 📦
25+
run: |
26+
yarn
27+
yarn binary:build
28+
- name: Save Artifacts For Supabase CDN 🏗
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: build-supabase-artifact-${{ matrix.os }}
32+
path: ./build/stage/libpg-query-node/
33+
- name: Save Artifacts For NPM 🏗
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: build-npm-artifact-${{ matrix.os }}
37+
path: |
38+
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
39+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}
40+
build-wasm:
41+
needs: build-artifacts
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout Repository 📥
45+
uses: actions/checkout@v4
46+
- name: Setup Node.js 🌐
47+
uses: actions/setup-node@v4
48+
with:
49+
node-version: 20.x
50+
cache: yarn
51+
- name: Install and Build 🚀
52+
run: |
53+
yarn
54+
- name: Install Emscripten ✍🏻
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install cmake python3 python3-pip
58+
git clone --branch 3.1.59 --depth 1 https://github.com/emscripten-core/emsdk.git
59+
cd emsdk
60+
./emsdk install 3.1.59
61+
./emsdk activate 3.1.59
62+
source ./emsdk_env.sh
63+
- name: Build with Emscripten 🏗
64+
run: |
65+
source ./emsdk/emsdk_env.sh
66+
emmake make
67+
emmake make build
68+
- name: Archive production artifacts 🏛
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: wasm-artifacts
72+
path: wasm
73+
prepare-and-log:
74+
needs: build-wasm
75+
runs-on: ubuntu-latest
76+
steps:
77+
- name: Checkout Repository 📥
78+
uses: actions/checkout@v4
79+
- name: Get Artifacts 📚
80+
uses: actions/download-artifact@v4
81+
with:
82+
path: downloaded-artifacts
83+
- name: Prepare artifacts 📦
84+
run: |
85+
find ./downloaded-artifacts/
86+
cp ./downloaded-artifacts/build-npm-artifact-windows-latest/pg_query.lib ./libpg_query/windows/queryparser.lib
87+
cp ./downloaded-artifacts/build-npm-artifact-ubuntu-latest/libpg_query.a ./libpg_query/linux/libpg_query.a
88+
cp ./downloaded-artifacts/build-npm-artifact-macos-latest/libpg_query.a ./libpg_query/osx/libpg_query.a
89+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.js ./wasm/libpg-query.js
90+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.wasm ./wasm/libpg-query.wasm
91+
rm -rf ./downloaded-artifacts
92+
- name: Log
93+
run: |
94+
find ./libpg_query/
95+
find ./wasm

.github/workflows/generated-build-and-test.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and Test 🛠
1+
name: Generated Build libpg-query 🛠
22
'on':
33
workflow_dispatch: null
44
jobs:
@@ -7,6 +7,7 @@ jobs:
77
strategy:
88
matrix:
99
os:
10+
- windows-latest
1011
- macos-latest
1112
- ubuntu-latest
1213
steps:
@@ -36,7 +37,8 @@ jobs:
3637
name: build-npm-artifact-${{ matrix.os }}
3738
path: |
3839
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
39-
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}
40+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' ||
41+
matrix.os == 'windows-latest' && './libpg_query/windows/pg_query.lib' }}
4042
build-wasm:
4143
needs: build-artifacts
4244
runs-on: ubuntu-latest
@@ -70,7 +72,7 @@ jobs:
7072
with:
7173
name: wasm-artifacts
7274
path: wasm
73-
prepare-and-publish:
75+
prepare-and-log:
7476
needs: build-wasm
7577
runs-on: ubuntu-latest
7678
steps:

.github/workflows/run-tests-linux.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Linux 🧪
22

33
on:
4+
push:
45
pull_request:
5-
types: [opened, push, reopened]
6+
types: [opened, synchronize, reopened]
67
workflow_dispatch:
78

89
jobs:

.github/workflows/run-tests-mac.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Mac 🧪
22

33
on:
4+
push:
45
pull_request:
5-
types: [opened, push, reopened]
6+
types: [opened, synchronize, reopened]
67
workflow_dispatch:
78

89
jobs:

.github/workflows/run-tests-win.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Windows 🛠
22

33
on:
4+
push:
45
pull_request:
5-
types: [opened, push, reopened]
6+
types: [opened, synchronize, reopened]
67
workflow_dispatch:
78

89
jobs:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build and Publish 🚀
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-artifacts:
8+
import-yaml: yaml/build-artifacts-no-win.yaml
9+
10+
build-wasm:
11+
needs: build-artifacts
12+
import-yaml: yaml/build-wasm.yaml
13+
14+
prepare-and-publish:
15+
needs: build-wasm
16+
import-yaml: yaml/prepare-and-publish.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build and Test 🛠
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-artifacts:
8+
import-yaml: yaml/build-artifacts-no-win.yaml
9+
10+
build-wasm:
11+
needs: build-artifacts
12+
import-yaml: yaml/build-wasm.yaml
13+
14+
prepare-and-log:
15+
needs: build-wasm
16+
import-yaml: yaml/prepare-and-log.yaml

.yamlize/workflows/build-and-test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
needs: build-artifacts
1212
import-yaml: yaml/build-wasm.yaml
1313

14-
prepare-and-publish:
14+
prepare-and-log:
1515
needs: build-wasm
1616
import-yaml: yaml/prepare-and-log.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: Save Artifacts For NPM 🏗
2+
uses: actions/upload-artifact@v4
3+
with:
4+
name: build-npm-artifact-${{ matrix.os }}
5+
path: |
6+
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
7+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}

.yamlize/workflows/yaml/artifacts/npm.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ with:
44
name: build-npm-artifact-${{ matrix.os }}
55
path: |
66
${{ matrix.os == 'macos-latest' && './libpg_query/osx/libpg_query.a' ||
7-
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' }}
7+
matrix.os == 'ubuntu-latest' && './libpg_query/linux/libpg_query.a' ||
8+
matrix.os == 'windows-latest' && './libpg_query/windows/pg_query.lib' }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: Prepare artifacts 📦
2+
run: |
3+
find ./downloaded-artifacts/
4+
cp ./downloaded-artifacts/build-npm-artifact-ubuntu-latest/libpg_query.a ./libpg_query/linux/libpg_query.a
5+
cp ./downloaded-artifacts/build-npm-artifact-macos-latest/libpg_query.a ./libpg_query/osx/libpg_query.a
6+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.js ./wasm/libpg-query.js
7+
cp ./downloaded-artifacts/wasm-artifacts/libpg-query.wasm ./wasm/libpg-query.wasm
8+
rm -rf ./downloaded-artifacts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
runs-on: ${{ matrix.os }}
2+
strategy:
3+
matrix:
4+
os: [macos-latest, ubuntu-latest]
5+
steps:
6+
- import-yaml: git/checkout.yaml
7+
- import-yaml: node/setup.yaml
8+
- import-yaml: git/configure.yaml
9+
10+
- name: Install and Build 📦
11+
run: |
12+
yarn
13+
yarn binary:build
14+
15+
- import-yaml: artifacts/supabase.yaml
16+
- import-yaml: artifacts/npm-no-win.yaml

.yamlize/workflows/yaml/build-artifacts.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
runs-on: ${{ matrix.os }}
22
strategy:
33
matrix:
4-
os: [macos-latest, ubuntu-latest]
4+
os: [windows-latest, macos-latest, ubuntu-latest]
55
steps:
66
- import-yaml: git/checkout.yaml
77
- import-yaml: node/setup.yaml

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
"configure": "node-pre-gyp configure",
3535
"install": "node-pre-gyp install --fallback-to-build --loglevel verbose",
3636
"rebuild": "node-pre-gyp rebuild --loglevel verbose",
37-
"make:wasm": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
38-
"build:wasm": "yarn make:wasm build",
39-
"rebuild:wasm": "yarn make:wasm rebuild",
40-
"clean:wasm": "yarn make:wasm clean",
41-
"clean-cache:wasm": "yarn make:wasm clean-cache",
42-
"workflows": "node script/workflows.js",
43-
"build:generate": "node script/utils/generate.js",
37+
"wasm:make": "docker run --rm -v $(pwd):/src -u $(id -u):$(id -g) emscripten/emsdk emmake make",
38+
"wasm:build": "yarn wasm:make build",
39+
"wasm:rebuild": "yarn wasm:make rebuild",
40+
"wasm:clean": "yarn wasm:make clean",
41+
"wasm:clean-cache": "yarn wasm:make clean-cache",
42+
"generate:workflows:win": "node script/generate-workflows.js",
43+
"generate:workflows:no-win": "node script/generate-non-win-workflows.js",
44+
"generate:workflows": "npm run generate:workflows:win && npm run generate:workflows:no-win",
45+
"generate:build": "node script/utils/generate.js",
4446
"test": "mocha --timeout 5000",
4547
"binary:build": "node-pre-gyp rebuild package",
4648
"binary:publish": "AWS_PROFILE=supabase-dev node-pre-gyp publish"

script/buildAddon.bat

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
:: this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)
1+
:: this file is auto-generated, use "yarn generate:build <env>" to rebuild with an env (e.g., pg-15)
22
@echo off
33

44
set LIBPG_REPO=https://github.com/pganalyze/libpg_query.git

script/buildAddon.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
# this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)
2+
# this file is auto-generated, use "yarn generate:build <env>" to rebuild with an env (e.g., pg-15)
33

44
LIBPG_REPO=https://github.com/pganalyze/libpg_query.git
55
LIBPG_COMMIT=db39825bc7c1ddd45962ec6a626d740b7f8f027a

script/generate-non-win-workflows.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const { exec } = require('child_process');
2+
const { join } = require('path');
3+
const fs = require('fs');
4+
const yaml = require('js-yaml');
5+
6+
// if (typeof process.argv[2] !== 'string') {
7+
// throw new Error('branchName not provided');
8+
// }
9+
10+
const yamldir = (s) => join(__dirname, '/../.yamlize/', s);
11+
const workflowDir = (s) => join(__dirname, '/../.github/workflows/', s);
12+
13+
const cmd = (config, workflow) => ([
14+
'yamlize',
15+
'--config',
16+
yamldir(`config/${config}`),
17+
18+
'--inFile',
19+
yamldir(`workflows/${workflow}`),
20+
21+
'--outFile',
22+
workflowDir(`generated-${workflow}`),
23+
].join(' '));
24+
25+
26+
exec(cmd('config.yaml', 'build-and-test-no-win.yaml'), (error, _stdout, _stderr) => {
27+
if (error) {
28+
console.error(`Error: ${error.message}`);
29+
return;
30+
}
31+
32+
// Read the generated YAML file
33+
const outputPath = workflowDir(`generated-build-and-test-no-win.yaml`);
34+
try {
35+
const fileContents = fs.readFileSync(outputPath, 'utf8');
36+
const data = yaml.load(fileContents);
37+
38+
// Modify the top-level 'name' property
39+
data.name = 'Generated Build libpg-query no windows 🛠';
40+
41+
// Write the modified YAML back to the file
42+
const newYamlContent = yaml.dump(data, { lineWidth: -1 });
43+
fs.writeFileSync(outputPath, newYamlContent, 'utf8');
44+
} catch (readOrWriteError) {
45+
console.error(`Error processing YAML file: ${readOrWriteError}`);
46+
}
47+
});

script/workflows.js renamed to script/generate-workflows.js

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { exec } = require('child_process');
22
const { join } = require('path');
3+
const fs = require('fs');
4+
const yaml = require('js-yaml');
35

46
// if (typeof process.argv[2] !== 'string') {
57
// throw new Error('branchName not provided');
@@ -26,4 +28,21 @@ exec(cmd('config.yaml', 'build-and-test.yaml'), (error, _stdout, _stderr) => {
2628
console.error(`Error: ${error.message}`);
2729
return;
2830
}
31+
32+
33+
// Read the generated YAML file
34+
const outputPath = workflowDir(`generated-build-and-test.yaml`);
35+
try {
36+
const fileContents = fs.readFileSync(outputPath, 'utf8');
37+
const data = yaml.load(fileContents);
38+
39+
// Modify the top-level 'name' property
40+
data.name = 'Generated Build libpg-query 🛠';
41+
42+
// Write the modified YAML back to the file
43+
const newYamlContent = yaml.dump(data, { lineWidth: -1 });
44+
fs.writeFileSync(outputPath, newYamlContent, 'utf8');
45+
} catch (readOrWriteError) {
46+
console.error(`Error processing YAML file: ${readOrWriteError}`);
47+
}
2948
});

script/utils/generate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ templates.forEach(template => {
9090
let newContent = '';
9191

9292
if (commentPrefix) {
93-
const commentLine = `${commentPrefix} this file is auto-generated, use "yarn build:generate <env>" to rebuild with an env (e.g., pg-15)\n`;
93+
const commentLine = `${commentPrefix} this file is auto-generated, use "yarn generate:build <env>" to rebuild with an env (e.g., pg-15)\n`;
9494
if (content.startsWith('#!')) {
9595
// Find the end of the first line (shebang)
9696
const firstLineEnd = content.indexOf('\n') + 1;

0 commit comments

Comments
 (0)