Skip to content

Commit 3bf3bab

Browse files
init commit
0 parents  commit 3bf3bab

File tree

9 files changed

+275
-0
lines changed

9 files changed

+275
-0
lines changed

.eslintignore

Whitespace-only changes.

.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": ["plugin:github/recommended"],
3+
"env": {
4+
"node": true,
5+
"es6": true
6+
}
7+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env*
2+
node_modules/

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 80,
3+
"tabWidth": 2,
4+
"singleQuote": true,
5+
"trailingComma": "none",
6+
"semi": false
7+
}

package-lock.json

Lines changed: 131 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "postgres_lsp_gh_action",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"engines": {
9+
"node": ">=20.5 <23"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"description": "",
15+
"devDependencies": {
16+
"@types/node": "22.13.5",
17+
"typescript": "5.7.3"
18+
},
19+
"dependencies": {
20+
"@actions/core": "1.11.1",
21+
"@actions/tool-cache": "2.0.2"
22+
}
23+
}

src/install.ts

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import * as core from '@actions/core'
2+
import * as toolCache from '@actions/tool-cache'
3+
import { exec } from 'node:child_process'
4+
import { promisify } from 'node:util'
5+
import os from 'node:os'
6+
7+
const doExec = promisify(exec)
8+
9+
main().then(() => process.exit(0))
10+
async function main() {
11+
try {
12+
const version = core.getInput('version', { required: true })
13+
14+
const url = getDownloadUrl(version)
15+
const tool = await toolCache.downloadTool(url)
16+
core.addPath(tool)
17+
18+
const installedVersion = await determineInstalledVersion()
19+
core.setOutput('installed-version', installedVersion)
20+
} catch (err) {
21+
if (err instanceof Error) {
22+
core.setFailed(err.message)
23+
}
24+
}
25+
}
26+
27+
const archMappings = {
28+
arm64: 'aarch64',
29+
x64: 'x86_64'
30+
}
31+
32+
function getArch() {
33+
const arch = os.arch()
34+
for (const [nodeArch, rustArch] of Object.entries(archMappings)) {
35+
if (nodeArch === arch) {
36+
return rustArch
37+
}
38+
}
39+
throw new Error(
40+
`Unsupported arch: ${arch}. We currently only support: ${Object.keys(
41+
archMappings
42+
).join(', ')}`
43+
)
44+
}
45+
46+
const platformMappings = {
47+
darwin: 'darwin',
48+
linux: 'linux-gnu',
49+
win32: 'windows-msvc'
50+
}
51+
52+
function getPlatform() {
53+
const platform = os.platform()
54+
for (const [nodePlatform, rustPlatform] of Object.entries(platformMappings)) {
55+
if (nodePlatform === platform) {
56+
return rustPlatform
57+
}
58+
}
59+
throw new Error(
60+
`Unsupported platform: ${platform}. We currently only support: ${Object.keys(
61+
platformMappings
62+
).join(', ')}`
63+
)
64+
}
65+
66+
function getFileName(): string {
67+
const platform = getPlatform()
68+
const arch = getArch()
69+
70+
return `plgt_${arch}-${platform}`
71+
}
72+
73+
function getDownloadUrl(version: string): string {
74+
const filename = getFileName()
75+
76+
if (version.toLowerCase() === 'latest') {
77+
return `https://github.com/supabase-community/postgres_lsp/releases/latest/download/${filename}`
78+
} else {
79+
return `https://github.com/supabase-community/postgres_lsp/releases/download/${version}/${filename}`
80+
}
81+
}
82+
83+
async function determineInstalledVersion(): Promise<string> {
84+
const { stdout } = await doExec('pglt --version')
85+
86+
const version = stdout.trim()
87+
if (!version) {
88+
throw new Error('Could not determine installed PGLT version')
89+
}
90+
91+
return version
92+
}

tsconfig.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES6",
4+
"module": "CommonJS",
5+
"rootDir": "./src",
6+
"strict": true,
7+
"noImplicitAny": true,
8+
"esModuleInterop": true
9+
},
10+
"exclude": ["node_modules", "dist"]
11+
}

0 commit comments

Comments
 (0)