Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
- uses: ./
with:
version: ${{ inputs.version }}
- run: postgrestools check --skip-db test.sql
- run: postgres-language-server check --skip-db test.sql
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
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.

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

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

The action installs `postgres-language-server` and also provides
`postgrestools` as a compatibility alias.

## Example Usage

```yaml
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Postgres Language Server CLI Action
description: Setup Postgres Language Server on Github Action Runners
description: Setup Postgres Language Server on GitHub Actions runners
author: Supabase-Community
inputs:
version:
description: Semver-Version of CLI to install. Use "latest" for always using the latest stable release.
required: true
outputs:
installed-version:
description: Version that of the CLI that was installed on your runner.
description: Version of the CLI installed on your runner.
runs:
using: node20
main: dist/index.js
36 changes: 23 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28256,6 +28256,8 @@ const node_path_1 = __importDefault(__nccwpck_require__(6760));
const promises_1 = __nccwpck_require__(1943);
const fs_1 = __nccwpck_require__(9896);
const doExec = (0, node_util_1.promisify)(node_child_process_1.exec);
const currentBinaryName = 'postgres-language-server';
const legacyBinaryName = 'postgrestools';
const platformMappings = {
darwin: 'darwin',
linux: 'unknown-linux-gnu',
Expand Down Expand Up @@ -28310,21 +28312,29 @@ function getDownloadUrl(version, binary) {
}
function determineInstalledVersion() {
return __awaiter(this, void 0, void 0, function* () {
const { stdout } = yield doExec(`postgrestools --version`);
const version = stdout.trim();
if (!version) {
throw new Error('Could not determine installed PostgresTools version');
const binaries = [currentBinaryName, legacyBinaryName];
for (const binary of binaries) {
try {
const { stdout } = yield doExec(`${binary} --version`);
const version = stdout.trim();
if (version) {
return version;
}
}
catch (_a) {
continue;
}
}
return version;
throw new Error('Could not determine installed Postgres Language Server version');
});
}
function main() {
return __awaiter(this, void 0, void 0, function* () {
try {
const version = core.getInput('version', { required: true });
let url = getDownloadUrl(version, 'postgres-language-server');
let url = getDownloadUrl(version, currentBinaryName);
if (!(yield urlExists(url))) {
url = getDownloadUrl(version, 'postgrestools');
url = getDownloadUrl(version, legacyBinaryName);
}
const tool = yield toolCache.downloadTool(url);
yield (0, promises_1.chmod)(tool, '755');
Expand All @@ -28333,14 +28343,14 @@ function main() {
core.info(`Binary dir not found. Creating one at ${binDir}`);
yield (0, promises_1.mkdir)(binDir, { recursive: true });
}
const symlinkPath = node_path_1.default.join(binDir, 'postgrestools');
yield (0, promises_1.symlink)(tool, symlinkPath);
const binarySymlinkPath = node_path_1.default.join(binDir, currentBinaryName);
yield (0, promises_1.rm)(binarySymlinkPath, { force: true });
yield (0, promises_1.symlink)(tool, binarySymlinkPath);
const legacySymlinkPath = node_path_1.default.join(binDir, legacyBinaryName);
yield (0, promises_1.rm)(legacySymlinkPath, { force: true });
yield (0, promises_1.symlink)(tool, legacySymlinkPath);
core.info(`Adding to path: ${binDir}`);
core.addPath(binDir);
/**
* TODO: GH Runner still won't find the `postgrestools` binary
* The `tool` binary path works, however – seems to be something with symlink?
*/
const installedVersion = yield determineInstalledVersion();
core.setOutput('installed-version', installedVersion);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "postgrestools-cli-action",
"name": "postgres-language-server-cli-action",
"version": "0.0.1",
"description": "Installs the PostgresTools Cli on your Github Action Runner.",
"description": "Installs the Postgres Language Server CLI on your GitHub Actions runner.",
"main": "dist/index.js",
"scripts": {
"build": "ncc build --source-map --license license.txt src/index.ts -o dist",
Expand All @@ -15,7 +15,7 @@
"keywords": ["actions", "node", "setup", "postgres", "sql", "lsp"],
"repository": {
"type": "git",
"url": "git+https://github.com/supabase-community/pglt-cli-action.git"
"url": "git+https://github.com/supabase-community/postgres-language-server-cli-action.git"
},
"author": "Supabase Community",
"contributors": [
Expand Down
44 changes: 29 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import { exec } from 'node:child_process'
import { promisify } from 'node:util'
import os from 'node:os'
import path from 'node:path'
import { mkdir, symlink, chmod } from 'fs/promises'
import { chmod, mkdir, rm, symlink } from 'fs/promises'
import { existsSync } from 'fs'

const doExec = promisify(exec)

const currentBinaryName = 'postgres-language-server'
const legacyBinaryName = 'postgrestools'

const platformMappings = {
darwin: 'darwin',
linux: 'unknown-linux-gnu',
Expand Down Expand Up @@ -75,23 +78,33 @@ function getDownloadUrl(version: string, binary: string): string {
}

async function determineInstalledVersion(): Promise<string> {
const { stdout } = await doExec(`postgrestools --version`)

const version = stdout.trim()
if (!version) {
throw new Error('Could not determine installed PostgresTools version')
const binaries = [currentBinaryName, legacyBinaryName]

for (const binary of binaries) {
try {
const { stdout } = await doExec(`${binary} --version`)
const version = stdout.trim()

if (version) {
return version
}
} catch {
continue
}
}

return version
throw new Error(
'Could not determine installed Postgres Language Server version'
)
}

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

let url = getDownloadUrl(version, 'postgres-language-server')
let url = getDownloadUrl(version, currentBinaryName)
if (!(await urlExists(url))) {
url = getDownloadUrl(version, 'postgrestools')
url = getDownloadUrl(version, legacyBinaryName)
}

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

const symlinkPath = path.join(binDir, 'postgrestools')
await symlink(tool, symlinkPath)
const binarySymlinkPath = path.join(binDir, currentBinaryName)
await rm(binarySymlinkPath, { force: true })
await symlink(tool, binarySymlinkPath)

const legacySymlinkPath = path.join(binDir, legacyBinaryName)
await rm(legacySymlinkPath, { force: true })
await symlink(tool, legacySymlinkPath)

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

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