Skip to content

Commit 324ddbe

Browse files
authored
Merge pull request #253 from ryoppippi/feature/248
feat: Add npm publishing workflow
2 parents c7d9dfc + 217ebd5 commit 324ddbe

File tree

6 files changed

+307
-2
lines changed

6 files changed

+307
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ on:
44
push:
55
pull_request:
66

7+
env:
8+
DENO_VERSION: 1.x
9+
NODE_VERSION: 20.x
10+
711
permissions:
812
contents: read
913
pull-requests: write
@@ -14,6 +18,8 @@ jobs:
1418
steps:
1519
- uses: actions/checkout@v4
1620
- uses: denoland/setup-deno@v1
21+
with:
22+
deno-version: ${{ env.DENO_VERSION }}
1723
- run: deno lint
1824
- name: Test
1925
run: |
@@ -35,8 +41,30 @@ jobs:
3541
steps:
3642
- uses: actions/checkout@v4
3743
- uses: denoland/setup-deno@v1
44+
with:
45+
deno-version: ${{ env.DENO_VERSION }}
3846
- run: deno publish --dry-run
3947

48+
npm-publish-dry-run:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
with:
53+
fetch-depth: 0
54+
- uses: denoland/setup-deno@v1
55+
with:
56+
deno-version: ${{ env.DENO_VERSION }}
57+
- uses: oven-sh/setup-bun@v1
58+
with:
59+
bun-version: latest
60+
- uses: actions/setup-node@v4
61+
with:
62+
node-version: ${{ env.NODE_VERSION }}
63+
registry-url: "https://registry.npmjs.org"
64+
- run: deno task build-npm
65+
- run: |
66+
cd npm
67+
npm publish --dry-run
4068
4169
action-timeline:
4270
needs:

.github/workflows/npm.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: npm
2+
3+
env:
4+
DENO_VERSION: 1.x
5+
NODE_VERSION: 20.x
6+
7+
on:
8+
push:
9+
tags:
10+
- "*"
11+
12+
jobs:
13+
publish:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
- uses: denoland/setup-deno@v1
20+
- uses: oven-sh/setup-bun@v1
21+
with:
22+
bun-version: latest
23+
- uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ env.NODE_VERSION }}
26+
registry-url: "https://registry.npmjs.org"
27+
- name: Build
28+
run: deno task build-npm
29+
- name: Publish
30+
run: |
31+
cd npm
32+
npm publish
33+
env:
34+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/node_modules
33
/types
44
/coverage
5+
/npm

deno.jsonc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
"imports": {
99
"type-fest": "npm:type-fest@4.15.0",
1010
"assert": "jsr:@std/assert@0.222.1",
11-
"type-testing": "jsr:@std/testing@0.222.1/types"
11+
"type-testing": "jsr:@std/testing@0.222.1/types",
12+
"@deno/dnt": "jsr:@deno/dnt@^0.41.1"
1213
},
1314
"tasks": {
1415
"dev": "deno run --watch ./src/index.ts",
1516
"check": "deno check ./**/*.ts",
1617
"test": "deno test -A --parallel --doc",
1718
"test:coverage": "deno task test --coverage=coverage",
1819
"coverage:show": "deno coverage ./coverage",
19-
"coverage:lco": "deno coverage --lcov ./coverage > ./coverage/lcov.info"
20+
"coverage:lco": "deno coverage --lcov ./coverage > ./coverage/lcov.info",
21+
"build-npm": "deno run -A scripts/build_npm.ts $(git describe --tags --always --dirty)"
2022
},
2123
"fmt": {
2224
"exclude": [

deno.lock

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

scripts/build_npm.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { build, emptyDir } from "@deno/dnt";
2+
3+
const name = "str-fns";
4+
const version = Deno.args[0];
5+
if (!version) {
6+
throw new Error("No version argument is specified");
7+
}
8+
console.log("*".repeat(80));
9+
console.log(`${name} ${version}`);
10+
console.log("*".repeat(80));
11+
12+
await emptyDir("./npm");
13+
14+
await build({
15+
typeCheck: false,
16+
test: false,
17+
entryPoints: ["src/index.ts"],
18+
outDir: "./npm",
19+
shims: {
20+
deno: "dev",
21+
},
22+
packageManager: "bun",
23+
package: {
24+
name,
25+
version,
26+
author: "@ryoppippi",
27+
license: "MIT",
28+
repository: "ryoppippi/str-fns",
29+
},
30+
});
31+
32+
// post build steps
33+
Deno.copyFileSync("LICENSE", "npm/LICENSE");
34+
Deno.copyFileSync("README.md", "npm/README.md");

0 commit comments

Comments
 (0)