docs-util: fix release scripts (#6353)

- Fix GitHub action to run on push and check if the commit message is "chore: Release". Only then are TSDocs generated and a PR is opened.
- Add an option to pass to the `run:release` method of the docblock generator a release tag. This is helpful in cases when the GitHub action fails for any reason.
- Add scripts that checks the message of a commit.
This commit is contained in:
Shahed Nasser
2024-02-08 22:36:27 +02:00
committed by GitHub
parent ef64f3740d
commit 66e8f4e0d2
7 changed files with 88 additions and 9 deletions

View File

@@ -26,6 +26,22 @@ export class GitManager {
})
}
async getCommitFilesSinceRelease(tagName: string) {
const { data: release } = await this.octokit.request(
"GET /repos/{owner}/{repo}/releases/tags/{tag}",
{
owner: this.owner,
repo: this.repo,
tag: tagName,
headers: {
"X-GitHub-Api-Version": this.gitApiVersion,
},
}
)
return this.getCommitsFiles(release.published_at)
}
async getCommitFilesSinceLastRelease() {
// list releases to get the latest two releases
const { data: release } = await this.octokit.request(
@@ -39,13 +55,17 @@ export class GitManager {
}
)
return this.getCommitsFiles(release.published_at)
}
async getCommitsFiles(date?: string | null) {
// get commits between the last two releases
const commits = await this.octokit.paginate(
"GET /repos/{owner}/{repo}/commits",
{
owner: this.owner,
repo: this.repo,
since: release.published_at || undefined,
since: date || undefined,
per_page: 100,
}
)

View File

@@ -4,12 +4,18 @@ import DocblockGenerator from "../classes/docblock-generator.js"
import getMonorepoRoot from "../utils/get-monorepo-root.js"
import { GitManager } from "../classes/git-manager.js"
export default async function () {
type Options = {
tag?: string
}
export default async function ({ tag }: Options) {
const gitManager = new GitManager()
console.log("Get files in commits since last release")
console.log(`Get files in commits since ${tag || "last release"}`)
const files = await gitManager.getCommitFilesSinceLastRelease()
const files = tag
? await gitManager.getCommitFilesSinceRelease(tag)
: await gitManager.getCommitFilesSinceLastRelease()
// filter changed files
let filteredFiles = filterFiles(files)

View File

@@ -36,6 +36,10 @@ program
.description(
"Generate TSDoc doc-blocks for files part of the latest release. It will retrieve the files of commits between the latest two releases."
)
.option(
"--tag <tag>",
"Specify a release tag to use rather than the latest release."
)
.action(runRelease)
program.parse()