Skip to content

Commit 9ba2266

Browse files
authored
Merge pull request #9 from supabase-community/fix/binary-names
fix: use new binary name
2 parents 84e0778 + 927fd99 commit 9ba2266

7 files changed

Lines changed: 63 additions & 36 deletions

File tree

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ jobs:
1515
- uses: ./
1616
with:
1717
version: ${{ inputs.version }}
18-
- run: postgrestools check --skip-db test.sql
18+
- run: postgres-language-server check --skip-db test.sql

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
This is a simple action that will install the [Postgres Language Server](https://github.com/supabase-community/postgres-language-server) on your runner. It will install the appropriate binary for your machine.
44

55
It has a single input: `version: latest | <semver>`.
6-
Use `latest` if you want to use the latest available PostgresTools version in your runner.
6+
Use `latest` if you want to use the latest available Postgres Language Server version in your runner.
77
Use a specific tag, such as `0.16.0`, if you want to use a specific version.
88

99
Whatever version is used will be output as `outputs.installed-version`.
1010

11+
The action installs `postgres-language-server` and also provides
12+
`postgrestools` as a compatibility alias.
13+
1114
## Example Usage
1215

1316
```yaml

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name: Postgres Language Server CLI Action
2-
description: Setup Postgres Language Server on Github Action Runners
2+
description: Setup Postgres Language Server on GitHub Actions runners
33
author: Supabase-Community
44
inputs:
55
version:
66
description: Semver-Version of CLI to install. Use "latest" for always using the latest stable release.
77
required: true
88
outputs:
99
installed-version:
10-
description: Version that of the CLI that was installed on your runner.
10+
description: Version of the CLI installed on your runner.
1111
runs:
1212
using: node20
1313
main: dist/index.js

dist/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28256,6 +28256,8 @@ const node_path_1 = __importDefault(__nccwpck_require__(6760));
2825628256
const promises_1 = __nccwpck_require__(1943);
2825728257
const fs_1 = __nccwpck_require__(9896);
2825828258
const doExec = (0, node_util_1.promisify)(node_child_process_1.exec);
28259+
const currentBinaryName = 'postgres-language-server';
28260+
const legacyBinaryName = 'postgrestools';
2825928261
const platformMappings = {
2826028262
darwin: 'darwin',
2826128263
linux: 'unknown-linux-gnu',
@@ -28310,21 +28312,29 @@ function getDownloadUrl(version, binary) {
2831028312
}
2831128313
function determineInstalledVersion() {
2831228314
return __awaiter(this, void 0, void 0, function* () {
28313-
const { stdout } = yield doExec(`postgrestools --version`);
28314-
const version = stdout.trim();
28315-
if (!version) {
28316-
throw new Error('Could not determine installed PostgresTools version');
28315+
const binaries = [currentBinaryName, legacyBinaryName];
28316+
for (const binary of binaries) {
28317+
try {
28318+
const { stdout } = yield doExec(`${binary} --version`);
28319+
const version = stdout.trim();
28320+
if (version) {
28321+
return version;
28322+
}
28323+
}
28324+
catch (_a) {
28325+
continue;
28326+
}
2831728327
}
28318-
return version;
28328+
throw new Error('Could not determine installed Postgres Language Server version');
2831928329
});
2832028330
}
2832128331
function main() {
2832228332
return __awaiter(this, void 0, void 0, function* () {
2832328333
try {
2832428334
const version = core.getInput('version', { required: true });
28325-
let url = getDownloadUrl(version, 'postgres-language-server');
28335+
let url = getDownloadUrl(version, currentBinaryName);
2832628336
if (!(yield urlExists(url))) {
28327-
url = getDownloadUrl(version, 'postgrestools');
28337+
url = getDownloadUrl(version, legacyBinaryName);
2832828338
}
2832928339
const tool = yield toolCache.downloadTool(url);
2833028340
yield (0, promises_1.chmod)(tool, '755');
@@ -28333,14 +28343,14 @@ function main() {
2833328343
core.info(`Binary dir not found. Creating one at ${binDir}`);
2833428344
yield (0, promises_1.mkdir)(binDir, { recursive: true });
2833528345
}
28336-
const symlinkPath = node_path_1.default.join(binDir, 'postgrestools');
28337-
yield (0, promises_1.symlink)(tool, symlinkPath);
28346+
const binarySymlinkPath = node_path_1.default.join(binDir, currentBinaryName);
28347+
yield (0, promises_1.rm)(binarySymlinkPath, { force: true });
28348+
yield (0, promises_1.symlink)(tool, binarySymlinkPath);
28349+
const legacySymlinkPath = node_path_1.default.join(binDir, legacyBinaryName);
28350+
yield (0, promises_1.rm)(legacySymlinkPath, { force: true });
28351+
yield (0, promises_1.symlink)(tool, legacySymlinkPath);
2833828352
core.info(`Adding to path: ${binDir}`);
2833928353
core.addPath(binDir);
28340-
/**
28341-
* TODO: GH Runner still won't find the `postgrestools` binary
28342-
* The `tool` binary path works, however – seems to be something with symlink?
28343-
*/
2834428354
const installedVersion = yield determineInstalledVersion();
2834528355
core.setOutput('installed-version', installedVersion);
2834628356
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "postgrestools-cli-action",
2+
"name": "postgres-language-server-cli-action",
33
"version": "0.0.1",
4-
"description": "Installs the PostgresTools Cli on your Github Action Runner.",
4+
"description": "Installs the Postgres Language Server CLI on your GitHub Actions runner.",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "ncc build --source-map --license license.txt src/index.ts -o dist",
@@ -15,7 +15,7 @@
1515
"keywords": ["actions", "node", "setup", "postgres", "sql", "lsp"],
1616
"repository": {
1717
"type": "git",
18-
"url": "git+https://github.com/supabase-community/pglt-cli-action.git"
18+
"url": "git+https://github.com/supabase-community/postgres-language-server-cli-action.git"
1919
},
2020
"author": "Supabase Community",
2121
"contributors": [

src/index.ts

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ import { exec } from 'node:child_process'
44
import { promisify } from 'node:util'
55
import os from 'node:os'
66
import path from 'node:path'
7-
import { mkdir, symlink, chmod } from 'fs/promises'
7+
import { chmod, mkdir, rm, symlink } from 'fs/promises'
88
import { existsSync } from 'fs'
99

1010
const doExec = promisify(exec)
1111

12+
const currentBinaryName = 'postgres-language-server'
13+
const legacyBinaryName = 'postgrestools'
14+
1215
const platformMappings = {
1316
darwin: 'darwin',
1417
linux: 'unknown-linux-gnu',
@@ -75,23 +78,33 @@ function getDownloadUrl(version: string, binary: string): string {
7578
}
7679

7780
async function determineInstalledVersion(): Promise<string> {
78-
const { stdout } = await doExec(`postgrestools --version`)
79-
80-
const version = stdout.trim()
81-
if (!version) {
82-
throw new Error('Could not determine installed PostgresTools version')
81+
const binaries = [currentBinaryName, legacyBinaryName]
82+
83+
for (const binary of binaries) {
84+
try {
85+
const { stdout } = await doExec(`${binary} --version`)
86+
const version = stdout.trim()
87+
88+
if (version) {
89+
return version
90+
}
91+
} catch {
92+
continue
93+
}
8394
}
8495

85-
return version
96+
throw new Error(
97+
'Could not determine installed Postgres Language Server version'
98+
)
8699
}
87100

88101
async function main() {
89102
try {
90103
const version = core.getInput('version', { required: true })
91104

92-
let url = getDownloadUrl(version, 'postgres-language-server')
105+
let url = getDownloadUrl(version, currentBinaryName)
93106
if (!(await urlExists(url))) {
94-
url = getDownloadUrl(version, 'postgrestools')
107+
url = getDownloadUrl(version, legacyBinaryName)
95108
}
96109

97110
const tool = await toolCache.downloadTool(url)
@@ -104,16 +117,17 @@ async function main() {
104117
await mkdir(binDir, { recursive: true })
105118
}
106119

107-
const symlinkPath = path.join(binDir, 'postgrestools')
108-
await symlink(tool, symlinkPath)
120+
const binarySymlinkPath = path.join(binDir, currentBinaryName)
121+
await rm(binarySymlinkPath, { force: true })
122+
await symlink(tool, binarySymlinkPath)
123+
124+
const legacySymlinkPath = path.join(binDir, legacyBinaryName)
125+
await rm(legacySymlinkPath, { force: true })
126+
await symlink(tool, legacySymlinkPath)
109127

110128
core.info(`Adding to path: ${binDir}`)
111129
core.addPath(binDir)
112130

113-
/**
114-
* TODO: GH Runner still won't find the `postgrestools` binary
115-
* The `tool` binary path works, however – seems to be something with symlink?
116-
*/
117131
const installedVersion = await determineInstalledVersion()
118132
core.setOutput('installed-version', installedVersion)
119133
} catch (err) {

0 commit comments

Comments
 (0)