Skip to content

Commit 031b241

Browse files
authored
Merge pull request #14 from typetorch/ci/npm-publish
CI on every PR, npm publish from a version tag; 0.10.4
2 parents 08dc817 + f697086 commit 031b241

7 files changed

Lines changed: 119 additions & 4 deletions

File tree

‎.github/actions/setup/action.yml‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Setup
2+
description: Bun, Node, Lune and Rojo (the luau engine and backup tests run Lune and Rojo), and the dependencies.
3+
runs:
4+
using: composite
5+
steps:
6+
- uses: oven-sh/setup-bun@v2
7+
with:
8+
bun-version: 1.4.2
9+
- uses: actions/setup-node@v4
10+
with:
11+
node-version: 22
12+
registry-url: https://registry.npmjs.org
13+
- name: Lune and Rojo
14+
shell: bash
15+
run: |
16+
set -euo pipefail
17+
tools="$RUNNER_TEMP/tools"
18+
mkdir -p "$tools"
19+
curl -sSLf -o "$tools/lune.zip" https://github.com/lune-org/lune/releases/download/v0.10.5/lune-0.10.5-linux-x86_64.zip
20+
curl -sSLf -o "$tools/rojo.zip" https://github.com/rojo-rbx/rojo/releases/download/v7.6.1/rojo-7.6.1-linux-x86_64.zip
21+
unzip -oq "$tools/lune.zip" -d "$tools"
22+
unzip -oq "$tools/rojo.zip" -d "$tools"
23+
chmod +x "$tools/lune" "$tools/rojo"
24+
echo "$tools" >> "$GITHUB_PATH"
25+
"$tools/lune" --version
26+
"$tools/rojo" --version
27+
- name: Dependencies
28+
shell: bash
29+
run: bun install --frozen-lockfile

‎.github/workflows/ci.yml‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Typecheck, tests (Lune and Rojo included, so nothing skips), the build and the pack smoke test under Node.
2+
name: CI
3+
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: ./.github/actions/setup
18+
- run: bun run typecheck
19+
- run: bun test
20+
- run: bun run build
21+
- run: node scripts/smoke.mjs --pack

‎.github/workflows/publish.yml‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Publishes @typetorch/cli to npm when a version tag is pushed:
2+
# npm version <x.y.z> -m "release %s" && git push origin main --follow-tags
3+
# The tag must match package.json. `npm publish` runs prepublishOnly (build, bun test, pack smoke test) first, and
4+
# publishes with provenance. Auth: npm trusted publishing (OIDC; set this repo and workflow as a trusted publisher of
5+
# @typetorch/cli on npmjs.com), or an NPM_TOKEN repository secret (an automation token) until that is set up.
6+
# A prerelease version (0.11.0-next.0) goes to the "next" dist-tag; anything else to "latest".
7+
name: Publish
8+
9+
on:
10+
push:
11+
tags: ["v*"]
12+
13+
permissions:
14+
contents: write # the GitHub release
15+
id-token: write # npm provenance and trusted publishing
16+
17+
concurrency:
18+
group: publish
19+
cancel-in-progress: false
20+
21+
jobs:
22+
publish:
23+
runs-on: ubuntu-latest
24+
environment: npm
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: ./.github/actions/setup
28+
- name: npm 11.5+ (trusted publishing)
29+
run: npm install -g npm@^11.5.1
30+
- name: The tag, package.json and npm agree
31+
id: version
32+
run: |
33+
set -euo pipefail
34+
version=$(node -p "require('./package.json').version")
35+
name=$(node -p "require('./package.json').name")
36+
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
37+
echo "::error::tag ${GITHUB_REF_NAME} but package.json is ${version}"
38+
exit 1
39+
fi
40+
if npm view "${name}@${version}" version >/dev/null 2>&1; then
41+
echo "::error::${name}@${version} is already on npm"
42+
exit 1
43+
fi
44+
tag=latest
45+
case "$version" in *-*) tag=next ;; esac
46+
echo "version=${version}" >> "$GITHUB_OUTPUT"
47+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
48+
- name: Publish
49+
run: npm publish --provenance --access public --tag "${{ steps.version.outputs.tag }}"
50+
env:
51+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
52+
- name: GitHub release
53+
run: gh release create "${GITHUB_REF_NAME}" --title "${GITHUB_REF_NAME}" --generate-notes ${{ steps.version.outputs.tag == 'next' && '--prerelease' || '' }}
54+
env:
55+
GH_TOKEN: ${{ github.token }}

