Skip to content

Commit

Permalink
chore(ci): automatically include releases notes in release draft (den…
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Apr 2, 2022
1 parent 94885bc commit c0ee027
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,17 @@ jobs:
echo ${GITHUB_REF#refs/*/} > release-latest.txt
gsutil -h "Cache-Control: no-cache" cp release-latest.txt gs:https://dl.deno.land/release-latest.txt
- name: Create release notes
shell: bash
if: |
matrix.job == 'test' &&
matrix.profile == 'release' &&
github.repository == 'denoland/deno' &&
startsWith(github.ref, 'refs/tags/')
run: |
export PATH=$PATH:$(pwd)/target/release
./tools/release/05_create_release_notes.ts
- name: Upload release to GitHub
uses: softprops/action-gh-release@59c3b4891632ff9a897f99a91d7bc557467a3a22
if: |
Expand All @@ -570,6 +581,7 @@ jobs:
target/release/deno-x86_64-apple-darwin.zip
target/release/deno_src.tar.gz
target/release/lib.deno.d.ts
body_path: target/release/release-notes.md
draft: true

publish-canary:
Expand Down
38 changes: 8 additions & 30 deletions tools/release/01_bump_crate_versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const cliCrate = workspace.getCliCrate();
const originalCliVersion = cliCrate.version;

// update the std version used in the code
console.log("Updating std version...");
await updateStdVersion();

// increment the cli version
Expand All @@ -32,6 +33,7 @@ await workspace.getCliCrate().cargoUpdate("--workspace");

// try to update the Releases.md markdown text
try {
console.log("Updating Releases.md...");
await updateReleasesMd();
} catch (err) {
console.error(err);
Expand All @@ -43,38 +45,14 @@ try {
}

async function updateReleasesMd() {
const filePath = path.join(DenoWorkspace.rootDirPath, "Releases.md");
const oldFileText = await Deno.readTextFile(filePath);
const insertText = await getReleasesMdText();

await Deno.writeTextFile(
filePath,
oldFileText.replace(/^### /m, insertText + "\n\n### "),
);

await workspace.runFormatter();
console.log(
"Updated Release.md -- Please review the output to ensure it's correct.",
);
}

async function getReleasesMdText() {
const gitLog = await getGitLog();
const formattedGitLog = gitLog.formatForReleaseMarkdown();
const formattedDate = getFormattedDate(new Date());

return `### ${cliCrate.version} / ${formattedDate}\n\n` +
`${formattedGitLog}`;

function getFormattedDate(date: Date) {
const formattedMonth = padTwoDigit(date.getMonth() + 1);
const formattedDay = padTwoDigit(date.getDate());
return `${date.getFullYear()}.${formattedMonth}.${formattedDay}`;
const releasesMdFile = workspace.getReleasesMdFile();
releasesMdFile.updateWithGitLog({
version: cliCrate.version,
gitLog,
});

function padTwoDigit(val: number) {
return val.toString().padStart(2, "0");
}
}
await workspace.runFormatter();
}

async function getGitLog() {
Expand Down
12 changes: 12 additions & 0 deletions tools/release/05_create_release_notes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-run=cargo,git --no-check
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { path } from "./deps.ts";
import { DenoWorkspace } from "./deno_workspace.ts";

const workspace = await DenoWorkspace.load();

// create a release notes file for the GH release draft
await Deno.writeTextFile(
path.join(DenoWorkspace.rootDirPath, "./target/release/release-notes.md"),
workspace.getReleasesMdFile().getLatestReleaseText().fullText,
);
8 changes: 7 additions & 1 deletion tools/release/deno_workspace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

import { path, Repo } from "./deps.ts";
import { path, ReleasesMdFile, Repo } from "./deps.ts";

export class DenoWorkspace {
#repo: Repo;
Expand Down Expand Up @@ -46,6 +46,12 @@ export class DenoWorkspace {
return this.#repo.getCrate(name);
}

getReleasesMdFile() {
return new ReleasesMdFile(
path.join(DenoWorkspace.rootDirPath, "Releases.md"),
);
}

runFormatter() {
return this.#repo.runCommandWithOutput([
"deno",
Expand Down
4 changes: 2 additions & 2 deletions tools/release/deps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

export * from "https://raw.githubusercontent.com/denoland/automation/0.9.2/mod.ts";
export * from "https://raw.githubusercontent.com/denoland/automation/0.9.2/github_actions.ts";
export * from "https://raw.githubusercontent.com/denoland/automation/0.11.0/mod.ts";
export * from "https://raw.githubusercontent.com/denoland/automation/0.11.0/github_actions.ts";

0 comments on commit c0ee027

Please sign in to comment.