Skip to content

[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
Show file tree
Hide file tree
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 Feb 21, 2025
a9f36e7
don't have that yet
juleswritescode Feb 21, 2025
3e24df4
copy that schema
juleswritescode Feb 21, 2025
4afd792
add thangs
juleswritescode Feb 21, 2025
125f8fc
ok?
juleswritescode Feb 21, 2025
6baf503
trim names
juleswritescode Feb 21, 2025
6b0aa3d
debug thing
juleswritescode Feb 21, 2025
eaf3097
ok?
juleswritescode Feb 21, 2025
0ce8fa3
changy change
juleswritescode Feb 21, 2025
f63de17
like so?
juleswritescode Feb 21, 2025
d7cf708
make it test
juleswritescode Feb 21, 2025
dbe1924
well
juleswritescode Feb 21, 2025
9e3e092
thats not a valid alias
juleswritescode Feb 21, 2025
711fb48
use pipes
juleswritescode Feb 21, 2025
f4abd92
rework
juleswritescode Feb 21, 2025
38e30cf
ocd
juleswritescode Feb 21, 2025
584c67a
wrong platform name
juleswritescode Feb 21, 2025
ebd6760
debug
juleswritescode Feb 21, 2025
c698b4c
well...
juleswritescode Feb 21, 2025
10d0822
more sexy
juleswritescode Feb 21, 2025
92c9658
thats not an underscore
juleswritescode Feb 21, 2025
348dfaf
schema src
juleswritescode Feb 21, 2025
d436948
escape?
juleswritescode Feb 21, 2025
a1607c5
cleanup
juleswritescode Feb 21, 2025
c3b03b2
herantasten
juleswritescode Feb 21, 2025
bbde5f7
these underscores dang
juleswritescode Feb 21, 2025
29e9dbd
it apparently works
juleswritescode Feb 21, 2025
9250363
restructure
juleswritescode Feb 21, 2025
7a4f004
ls that stuff
juleswritescode Feb 21, 2025
59bd643
cat instead
juleswritescode Feb 21, 2025
7aed7f4
this the script?
juleswritescode Feb 21, 2025
5bf5a70
desc
juleswritescode Feb 21, 2025
9d190c7
prepwork
juleswritescode Feb 21, 2025
82cf431
improve left & right
juleswritescode Feb 21, 2025
ee914d7
test-release name
juleswritescode Feb 21, 2025
72499a5
?
juleswritescode Feb 21, 2025
0661574
ok
juleswritescode Feb 21, 2025
ea97ad8
ack
juleswritescode Feb 21, 2025
78be9bf
another
juleswritescode Feb 21, 2025
d920fc9
verify
juleswritescode Feb 21, 2025
099350c
ok
juleswritescode Feb 21, 2025
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
53 changes: 53 additions & 0 deletions .github/workflows/publish.yml
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 }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
fail_on_unmatched_files: true
draft: true

- name: ✅ Output Link to Worflow Summary
- name: ✅ Output Link to Workflow Summary
run: |
{
echo "# 🚀 Release completed!"
Expand Down
36 changes: 36 additions & 0 deletions packages/@pglt/pglt/package.json
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"
}
}
182 changes: 182 additions & 0 deletions packages/@pglt/pglt/scripts/generate-packages.mjs
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);
})();
1 change: 1 addition & 0 deletions packages/@pglt/pglt_aarch64-apple-darwin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/@pglt/pglt_aarch64-pc-windows-msvc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/@pglt/pglt_aarch64-unknown-linux-gnu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/@pglt/pglt_x86_64-apple-darwin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/@pglt/pglt_x86_64-pc-windows-msvc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions packages/@pglt/pglt_x86_64-unknown-linux-gnu/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}