Skip to content

Commit

Permalink
Ci/configure gulp for ci (#14)
Browse files Browse the repository at this point in the history
* ci: configure gulp

* ci: read package version directly

* ci: skip release commits

* ci: enable github releases

* ci: remove changelog
  • Loading branch information
Wroud authored Sep 9, 2024
1 parent 155b824 commit ba54318
Show file tree
Hide file tree
Showing 218 changed files with 662 additions and 1,713 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
- name: Run ci:prepublish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
GITHUB_REPOSITORY_NAME: ${{ github.repository }}
run: yarn workspaces foreach -A --no-private run ci:prepublish

- name: Release
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/keyv-npm-3.0.0-31c4735a55-eb128eb136.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/meow-npm-3.7.0-5653cc98af-e5ba4632b6.zip
Binary file not shown.
Binary file removed .yarn/cache/meow-npm-4.0.1-04410d5b48-3e6a6688d2.zip
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/meow-npm-8.1.2-bcfe48d4f3-9a8d90e616.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ms-npm-2.1.3-81ff3cfac1-d924b57e73.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/pify-npm-2.3.0-8b63310934-551ff8ab83.zip
Binary file not shown.
Binary file removed .yarn/cache/pify-npm-3.0.0-679ee405c8-fead19ed9d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/q-npm-1.5.1-a28b3cfeaf-7855fbdba1.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/_aggregate/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
},
{
"path": "../docs"
},
{
"path": "../ci"
},
{
"path": "../ci-github-release"
}
]
}
30 changes: 30 additions & 0 deletions packages/ci-github-release/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "@wroud/ci-github-release",
"private": true,
"version": "0.0.1",
"type": "module",
"packageManager": "[email protected]",
"devDependencies": {
"@tsconfig/node20": "^20",
"@types/conventional-changelog": "^3",
"@types/conventional-changelog-core": "^4",
"@types/conventional-changelog-writer": "^4",
"@types/conventional-commits-parser": "^5",
"@types/git-semver-tags": "^7",
"@types/node": "^20",
"@types/semver": "^7",
"@wroud/tsconfig": "workspace:^",
"typescript": "^5"
},
"exports": {
".": "./lib/github-release.js"
},
"dependencies": {
"@octokit/rest": "^21",
"conventional-changelog": "^6",
"conventional-changelog-conventionalcommits": "^8",
"git-semver-tags": "^8",
"semver": "^7",
"semver-regex": "^4"
}
}
4 changes: 4 additions & 0 deletions packages/ci-github-release/src/IAuthOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface IAuthOptions {
type: "token" | "oauth";
token: string;
}
6 changes: 6 additions & 0 deletions packages/ci-github-release/src/git-semver-tags.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as gitSemverTags from "git-semver-tags";

declare module "git-semver-tags" {
const p = gitSemverTags.default;
export { p as getSemverTags };
}
122 changes: 122 additions & 0 deletions packages/ci-github-release/src/github-release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import conventionalChangelog from "conventional-changelog";
import { getSemverTags } from "git-semver-tags";
import { Octokit } from "@octokit/rest";
import semver from "semver";
import { Transform } from "stream";
import { transform } from "./transform.js";

import type {
Context,
GitRawCommitsOptions,
ParserOptions,
WriterOptions,
} from "conventional-changelog-core";
import type { Context as WriterContext } from "conventional-changelog-writer";
import type { Commit } from "conventional-commits-parser";
import type { IAuthOptions } from "./IAuthOptions.js";

function log(message: string, ...args: any[]) {
console.log(`[ci-github-releaser] ${message}`, ...args);
}

type Options<
TCommit extends Commit = Commit,
TContext extends WriterContext = WriterContext,
> = conventionalChangelog.Options<TCommit, TContext>;

/**
* Create a GitHub release for the latest version in the repository.
*
* @param auth - The authentication options for the GitHub API.
* @param changelogOpts - Options for the changelog generation.
* @param context - The context object with owner and repository.
* @param gitRawCommitsOpts - Options for git-raw-commits.
* @param parserOpts - Options for the parser.
* @param writerOpts - Options for the writer.
*/
export async function githubRelease<
TCommit extends Commit = Commit,
TContext extends WriterContext = Context,
>(
auth: IAuthOptions,
changelogOpts: Options<TCommit, TContext> = {},
context: Partial<TContext> = {},
gitRawCommitsOpts: GitRawCommitsOptions = {},
parserOpts: ParserOptions = {},
writerOpts: WriterOptions<TCommit, TContext> = {},
) {
const { owner, repository } = context;
if (!owner || !repository) {
throw new Error("Expected context object with 'owner' and 'repository'");
}

log(`Creating GitHub release for ${owner}/${repository}`);
// Initialize Octokit with authentication
const octokit = new Octokit({ auth: auth.token });

changelogOpts = {
transform,
releaseCount: 1,
...changelogOpts,
};

writerOpts.includeDetails = true;
writerOpts.headerPartial = writerOpts.headerPartial || "";

const tags = await getSemverTags({
tagPrefix: changelogOpts.tagPrefix,
});

if (!tags?.length) {
throw new Error("No semver tags found");
}

const { releaseCount = 1 } = changelogOpts;
if (releaseCount !== 0) {
gitRawCommitsOpts = { from: tags[releaseCount], ...gitRawCommitsOpts };
}

gitRawCommitsOpts.to = gitRawCommitsOpts.to || tags[0];

await new Promise((resolve, reject) => {
conventionalChangelog(
changelogOpts,
context,
gitRawCommitsOpts,
parserOpts,
writerOpts,
)
.on("error", reject)
.on("end", resolve)
.pipe(
new Transform({
objectMode: true,
transform(chunk, enc, callback) {
if (!chunk.keyCommit) {
log("Skipping chunk without keyCommit");
}
const version = chunk.keyCommit?.version;
if (!version) {
callback();
return;
}

const options = {
owner,
repo: repository,
tag_name: version,
name: version,
body: chunk.log,
draft: false,
prerelease: (semver.parse(version)?.prerelease || []).length > 0,
};

octokit.repos
.createRelease(options)
.then(() => callback())
.catch(callback);
},
}),
);
});
}
24 changes: 24 additions & 0 deletions packages/ci-github-release/src/transform.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Commit } from "conventional-commits-parser";
import type { Options } from "conventional-changelog-core";
import semverRegex from "semver-regex";

