Skip to content

Commit 3a0522f

Browse files
authored
feat: publish to jsr (#44)
1 parent ac357ea commit 3a0522f

File tree

16 files changed

+813
-106
lines changed

16 files changed

+813
-106
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ on:
55
push:
66
branches: [main]
77
tags:
8-
- '*'
8+
- "*"
99
jobs:
1010
test:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v3
14-
- uses: denoland/setup-deno@v1
15-
with:
16-
deno-version: 1.x
17-
- run: deno lint
18-
- run: deno fmt --check
19-
- run: deno check mod.ts tasks/publish_release.ts tasks/bump_deno_deps.ts github_actions.ts
13+
- uses: actions/checkout@v4
14+
- uses: denoland/setup-deno@v2
15+
with:
16+
deno-version: 2.x
17+
- run: deno lint
18+
- run: deno fmt --check
19+
- run: deno check
20+
jsr:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
id-token: write
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: denoland/setup-deno@v2
28+
- name: Publish to JSR on tag
29+
run: deno run -A jsr:@david/publish-on-tag@0.2.0

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright 2018-2023 the Deno authors
3+
Copyright 2018-2025 the Deno authors
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

cargo.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
1+
// Copyright 2018-2025 the Deno authors. All rights reserved. MIT license.
22

3-
import { $, PathRef } from "./deps.ts";
3+
import { $, type Path } from "@david/dax";
44

55
export interface CargoMetadata {
66
packages: CargoPackageMetadata[];
@@ -26,7 +26,9 @@ export interface CargoDependencyMetadata {
2626
kind: "dev" | null;
2727
}
2828

29-
export function getCargoMetadata(directory: PathRef | string) {
29+
export function getCargoMetadata(
30+
directory: Path | string,
31+
): Promise<CargoMetadata> {
3032
return $`cargo metadata --format-version 1`
3133
.cwd(directory)
3234
.json<CargoMetadata>();

crate.ts

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
1+
// Copyright 2018-2025 the Deno authors. All rights reserved. MIT license.
22

3-
import { $, dax, PathRef, semver } from "./deps.ts";
3+
import * as dax from "@david/dax";
4+
import { $, type Path } from "@david/dax";
5+
import * as semver from "@std/semver";
46
import type { Repo } from "./repo.ts";
5-
import { CargoDependencyMetadata, CargoPackageMetadata } from "./cargo.ts";
7+
import type { CargoDependencyMetadata, CargoPackageMetadata } from "./cargo.ts";
68
import { getCratesIoMetadata } from "./crates_io.ts";
79

810
export interface CrateDep {
@@ -24,28 +26,28 @@ export class Crate {
2426
this.#pkg = crateMetadata;
2527
}
2628

27-
get manifestPath() {
29+
get manifestPath(): Path {
2830
return $.path(this.#pkg.manifest_path);
2931
}
3032

31-
get folderPath() {
33+
get folderPath(): Path {
3234
return this.manifestPath.parentOrThrow();
3335
}
3436

35-
get name() {
37+
get name(): string {
3638
return this.#pkg.name;
3739
}
3840

39-
get version() {
41+
get version(): string {
4042
return this.#pkg.version;
4143
}
4244

43-
get dependencies() {
45+
get dependencies(): readonly CargoDependencyMetadata[] {
4446
return this.#pkg.dependencies as readonly CargoDependencyMetadata[];
4547
}
4648

4749
/** Prompts the user how they would like to patch and increments the version accordingly. */
48-
async promptAndIncrement() {
50+
async promptAndIncrement(): Promise<"patch" | "minor" | "major"> {
4951
const result = await this.promptAndTryIncrement();
5052
if (result == null) {
5153
throw new Error("No decision.");
@@ -54,7 +56,9 @@ export class Crate {
5456
}
5557

5658
/** Prompts the user how they would like to patch and increments the version accordingly. */
57-
async promptAndTryIncrement() {
59+
async promptAndTryIncrement(): Promise<
60+
"patch" | "minor" | "major" | undefined
61+
> {
5862
$.log(`${this.name} is on ${this.version}`);
5963
const versionIncrement = getVersionIncrement();
6064
if (versionIncrement != null) {
@@ -110,12 +114,14 @@ export class Crate {
110114
this.#updateManifestVersion(version);
111115
}
112116

113-
static async getLatestVersion(crateName: string) {
117+
static async getLatestVersion(
118+
crateName: string,
119+
): Promise<string | undefined> {
114120
return (await getCratesIoMetadata(crateName))?.crate.max_stable_version;
115121
}
116122

117123
/** Gets the latest version from crates.io or returns undefined if not exists. */
118-
getLatestVersion() {
124+
getLatestVersion(): Promise<string | undefined> {
119125
return Crate.getLatestVersion(this.name);
120126
}
121127

@@ -169,7 +175,7 @@ export class Crate {
169175
}
170176

171177
/** Gets all the descendant dependencies in the repository. */
172-
descendantDependenciesInRepo() {
178+
descendantDependenciesInRepo(): Crate[] {
173179
// try to maintain publish order.
174180
const crates = new Map<string, Crate>();
175181
const stack = [...this.immediateDependenciesInRepo()];
@@ -184,7 +190,7 @@ export class Crate {
184190
}
185191

186192
/** Gets the immediate child dependencies found in the repo. */
187-
immediateDependenciesInRepo() {
193+
immediateDependenciesInRepo(): CrateDep[] {
188194
const dependencies: CrateDep[] = [];
189195
for (const dependency of this.#pkg.dependencies) {
190196
const crate = this.repo.crates.find((c) => c.name === dependency.name);
@@ -199,17 +205,17 @@ export class Crate {
199205
}
200206

201207
/** Gets if published or not, returning undefined if it was never published. */
202-
async isPublished() {
208+
async isPublished(): Promise<boolean | undefined> {
203209
const cratesIoMetadata = await getCratesIoMetadata(this.name);
204210
if (cratesIoMetadata == null) {
205211
return undefined;
206212
}
207-
return cratesIoMetadata.versions.some((v) =>
213+
return cratesIoMetadata.versions.some((v: any) =>
208214
v.num === this.version.toString()
209215
);
210216
}
211217

212-
async publish(...additionalArgs: string[]) {
218+
async publish(...additionalArgs: string[]): Promise<boolean> {
213219
const isPublished = await this.isPublished();
214220
if (isPublished == null) {
215221
$.log(`Never published, so skipping ${this.name} ${this.version}`);
@@ -269,20 +275,20 @@ export class Crate {
269275
await this.command(cliArgs);
270276
}
271277

272-
command(command: string | string[]) {
278+
command(command: string | string[]): dax.CommandBuilder {
273279
return new dax.CommandBuilder()
274280
.command(command)
275281
.cwd(this.folderPath);
276282
}
277283

278284
#updateManifestFile(
279-
action: (filePath: PathRef, fileText: string) => string,
285+
action: (filePath: Path, fileText: string) => string,
280286
) {
281287
updateFileEnsureChange(this.manifestPath, action);
282288
}
283289

284290
#updateRootManifestFile(
285-
action: (filePath: PathRef, fileText: string) => string,
291+
action: (filePath: Path, fileText: string) => string,
286292
) {
287293
const rootManifestFilePath = this.repo.folderPath.join("Cargo.toml");
288294
if (
@@ -296,8 +302,8 @@ export class Crate {
296302
}
297303

298304
function updateFileEnsureChange(
299-
filePath: PathRef,
300-
action: (filePath: PathRef, fileText: string) => string,
305+
filePath: Path,
306+
action: (filePath: Path, fileText: string) => string,
301307
) {
302308
const originalText = filePath.readTextSync();
303309
const newText = action(filePath, originalText);

crates_io.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
2-
import { $ } from "./deps.ts";
1+
// Copyright 2018-2025 the Deno authors. All rights reserved. MIT license.
2+
import { $ } from "@david/dax";
33

44
export interface CratesIoMetadata {
55
crate: {

deno.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@deno/rust-automation",
3+
"imports": {
4+
"@david/dax": "jsr:@david/dax@^0.43.2",
5+
"@std/semver": "jsr:@std/semver@^1.0.5",
6+
"octokit": "npm:octokit@^5.0.3"
7+
},
8+
"lint": {
9+
"rules": {
10+
"exclude": ["no-explicit-any"]
11+
}
12+
},
13+
"exports": {
14+
".": "./mod.ts",
15+
"./repo": "./repo.ts",
16+
"./github-actions": "./github_actions.ts",
17+
"./tasks/bump-deno-deps": "./tasks/bump_deno_deps.ts",
18+
"./tasks/publish-release": "./tasks/publish_release.ts"
19+
}
20+
}

0 commit comments

Comments
 (0)