Skip to content

Commit c136f2e

Browse files
committed
chore: dual publish
1 parent f61d5a1 commit c136f2e

File tree

18 files changed

+1926
-6
lines changed

18 files changed

+1926
-6
lines changed

.github/workflows/publish.reusable.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,23 @@ jobs:
3333
exit 1
3434
fi
3535
36+
- name: Generate Packages (deprecated)
37+
id: generate-packages
38+
run: node packages/@postgres-language-server/cli/scripts/generate-packages.mjs
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
RELEASE_TAG: ${{ inputs.release-tag }}
42+
PRERELEASE: ${{ inputs.is-prerelease }}
43+
3644
- name: Generate Packages
3745
id: generate-packages
38-
run: node packages/@postgrestools/postgrestools/scripts/generate-packages.mjs
46+
run: node packages/@postgres-language-server/cli/scripts/generate-packages.mjs
3947
env:
4048
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4149
RELEASE_TAG: ${{ inputs.release-tag }}
4250
PRERELEASE: ${{ inputs.is-prerelease }}
4351

44-
- name: Publish npm packages as nightly
52+
- name: Publish npm packages as nightly (deprecated)
4553
if: inputs.is-prerelease == 'true'
4654
run: |
4755
for package in packages/@postgrestools/*; do
@@ -50,7 +58,16 @@ jobs:
5058
env:
5159
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} #
5260

53-
- name: Publish npm packages as latest
61+
- name: Publish npm packages as nightly (deprecated)
62+
if: inputs.is-prerelease == 'true'
63+
run: |
64+
for package in packages/@postgres-language-server/*; do
65+
npm publish "$package" --tag nightly --access public --provenance
66+
done
67+
env:
68+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} #
69+
70+
- name: Publish npm packages as latest (deprecated)
5471
if: inputs.is-prerelease != 'true'
5572
run: |
5673
for package in packages/@postgrestools/*; do
@@ -66,3 +83,20 @@ jobs:
6683
done
6784
env:
6885
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
86+
87+
- name: Publish npm packages as latest
88+
if: inputs.is-prerelease != 'true'
89+
run: |
90+
for package in packages/@postgres-language-server/*; do
91+
version="${{ inputs.release-tag }}"
92+
npm_package_name=$(jq -r ".name" "$package/package.json")
93+
94+
if npm view "$npm_package_name@$version" version 2>/dev/null; then
95+
echo "Package $npm_package_name@$version already exists, skipping..."
96+
else
97+
echo "Publishing $npm_package_name@$version..."
98+
npm publish "$package" --tag latest --access public --provenance
99+
fi
100+
done
101+
env:
102+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,21 @@ jobs:
9696
if: matrix.config.os == 'windows-2022'
9797
run: |
9898
mkdir dist
99+
# deprecated
99100
cp target/${{ matrix.config.target }}/release/postgrestools.exe ./dist/postgrestools_${{ matrix.config.target }}
101+
cp target/${{ matrix.config.target }}/release/postgres-language-server.exe ./dist/postgres-language-server_${{ matrix.config.target }}
102+
100103
- name: 👦 Name the Binary
101104
if: matrix.config.os != 'windows-2022'
102105
run: |
103106
mkdir dist
107+
# deprecated
104108
cp target/${{ matrix.config.target }}/release/postgrestools ./dist/postgrestools_${{ matrix.config.target }}
109+
cp target/${{ matrix.config.target }}/release/postgres-language-server ./dist/postgres-language-server_${{ matrix.config.target }}
105110
106111
# It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other.
107112
# A common workaround is to upload and download the resulting artifacts.
108-
- name: 👆 Upload Artifacts
113+
- name: 👆 Upload Artifacts (deprecated)
109114
id: upload-artifacts
110115
uses: actions/upload-artifact@v4
111116
with:
@@ -117,6 +122,20 @@ jobs:
117122
compression-level: 2
118123
if-no-files-found: error
119124

125+
# It is not possible to return the artifacts from the matrix jobs individually: Matrix outputs overwrite each other.
126+
# A common workaround is to upload and download the resulting artifacts.
127+
- name: 👆 Upload Artifacts
128+
id: upload-artifacts
129+
uses: actions/upload-artifact@v4
130+
with:
131+
name: postgres-language-server_${{ matrix.config.target }}
132+
path: ./dist/postgres-language-server_*
133+
# The default compression level is 6; this took the binary down from 350 to 330MB.
134+
# It is recommended to use a lower level for binaries, since the compressed result is not much smaller,
135+
# and the higher levels of compression take much longer.
136+
compression-level: 2
137+
if-no-files-found: error
138+
120139
create_changelog_and_release:
121140
runs-on: ubuntu-latest
122141
needs: [extract_version, build_and_test] # make sure that tests & build work correctly
@@ -142,13 +161,20 @@ jobs:
142161
echo "Tag does not match: ${{ steps.create_changelog.outputs.version }} vs ${{ needs.extract_version.outputs.version }}"
143162
exit 1
144163
145-
- name: 👇 Download Artifacts
164+
- name: 👇 Download Artifacts (deprecated)
146165
uses: actions/download-artifact@v4
147166
id: download
148167
with:
149168
merge-multiple: true
150169
pattern: postgrestools_*
151170

171+
- name: 👇 Download Artifacts
172+
uses: actions/download-artifact@v4
173+
id: download
174+
with:
175+
merge-multiple: true
176+
pattern: postgres-language-server_*
177+
152178
- name: 📂 Create Release
153179
uses: softprops/action-gh-release@v2
154180
id: create-release

crates/pgt_cli/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ doctest = false
6161
[[bin]]
6262
name = "postgrestools"
6363
path = "src/main.rs"
64+
65+
[[bin]]
66+
name = "postgres-language-server"
67+
path = "src/main.rs"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "@postgres-language-server/backend-jsonrpc",
3+
"version": "<placeholder>",
4+
"main": "dist/index.js",
5+
"scripts": {
6+
"test": "bun test",
7+
"test:ci": "bun build && bun test",
8+
"build": "bun build ./src/index.ts --outdir ./dist --target node"
9+
},
10+
"files": ["dist/", "README.md"],
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/supabase-community/postgres-language-server.git",
14+
"directory": "packages/@postgres-language-server/backend-jsonrpc"
15+
},
16+
"author": "Supabase Community",
17+
"bugs": "ttps://github.com/supabase-community/postgres-language-server/issues",
18+
"description": "Bindings to the JSON-RPC Workspace API of the Postgres Language Tools daemon",
19+
"keywords": ["TypeScript", "Postgres"],
20+
"license": "MIT",
21+
"publishConfig": {
22+
"provenance": true
23+
},
24+
"optionalDependencies": {
25+
"@postgres-language-server/cli-win32-x64": "<placeholder>",
26+
"@postgres-language-server/cli-win32-arm64": "<placeholder>",
27+
"@postgres-language-server/cli-darwin-x64": "<placeholder>",
28+
"@postgres-language-server/cli-darwin-arm64": "<placeholder>",
29+
"@postgres-language-server/cli-linux-x64": "<placeholder>",
30+
"@postgres-language-server/cli-linux-arm64": "<placeholder>"
31+
}
32+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { execSync } from "node:child_process";
2+
3+
/**
4+
* Gets the path of the binary for the current platform
5+
*
6+
* @returns Filesystem path to the binary, or null if no prebuilt distribution exists for the current platform
7+
*/
8+
export function getCommand(): string | null {
9+
const { platform, arch } = process;
10+
11+
const PLATFORMS: Partial<
12+
Record<
13+
NodeJS.Platform | "linux-musl",
14+
Partial<Record<NodeJS.Architecture, string>>
15+
>
16+
> = {
17+
win32: {
18+
x64: "@postgres-language-server/cli-x86_64-windows-msvc/postgres-language-server.exe",
19+
arm64: "@postgres-language-server/cli-aarch64-windows-msvc/postgres-language-server.exe",
20+
},
21+
darwin: {
22+
x64: "@postgres-language-server/cli-x86_64-apple-darwin/postgres-language-server",
23+
arm64: "@postgres-language-server/cli-aarch64-apple-darwin/postgres-language-server",
24+
},
25+
linux: {
26+
x64: "@postgres-language-server/cli-x86_64-linux-gnu/postgres-language-server",
27+
arm64: "@postgres-language-server/cli-aarch64-linux-gnu/postgres-language-server",
28+
},
29+
"linux-musl": {
30+
x64: "@postgres-language-server/cli-x86_64-linux-musl/postgres-language-server",
31+
// no arm64 build for musl
32+
},
33+
};
34+
35+
function isMusl() {
36+
let stderr = "";
37+
try {
38+
stderr = execSync("ldd --version", {
39+
stdio: [
40+
"ignore", // stdin
41+
"pipe", // stdout – glibc systems print here
42+
"pipe", // stderr – musl systems print here
43+
],
44+
}).toString();
45+
} catch (err: unknown) {
46+
if (hasStdErr(err)) {
47+
stderr = err.stderr;
48+
}
49+
}
50+
if (stderr.indexOf("musl") > -1) {
51+
return true;
52+
}
53+
return false;
54+
}
55+
56+
function getPlatform(): NodeJS.Platform | "linux-musl" {
57+
if (platform === "linux") {
58+
return isMusl() ? "linux-musl" : "linux";
59+
}
60+
61+
return platform;
62+
}
63+
64+
const binPath = PLATFORMS?.[getPlatform()]?.[arch];
65+
if (!binPath) {
66+
return null;
67+
}
68+
69+
return require.resolve(binPath);
70+
}
71+
72+
function hasStdErr(err: unknown): err is { stderr: string } {
73+
return !!(err as any)?.stderr;
74+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { getCommand } from "./command";
2+
import { createSocket } from "./socket";
3+
import { Transport } from "./transport";
4+
import { type Workspace, createWorkspace as wrapTransport } from "./workspace";
5+
6+
/**
7+
* Create an instance of the Workspace client connected to a remote daemon
8+
* instance through the JSON-RPC protocol
9+
*
10+
* @returns A Workspace client, or null if the underlying platform is not supported
11+
*/
12+
export async function createWorkspace(): Promise<Workspace | null> {
13+
const command = getCommand();
14+
if (!command) {
15+
return null;
16+
}
17+
18+
return createWorkspaceWithBinary(command);
19+
}
20+
21+
/**
22+
* Create an instance of the Workspace client connected to a remote daemon
23+
* instance through the JSON-RPC protocol, using the provided command to spawn
24+
* the daemon if necessary
25+
*
26+
* @param command Path to the binary
27+
* @returns A Workspace client, or null if the underlying platform is not supported
28+
*/
29+
export async function createWorkspaceWithBinary(
30+
command: string,
31+
): Promise<Workspace> {
32+
const socket = await createSocket(command);
33+
const transport = new Transport(socket);
34+
35+
await transport.request("initialize", {
36+
capabilities: {},
37+
client_info: {
38+
name: "@postgres-language-server/backend-jsonrpc",
39+
version: "0.0.0",
40+
},
41+
});
42+
43+
return wrapTransport(transport);
44+
}
45+
46+
export * from "./workspace";
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { spawn } from "node:child_process";
2+
import { type Socket, connect } from "node:net";
3+
4+
function getSocket(command: string): Promise<string> {
5+
return new Promise((resolve, reject) => {
6+
const process = spawn(command, ["__print_socket"], {
7+
stdio: "pipe",
8+
});
9+
10+
process.on("error", reject);
11+
12+
let pipeName = "";
13+
process.stdout.on("data", (data) => {
14+
pipeName += data.toString("utf-8");
15+
});
16+
17+
process.on("exit", (code) => {
18+
if (code === 0) {
19+
resolve(pipeName.trimEnd());
20+
} else {
21+
reject(
22+
new Error(
23+
`Command '${command} __print_socket' exited with code ${code}`,
24+
),
25+
);
26+
}
27+
});
28+
});
29+
}
30+
31+
/**
32+
* Ensure the daemon server is running and create a Socket connected to the RPC channel
33+
*
34+
* @param command Path to the daemon binary
35+
* @returns Socket instance connected to the daemon
36+
*/
37+
export async function createSocket(command: string): Promise<Socket> {
38+
const path = await getSocket(command);
39+
const socket = connect(path);
40+
41+
await new Promise((resolve, reject) => {
42+
socket.once("error", reject);
43+
socket.once("ready", resolve);
44+
});
45+
46+
return socket;
47+
}

0 commit comments

Comments
 (0)