-
Notifications
You must be signed in to change notification settings - Fork 102
[wip] chore: add publish npm action #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
juleswritescode
wants to merge
41
commits into
supabase-community:main
from
juleswritescode:chore/add-publish-action
Closed
Changes from 6 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
064b3f2
chore: add publish npm action
juleswritescode a9f36e7
don't have that yet
juleswritescode 3e24df4
copy that schema
juleswritescode 4afd792
add thangs
juleswritescode 125f8fc
ok?
juleswritescode 6baf503
trim names
juleswritescode 6b0aa3d
debug thing
juleswritescode eaf3097
ok?
juleswritescode 0ce8fa3
changy change
juleswritescode f63de17
like so?
juleswritescode d7cf708
make it test
juleswritescode dbe1924
well
juleswritescode 9e3e092
thats not a valid alias
juleswritescode 711fb48
use pipes
juleswritescode f4abd92
rework
juleswritescode 38e30cf
ocd
juleswritescode 584c67a
wrong platform name
juleswritescode ebd6760
debug
juleswritescode c698b4c
well...
juleswritescode 10d0822
more sexy
juleswritescode 92c9658
thats not an underscore
juleswritescode 348dfaf
schema src
juleswritescode d436948
escape?
juleswritescode a1607c5
cleanup
juleswritescode c3b03b2
herantasten
juleswritescode bbde5f7
these underscores dang
juleswritescode 29e9dbd
it apparently works
juleswritescode 9250363
restructure
juleswritescode 7a4f004
ls that stuff
juleswritescode 59bd643
cat instead
juleswritescode 7aed7f4
this the script?
juleswritescode 5bf5a70
desc
juleswritescode 9d190c7
prepwork
juleswritescode 82cf431
improve left & right
juleswritescode ee914d7
test-release name
juleswritescode 72499a5
?
juleswritescode 0661574
ok
juleswritescode ea97ad8
ack
juleswritescode 78be9bf
another
juleswritescode d920fc9
verify
juleswritescode 099350c
ok
juleswritescode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Publish to NPM & Brew | ||
|
||
on: | ||
workflow_dispatch: | ||
release: | ||
types: [released] | ||
|
||
jobs: | ||
get_release_tag: | ||
name: Get Latest Release Tag | ||
runs-on: ubuntu-latest | ||
outputs: | ||
tagName: ${{ steps.get-tag-name.outputs.result }} | ||
steps: | ||
- uses: actions/github-script@v7 | ||
id: get-tag-name | ||
with: | ||
# result-encoding: string | ||
retries: 3 | ||
script: | | ||
const release = octokit.rest.repos.getLatestRelease({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
}); | ||
|
||
return { | ||
tagName: release.tag_name, | ||
assetsUrl: release.assets_url, | ||
} | ||
|
||
publish: | ||
name: Publish All the Things | ||
needs: get_release_tag | ||
runs-on: ubuntu-latest | ||
# todo: add secrets | ||
permissions: | ||
contents: write | ||
# ? what's this?! required for executing the node script? | ||
id-token: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Install Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: lts | ||
registry-url: "https://registry.npmjs.org" | ||
- name: Generate Packages | ||
run: node //todo | ||
|
||
- name: Publish npm packages as latest | ||
run: for package in packages/@biomejs/*; do if [ $package != "packages/@biomejs/js-api" ]; then npm publish $package --tag latest --access public --provenance; fi; done | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "pglt", | ||
"version": "0.1.0", | ||
"bin": { | ||
"pglt": "bin/pglt" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/supabase/postgres_lsp.git", | ||
"directory": "packages/@pglt/pglt" | ||
}, | ||
"author": "Philipp Steinrötter", | ||
"contributors": [ | ||
{ | ||
"name": "Julian Domke", | ||
"url": "https://github.com/juleswritescode" | ||
} | ||
], | ||
"license": "MIT or Apache-2.0", | ||
"description": "", | ||
"files": [ | ||
"bin/pglt", | ||
"schema.json" | ||
], | ||
"engines": { | ||
"node": ">=20" | ||
}, | ||
"optionalDependencies": { | ||
"@pglt/cli-aarch64-apple-darwin": "0.1.0", | ||
"@pglt/cli-aarch64-windows-msvc": "0.1.0", | ||
"@pglt/cli-aarch64-linux-gnu": "0.1.0", | ||
"@pglt/cli-x86_64-apple-darwin": "0.1.0", | ||
"@pglt/cli-x86_64-windows-msvc": "0.1.0", | ||
"@pglt/cli-x86_64-linux-gnu": "0.1.0" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
import assert from "node:assert"; | ||
import * as fs from "node:fs"; | ||
import { resolve } from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
import { format } from "node:util"; | ||
|
||
const CLI_ROOT = resolve(fileURLToPath(import.meta.url), "../.."); | ||
const PACKAGES_PGLT_ROOT = resolve(CLI_ROOT, ".."); | ||
const PGLT_ROOT = resolve(PACKAGES_PGLT_ROOT, "../.."); | ||
const MANIFEST_PATH = resolve(CLI_ROOT, "package.json"); | ||
|
||
async function downloadSchema(releaseTag, githubToken) { | ||
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${releaseTag}/schema.json`; | ||
|
||
const response = await fetch(assetUrl, { | ||
headers: { | ||
Authorization: `token ${githubToken}`, | ||
Accept: `application/octet-stream`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to Fetch Asset from ${assetUrl}`); | ||
} | ||
|
||
// download to root. | ||
const fileStream = fs.createWriteStream(resolve(PGLT_ROOT, "schema.json")); | ||
|
||
await new Promise((res, rej) => { | ||
response.body.pipeTo(fileStream); | ||
fileStream.on("error", rej); | ||
fileStream.on("finish", res); | ||
}); | ||
|
||
console.log(`Downloaded schema for ${releaseTag}`); | ||
} | ||
|
||
async function downloadAsset(platform, os, arch, releaseTag, githubToken) { | ||
const buildName = getBuildName(platform, arch); | ||
const assetUrl = `https://github.com/supabase-community/postgres_lsp/releases/download/${releaseTag}/${buildName}`; | ||
|
||
const response = await fetch(assetUrl, { | ||
headers: { | ||
Authorization: `token ${githubToken}`, | ||
Accept: `application/octet-stream`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to Fetch Asset from ${assetUrl}`); | ||
} | ||
|
||
// just download to root. | ||
const fileStream = fs.createWriteStream(getBinarySource(os, platform, arch)); | ||
|
||
await new Promise((res, rej) => { | ||
response.body.pipeTo(fileStream); | ||
fileStream.on("error", rej); | ||
fileStream.on("finish", res); | ||
}); | ||
|
||
console.log(`Downloaded asset for ${buildName} (v${releaseTag})`); | ||
} | ||
|
||
const rootManifest = JSON.parse( | ||
fs.readFileSync(MANIFEST_PATH).toString("utf-8") | ||
); | ||
|
||
function getBinaryExt(os) { | ||
return os === "windows" ? ".exe" : ""; | ||
} | ||
|
||
function getBinarySource(os, platform, arch) { | ||
const ext = getBinaryExt(os); | ||
return resolve(PGLT_ROOT, `${getBuildName(platform, arch)}${ext}`); | ||
} | ||
|
||
function getBuildName(platform, arch) { | ||
return format(`pglt_${arch}_${platform}`, arch); | ||
} | ||
|
||
function getPackageName(platform, arch) { | ||
// trim the "unknown" from linux | ||
const name = platform.split("-").slice(-2).join("-"); | ||
return format(`@pglt/cli_${name}`, arch); | ||
} | ||
|
||
function copyBinaryToNativePackage(platform, arch) { | ||
const buildName = getBuildName(platform, arch); | ||
const packageRoot = resolve(PACKAGES_PGLT_ROOT, buildName); | ||
const packageName = getPackageName(platform, arch); | ||
|
||
// "unknow-linux-gnu", "apple-darwin" – take linux, apple, windows | ||
const os = platform.split("-").find((_, idx) => idx === 1); | ||
|
||
// Update the package.json manifest | ||
const { version, license, repository, engines } = rootManifest; | ||
|
||
const manifest = JSON.stringify( | ||
{ | ||
name: packageName, | ||
version, | ||
license, | ||
repository, | ||
engines, | ||
os: [os], | ||
cpu: [arch], | ||
libc: (() => { | ||
switch (os) { | ||
case "linux": | ||
return "gnu"; | ||
case "windows": | ||
return "msvc"; | ||
default: | ||
return undefined; | ||
} | ||
})(), | ||
}, | ||
null, | ||
2 | ||
); | ||
|
||
const manifestPath = resolve(packageRoot, "package.json"); | ||
console.info(`Update manifest ${manifestPath}`); | ||
fs.writeFileSync(manifestPath, manifest); | ||
|
||
// Copy the CLI binary | ||
const binarySource = getBinarySource(os, platform, arch); | ||
const ext = getBinaryExt(os); | ||
const binaryTarget = resolve(packageRoot, `pglt${ext}`); | ||
|
||
if (!fs.existsSync(binarySource)) { | ||
console.error( | ||
`Source for binary for ${buildName} not found at: ${binarySource}` | ||
); | ||
process.exit(1); | ||
} | ||
|
||
console.info(`Copy binary ${binaryTarget}`); | ||
fs.copyFileSync(binarySource, binaryTarget); | ||
fs.chmodSync(binaryTarget, 0o755); | ||
} | ||
|
||
function copySchemaToNativePackage(platform, arch) { | ||
const buildName = getBuildName(platform, arch); | ||
const packageRoot = resolve(PACKAGES_PGLT_ROOT, buildName); | ||
|
||
const schemaSrc = resolve(packageRoot, `schema.json`); | ||
const schemaTarget = resolve(packageRoot, `schema.json`); | ||
|
||
if (!fs.existsSync(schemaSrc)) { | ||
console.error(`Schema.json not found at: ${schemaSrc}`); | ||
process.exit(1); | ||
} | ||
|
||
console.info(`Copying schema.json`); | ||
fs.copyFileSync(schemaSrc, schemaTarget); | ||
fs.chmodSync(schemaTarget, 0o666); | ||
} | ||
|
||
(async function main() { | ||
const githubToken = process.env.GITHUB_TOKEN; | ||
const releaseTag = process.env.RELEASE_TAG; | ||
|
||
assert(githubToken, "GITHUB_TOKEN not defined!"); | ||
assert(releaseTag, "RELEASE_TAG not defined!"); | ||
|
||
await downloadSchema(releaseTag, githubToken); | ||
|
||
const PLATFORMS = ["windows-msvc", "apple-darwin", "unknown-linux-gnu"]; | ||
const ARCHITECTURES = ["x86_64", "aarch64"]; | ||
|
||
for (const platform of PLATFORMS) { | ||
for (const arch of ARCHITECTURES) { | ||
await downloadAsset(platform, os, arch, releaseTag, githubToken); | ||
copyBinaryToNativePackage(platform, arch); | ||
copySchemaToNativePackage(platform, arch); | ||
} | ||
} | ||
|
||
process.exit(0); | ||
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.