‎README.md‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,12 @@ processes, PATH lookup, Windows `.cmd` scripts (Node won't spawn them directly:
762762
node; any other `.cmd` goes through cmd.exe with every argument quoted and escaped, and arguments with a double quote
763763
or a line break are refused), sleep and zstd live in `src/runtime.ts`, on Node's own modules. The build compiles with
764764
`types: ["node"]`, so a Bun global in `src/` doesn't compile. `prepublishOnly` runs the build, `bun test` and the
765-
pack smoke test; publishing is done by hand (`npm publish`, 2FA).
765+
pack smoke test. Releases go out from GitHub Actions (`.github/workflows/publish.yml`): bump and tag on main with
766+
`npm version <x.y.z> -m "release %s" && git push origin main --follow-tags`, and the tag's workflow checks that it
767+
matches package.json, publishes with provenance (a `-pre` version to the `next` dist-tag) and makes the GitHub release.
768+
npm auth is trusted publishing (this repo and `publish.yml` as a trusted publisher of @typetorch/cli on npmjs.com) or an
769+
`NPM_TOKEN` repository secret. `.github/workflows/ci.yml` runs the typecheck, `bun test` (with Lune and Rojo), the build
770+
and the pack smoke test on every push to main and every PR.
766771

767772
`bun run compile` builds a single binary (`release/typetorch`).
768773

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typetorch/cli",
3-
"version": "0.10.3",
3+
"version": "0.10.4",
44
"description": "TypeTorch CLI: build, upload and hot-swap roblox-ts game code on live Roblox servers, roll back, and list deployments.",
55
"license": "MIT",
66
"repository": {

‎scripts/smoke.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,10 @@ if (process.argv.includes("--pack")) {
173173
check("packed files: dist + README + LICENSE + package.json only", bad.length === 0, bad.join(", "));
174174
const user = userInfo().username;
175175
const home = homedir();
176+
// A generic account (CI's "runner", a container's "root") is an ordinary word in the sources, not a leak.
177+
const genericUser = /^(root|runner|user|admin|ubuntu|node)$/i.test(user);
176178
const hard = [
177-
{ what: "this machine's user name", re: new RegExp(`(^|[^a-z0-9])${user.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i") },
179+
...(genericUser ? [] : [{ what: "this machine's user name", re: new RegExp(`(^|[^a-z0-9])${user.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^a-z0-9]|$)`, "i") }]),
178180
{ what: "the home folder", re: new RegExp(home.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/\\\\/g, "[\\\\/]+"), "i") },
179181
{ what: "a Windows user folder", re: /[A-Za-z]:[\\/]+Users[\\/]+(?!<|\{|\$|%|\*|\.\.\.)[\w.-]+/ },
180182
{ what: "a macOS/Linux user folder", re: /(?<![\w.])\/(?:Users|home)\/(?!<|\{|\$|\*|\.\.\.)[a-z][\w.-]+/ },

‎src/keyfiles.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ export interface KeyFileInfo {
5252
createdAt: string;
5353
}
5454

55+
/** The home folder as the environment says now (Node's homedir() does; Bun's keeps the value from startup). */
56+
const home = () => (process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME) || homedir();
57+
5558
export function defaultKeyFile(universeId: number, role: KeyRole): string {
56-
return join(homedir(), ".config", "typetorch", "keys", role === "main" ? `${universeId}.key` : `${universeId}.fallback.key`);
59+
return join(home(), ".config", "typetorch", "keys", role === "main" ? `${universeId}.key` : `${universeId}.fallback.key`);
5760
}
5861

5962
/** A key-path variable from the real environment only (not from an env file, not from a .env Bun loaded). */

0 commit comments

Comments
 (0)