Skip to content

Commit 80a339a

Browse files
chore: add publish npm action (#217)
* chore: add publish npm action * don't have that yet * copy that schema * add thangs * ok? * trim names * debug thing * ok? * changy change * like so? * make it test * well * thats not a valid alias * use pipes * rework * ocd * wrong platform name * debug * well... * more sexy * thats not an underscore * schema src * escape? * cleanup * herantasten * these underscores dang * it apparently works * restructure * ls that stuff * cat instead * this the script? * desc * prepwork * improve left & right * test-release name * ? * ok * ack * another * verify * ok * test * workaround * no * try github * camels everywhere * await that * works * log * axiosga .! * no infinite * sanity * ok * better check * stringify * stringify * change for test * pieced together * permissions * fix * update msg * trim? * log package * path wrong? * classic * test name * huh * name * print package.json * test 3 * ah yes... * no scope * test5 * adjust that * test 6 * test 6 * add bin * test 7 * remove placeholders * publishconfig * hm * release 8 * binary file * hm * release 9 * nightly test * string * nightly2 test * sweet lord! * ok * name change * already caught two
1 parent 06466ac commit 80a339a

File tree

7 files changed

+487
-1
lines changed

7 files changed

+487
-1
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish NPM (Manual)
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
release-tag:
7+
type: string
8+
required: true
9+
description: Release Tag to Publish
10+
11+
jobs:
12+
validate_tag:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
is-prerelease: ${{ steps.validate-release.outputs.is-prerelease }}
16+
steps:
17+
- uses: actions/github-script@v7
18+
id: validate-release
19+
with:
20+
script: |
21+
/** the "core" module does not have access to workflow_dispatch inputs */
22+
const tag = '${{ inputs.release-tag }}';
23+
24+
/** Releases don't have a guaranteed order, so we'll have to paginate */
25+
let exhausted = false;
26+
let page = 1;
27+
while (!exhausted) {
28+
const releases = await github.rest.repos.listReleases({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
page,
32+
per_page: 100,
33+
}).then(r => r.data);
34+
35+
const matchingRelease = releases.find(r => r.tag_name === tag);
36+
if (matchingRelease) {
37+
core.setOutput('has-release', 'true');
38+
core.setOutput('is-prerelease', matchingRelease.prerelease.toString());
39+
return;
40+
}
41+
42+
if (releases.length < 100) {
43+
exhausted = true;
44+
} else if (page >= 10) {
45+
throw new Error("We iterated over 10 pages. Does the script work?");
46+
} else {
47+
page++
48+
}
49+
50+
}
51+
52+
core.setOutput('has-release', 'false');
53+
core.setOutput('is-prerelease', 'false');
54+
55+
- name: Abort
56+
if: steps.validate-release.outputs.has-release != 'true'
57+
run: |
58+
{
59+
echo "Tag ${{ github.event.inputs.release_tag }} not found."
60+
exit 1
61+
}
62+
63+
publish_npm:
64+
needs: validate_tag
65+
uses: ./.github/workflows/publish.reusable.yml
66+
permissions:
67+
contents: write
68+
id-token: write
69+
with:
70+
release-tag: ${{ github.event.inputs.release-tag }}
71+
is-prerelease: ${{ needs.validate_tag.outputs.is-prerelease }}
72+
secrets: inherit
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Publish to NPM & Brew
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
release-tag:
7+
type: string
8+
required: true
9+
is-prerelease:
10+
type: string
11+
required: true
12+
default: "false"
13+
14+
jobs:
15+
publish:
16+
name: Publish All the Things
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
# ? what's this?! required for executing the node script?
21+
id-token: write
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- name: Install Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: lts/*
29+
registry-url: "https://registry.npmjs.org"
30+
31+
- name: Generate Packages
32+
id: generate-packages
33+
run: node packages/@pglt/pglt/scripts/generate-packages.mjs
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
RELEASE_TAG: ${{ inputs.release-tag }}
37+
PRERELEASE: ${{ inputs.is-prerelease }}
38+
39+
- name: Verify NPM TOKEN exists
40+
run: |
41+
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
42+
echo "Secret is not defined"
43+
exit 1
44+
else
45+
echo "Secret is defined"
46+
fi
47+
48+
- name: Print package.json
49+
run: |
50+
cat packages/@pglt/pglt/package.json
51+
52+
- name: Publish npm packages as nightly
53+
if: inputs.is-prerelease == 'true'
54+
run: |
55+
for package in packages/@pglt/*; do
56+
npm publish $package --tag nightly --access public --provenance
57+
done
58+
env:
59+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} #
60+
61+
- name: Publish npm packages as latest
62+
if: inputs.is-prerelease != 'true'
63+
run: |
64+
for package in packages/@pglt/*; do
65+
npm publish $package --tag latest --access public --provenance
66+
done
67+
env:
68+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish.trigger.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish NPM (Automatic)
2+
3+
on:
4+
release:
5+
types: [released, prereleased]
6+
7+
jobs:
8+
publish_npm:
9+
uses: ./.github/workflows/publish.reusable.yml
10+
permissions:
11+
contents: write
12+
id-token: write
13+
with:
14+
release-tag: ${{ github.event.release.tag_name }}
15+
is-prerelease: ${{ github.event.release.prerelease }}
16+
secrets: inherit

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
fail_on_unmatched_files: true
131131
draft: true
132132

133-
- name: ✅ Output Link to Worflow Summary
133+
- name: ✅ Output Link to Workflow Summary
134134
run: |
135135
{
136136
echo "# 🚀 Release completed!"

packages/@pglt/pglt/bin/pglt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env node
2+
const { platform, arch, env } = process;
3+
4+
/**
5+
* platform and arch are values injected into the node runtime.
6+
* We use the values documented on https://nodejs.org.
7+
*/
8+
const PLATFORMS = {
9+
win32: {
10+
x64: "pglt-x86_64-windows-msvc/pglt.exe",
11+
arm64: "pglt-aarch64-windows-msvc/pglt.exe",
12+
},
13+
darwin: {
14+
x64: "pglt-x86_64-apple-darwin/pglt",
15+
arm64: "pglt-aarch64-apple-darwin/pglt",
16+
},
17+
linux: {
18+
x64: "pglt-x86_64-linux-gnu/pglt",
19+
arm64: "pglt-aarch64-linux-gnu/pglt",
20+
},
21+
};
22+
23+
const binPath = env.PGLT_BINARY || PLATFORMS?.[platform]?.[arch];
24+
25+
if (binPath) {
26+
const result = require("child_process").spawnSync(
27+
require.resolve(binPath),
28+
process.argv.slice(2),
29+
{
30+
shell: false,
31+
stdio: "inherit",
32+
env,
33+
}
34+
);
35+
36+
if (result.error) {
37+
throw result.error;
38+
}
39+
40+
process.exitCode = result.status;
41+
} else {
42+
console.error(
43+
"The pglt CLI package doesn't ship with prebuilt binaries for your platform yet. Please file an issue in the main repository."
44+
);
45+
process.exitCode = 1;
46+
}

packages/@pglt/pglt/package.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "pglt",
3+
"version": "<placeholder>",
4+
"bin": {
5+
"pglt": "bin/pglt"
6+
},
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/supabase-community/postgres_lsp.git",
10+
"directory": "packages/@pglt/pglt"
11+
},
12+
"author": "Supabase Community",
13+
"contributors": [
14+
{
15+
"name": "Philipp Steinrötter",
16+
"url": "https://github.com/psteinroe"
17+
},
18+
{
19+
"name": "Julian Domke",
20+
"url": "https://github.com/juleswritescode"
21+
}
22+
],
23+
"license": "MIT or Apache-2.0",
24+
"description": "A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling.",
25+
"files": [
26+
"bin/pglt",
27+
"schema.json"
28+
],
29+
"engines": {
30+
"node": ">=20"
31+
},
32+
"publishConfig": {
33+
"provenance": true
34+
},
35+
"optionalDependencies": {
36+
"pglt-x86_64-windows-msvc": "<placeholder>",
37+
"pglt-aarch64-windows-msvc": "<placeholder>",
38+
"pglt-x86_64-apple-darwin": "<placeholder>",
39+
"pglt-aarch64-apple-darwin": "<placeholder>",
40+
"pglt-x86_64-linux-gnu": "<placeholder>",
41+
"pglt-aarch64-linux-gnu": "<placeholder>"
42+
}
43+
}

0 commit comments

Comments
 (0)