Skip to content

Commit 26f4a8c

Browse files
committed
feat: support --dry-run, -n, DRY_RUN
1 parent adc5e90 commit 26f4a8c

File tree

6 files changed

+40
-48
lines changed

6 files changed

+40
-48
lines changed

.github/workflows/ci.yml

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

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: release
33
on:
44
push:
55
branches:
6-
- main
6+
- "**"
77

88
jobs:
99
lint:
@@ -35,6 +35,7 @@ jobs:
3535
- run: deno task test
3636

3737
release:
38+
name: "release${{ github.ref_name != 'main' && ' (dry-run)' || '' }}"
3839
runs-on: ubuntu-latest
3940
needs:
4041
- lint
@@ -46,6 +47,6 @@ jobs:
4647
with:
4748
fetch-depth: 0
4849
- uses: denoland/setup-deno@v2
49-
- run: deno run --allow-net --allow-env --allow-run shipit.ts
50+
- run: "deno run --allow-net --allow-env --allow-run shipit.ts ${{ github.ref_name != 'main' && '--dry-run' || '' }}"
5051
env:
5152
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ these are the most notable differences from upstream:
4949
- [x] Unit tests for the more complex commit messages.
5050
- [x] Update dependencies.
5151
- [ ] TODO: Bump version number in any `deno.json` and `deno.jsonc`.
52+
- [x] Dry-run mode, doesn't make any changes, but prints new version and release
53+
notes.
54+
- Use `--dry-run` or `-n` to enable, or set `DRY_RUN=1` in your environment.
5255

5356
## Usage
5457

@@ -89,7 +92,7 @@ step.
8992
permissions:
9093

9194
- `--allow-env`: It reads `GITHUB_TOKEN` from your local environment in order to
92-
authenticate with GitHub. It can also read `VERBOSE`.
95+
authenticate with GitHub. It can also read `DRY_RUN` and `VERBOSE`.
9396
- `--allow-run`: It needs to spawn subprocesses (`git`, `bash`) in order to
9497
gather information about your commits.
9598
- `--allow-net`: It needs to make outbound network requests to GitHub in order

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"test": " deno test --coverage --trace-leaks --allow-run --allow-env=VERBOSE",
1313
"test-watch": " deno test --watch --trace-leaks --allow-run --allow-env=VERBOSE",
1414
"coverage": " deno coverage",
15-
"release": " deno task all && GITHUB_TOKEN=$(gh auth token) deno run --allow-env=GITHUB_TOKEN,VERBOSE --allow-net=api.github.com --allow-run=bash,git shipit.ts",
15+
"release": " deno task all && GITHUB_TOKEN=$(gh auth token) deno run --allow-env=GITHUB_TOKEN,VERBOSE,DRY_RUN --allow-net=api.github.com --allow-run=bash,git shipit.ts",
1616
"bump-deps": " deno task forall-files-no-yaml -- deno run --allow-env --allow-read=.,$HOME/.cache/deno,$HOME/.local/share/deno-wasmbuild --allow-write=.,$HOME/.local/share/deno-wasmbuild --allow-run=git --allow-net jsr:@molt/cli@0.19.8 --commit --prefix=\"chore: \"",
1717
"list-files": " git ls-files | deno eval 'import{toText}from\"jsr:@std/streams@1.0.8\";console.log((await toText(Deno.stdin.readable)).split(\"\\n\").filter(f=>f.startsWith(\".github/workflows\")||/\\.((mj|j|t)sx?|jsonc?)$/.test(f)).filter(f=>{try{return !Deno.statSync(f).isDirectory}catch{}}).join(\"\\n\"))'",
1818
"foreach-file-no-json-yaml": "deno task list-files | grep -viE '\\.(jsonc?|ya?ml)$' | sh -c 'xargs -I {} -- \"$@\"'",

github.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,17 @@ export interface Commits {
99
other: string[];
1010
}
1111

12-
function generateNotes(
12+
/**
13+
* Generates the release notes for a given version and {@link Commits}.
14+
* @param version The version to generate notes for.
15+
* @param major The commits that are considered major.
16+
* @param minor The commits that are considered minor.
17+
* @param patch The commits that are considered patch.
18+
* @param docs The commits that are considered docs.
19+
* @param other The commits that are considered other.
20+
* @returns The release notes for the given version.
21+
*/
22+
export function generateReleaseNotes(
1323
version: string,
1424
{ major, minor, patch, docs, other }: Commits,
1525
): string {
@@ -47,7 +57,7 @@ function generateNotes(
4757
}
4858

4959
export default {
50-
async release(nextVer: string, commits: Commits): Promise<string> {
60+
async release(nextVer: string, releaseNotes: string): Promise<string> {
5161
const { owner, repo } = await git.repoInfo();
5262

5363
// Get the GitHub token from environment variables
@@ -56,9 +66,6 @@ export default {
5666
throw new Error("GITHUB_TOKEN environment variable is not set.");
5767
}
5868

59-
// Generate the release notes
60-
const body = generateNotes(nextVer, commits);
61-
6269
// Create a new release using the 'request' function
6370
const res = await request("POST /repos/{owner}/{repo}/releases", {
6471
headers: {
@@ -68,7 +75,7 @@ export default {
6875
repo,
6976
name: nextVer,
7077
tag_name: nextVer,
71-
body,
78+
body: releaseNotes,
7279
});
7380

7481
return res.data.html_url;

shipit.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import * as colors from "@std/fmt/colors";
99
import * as semver from "@std/semver";
1010
import git, { ROOT } from "./git.ts";
11-
import github from "./github.ts";
11+
import github, { type Commits, generateReleaseNotes } from "./github.ts";
1212
import { logHeader } from "./log.ts";
1313

1414
if (!import.meta.main) {
@@ -79,6 +79,23 @@ if (ver !== ROOT) {
7979
console.log("Next version:", `${nextVer}\n`);
8080
}
8181

82+
// Generate release notes.
83+
const commits: Commits = { major, minor, patch, docs, other };
84+
const releaseNotes = generateReleaseNotes(nextVer, commits);
85+
86+
// If we're in dry run mode, just print the release notes and exit.
87+
if (
88+
Deno.env.get("DRY_RUN") || Deno.args.includes("--dry-run") ||
89+
Deno.args.includes("-n")
90+
) {
91+
logHeader(
92+
"DRY_RUN or --dry-run is set, so not pushing any tags, nor creating a release.",
93+
);
94+
console.log(`Release notes for ${nextVer} would be:`);
95+
console.log(releaseNotes);
96+
Deno.exit(0);
97+
}
98+
8299
// Tag the new version.
83100
logHeader("Creating new remote tag...");
84101
await git.tag(nextVer);
@@ -90,7 +107,7 @@ logHeader("Creating new GitHub release...");
90107

91108
let url: string;
92109
try {
93-
url = await github.release(nextVer, { major, minor, patch, docs, other });
110+
url = await github.release(nextVer, releaseNotes);
94111
} catch (error) {
95112
// Something went wrong, so delete the local and remote tag and bail.
96113
console.error(error);

0 commit comments

Comments
 (0)