export function transform<T extends Commit = Commit>(
chunk: Commit,
cb: Options.Transform.Callback<T>,
) {
chunk = { ...chunk };

const gitTags = chunk["gitTags"];
if (typeof gitTags === "string") {
chunk["version"] = (gitTags.match(semverRegex()) || [])[0];
}

if (chunk["committerDate"]) {
// Format the date using toISOString and extract the date part in 'yyyy-mm-dd' format
chunk["committerDate"] = new Date(chunk["committerDate"])
.toISOString()
.split("T")[0];
}

cb(null, chunk as T);
}
14 changes: 14 additions & 0 deletions packages/ci-github-release/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "@wroud/tsconfig/tsconfig.json",
"compilerOptions": {
"tsBuildInfoFile": "./lib/.tsbuildinfo",
"rootDir": "src",
"rootDirs": ["src"],
"outDir": "lib",
"types": ["node"],
"incremental": true,
"composite": true
},
"include": ["src"],
"references": []
}
27 changes: 0 additions & 27 deletions packages/ci/bin/getVersion.js

This file was deleted.

18 changes: 11 additions & 7 deletions packages/ci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
"private": true,
"type": "module",
"packageManager": "[email protected]",
"bin": {
"get-version": "./bin/getVersion.js"
},
"devDependencies": {
"@tsconfig/node20": "^20"
"@tsconfig/node20": "^20",
"@types/conventional-changelog": "^3",
"@types/conventional-changelog-core": "^4",
"@types/conventional-changelog-writer": "^4",
"@types/conventional-commits-parser": "^5",
"@types/gulp": "^4",
"@types/node": "^20",
"@wroud/tsconfig": "workspace:^",
"typescript": "^5"
},
"exports": {
"./gulp": "./gulp/index.js"
"./gulp": "./lib/gulp/index.js"
},
"dependencies": {
"@wroud/ci-github-release": "workspace:^",
"conventional-changelog": "^6",
"conventional-changelog-cli": "^5",
"conventional-changelog-conventionalcommits": "^8",
"conventional-github-releaser": "^3",
"conventional-recommended-bump": "^10",
"execa": "^9",
"gulp": "^5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module "conventional-changelog-conventionalcommits" {
export type Preset = import("conventional-changelog-core").Options.Config;

export default function createPreset(options?: any): Promise<Preset>;
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,42 @@
import type { Preset } from "conventional-changelog-conventionalcommits";
import type { Commit } from "conventional-commits-parser";
import { Bumper } from "conventional-recommended-bump";

export class RestrictEmptyCommits extends Bumper {
loadPreset(preset) {
// @ts-ignore
override loadPreset(preset: Preset) {
// @ts-ignore
this.preset = preset;

this.whatBump = async (commits) => {
// @ts-ignore
this.whatBump = async (commits: Commit[]) => {
// @ts-ignore
const { whatBump } = await this.getPreset();

return whatBump(commits);
};

// @ts-ignore
this.tagGetter = async () => {
// @ts-ignore
const { tags } = await this.getPreset();

// @ts-ignore
return this.getLastSemverTag(tags);
};

// @ts-ignore
this.commitsGetter = async function* commitsGetter() {
// @ts-ignore
const { commits, parser } = await this.getPreset();

// @ts-ignore
yield* this.getCommits(commits, parser);
};

return this;
}
// @ts-ignore
bump(whatBump = this.whatBump) {
return super.bump((commits) => {
if (commits.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PassThrough } from "stream";

// Function to create a combined readable stream from two streams
export function combineStreams(...streams) {
export function combineStreams(...streams: NodeJS.ReadableStream[]) {
const passThrough = new PassThrough();
let currentStreamIndex = 0;

function pipeNext() {
if (currentStreamIndex < streams.length) {
const currentStream = streams[currentStreamIndex];
const currentStream = streams[currentStreamIndex]!;
currentStream.pipe(passThrough, { end: false });
currentStream.on("end", () => {
currentStreamIndex++;
Expand Down
File renamed without changes.
Loading

0 comments on commit ba54318

Please sign in to comment.