Skip to content

Commit

Permalink
ci: debug canary releases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Sep 22, 2023
1 parent 85b14d2 commit 74faee1
Show file tree
Hide file tree
Showing 5 changed files with 273 additions and 7 deletions.
20 changes: 13 additions & 7 deletions .github/workflows/publish-canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish canary release
on:
push:
branches:
- "main"
- "fix-canary-releases"

jobs:
tag-and-publish-to-npm:
Expand All @@ -11,7 +11,13 @@ jobs:
# Don't run on regular releases
if: "!startsWith(github.event.head_commit.message, 'release: ')"
steps:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
fetch-tags: true
fetch-depth: 0

- name: Test
run: pwd && ls -la . && ls -la .git && echo $GITHUB_WORKSPACE

- name: Setup Node.js
uses: actions/setup-node@v1
Expand All @@ -23,11 +29,11 @@ jobs:
run: yarn

- name: Run release script
run: yarn release:canary
run: yarn release:info && yarn release:canary

- name: Publish all packages
run: ./scripts/publish.sh canary
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# - name: Publish all packages
# run: ./scripts/publish.sh canary
# env:
# NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

timeout-minutes: 10
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"format:check": "prettier --check \"**/*.{ts,tsx,md}\"",
"format": "prettier --write \"**/*.{ts,tsx,md}\"",
"release": "yarn release:prepare && yarn changelog && yarn release-commit",
"release:info": "git fetch --tags && node scripts/conventional-tmp/cli -p angular",
"release:prepare": "git fetch --tags && conventional-recommended-bump -p angular | xargs yarn version:auto $1",
"release:canary": "yarn release:prepare && node scripts/get-unstable-version canary | xargs yarn version:auto $1",
"release:canary:old": "yarn release:prepare && node scripts/get-unstable-version canary | xargs yarn version:auto $1",
"release-commit": "git add -u && git commit -m \"release: v${npm_package_version}\"",
"version": "lerna version --force-publish -y --no-push --no-changelog --no-git-tag-version $npm_package_version",
"version:auto": "yarn version --no-git-tag-version --new-version $1",
Expand Down
106 changes: 106 additions & 0 deletions scripts/conventional-tmp/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/env node

"use strict";

const meow = require("meow");
const conventionalRecommendedBump = require("./");
const path = require("path");

const cli = meow(
`
Usage
conventional-recommended-bump
Example
conventional-recommended-bump
Options
-p, --preset Name of the preset you want to use
-g, --config A filepath of your config script
-h, --header-pattern Regex to match header pattern
-c, --header-correspondence Comma separated parts used to define what capturing group of 'headerPattern' captures what
-r, --reference-actions Comma separated keywords that used to reference issues
-i, --issue-prefixes Comma separated prefixes of an issue
-n, --note-keywords Comma separated keywords for important notes
-f, --field-pattern Regex to match other fields
-v, --verbose Verbose output
-l, --lerna-package Recommend a bump for a specific lerna package (:[email protected])
-t, --tag-prefix Tag prefix to consider when reading the tags
--commit-path Recommend a bump scoped to a specific directory
--skip-unstable If given, unstable tags will be skipped, e.g., x.x.x-alpha.1, x.x.x-rc.2
`,
{
flags: {
preset: {
alias: "p",
},
config: {
alias: "g",
},
"header-pattern": {
alias: "h",
},
"header-correspondence": {
alias: "c",
},
"reference-actions": {
alias: "r",
},
"issue-prefixes": {
alias: "i",
},
"note-keywords": {
alias: "n",
},
"field-pattern": {
alias: "f",
},
verbose: {
alias: "v",
},
"lerna-package": {
alias: "l",
},
"tag-prefix": {
alias: "t",
},
},
}
);

const options = {
path: cli.flags.commitPath,
lernaPackage: cli.flags.lernaPackage,
tagPrefix: cli.flags.tagPrefix,
skipUnstable: cli.flags.skipUnstable,
};
const flags = cli.flags;
const preset = flags.preset;
const config = flags.config;

if (preset) {
options.preset = preset;
delete flags.preset;
} else if (config) {
options.config = require(path.resolve(process.cwd(), config));
delete flags.config;
}

if (flags.verbose) {
options.warn = console.warn.bind(console);
}

conventionalRecommendedBump(options, flags, function (err, data) {
if (err) {
console.error(err.toString());
process.exit(1);
}

if (data.releaseType) {
console.log(data.releaseType);
}

if (flags.verbose && data.reason) {
console.log(`Reason: ${data.reason}`);
}
});
130 changes: 130 additions & 0 deletions scripts/conventional-tmp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"use strict";
const concat = require("concat-stream");
const conventionalCommitsFilter = require("conventional-commits-filter");
const conventionalCommitsParser = require("conventional-commits-parser");
const conventionalChangelogPresetLoader = require("conventional-changelog-preset-loader");
const gitSemverTags = require("git-semver-tags");
const gitRawCommits = require("git-raw-commits");
const presetResolver = require("./preset-resolver");

const VERSIONS = ["major", "minor", "patch"];

module.exports = conventionalRecommendedBump;

function conventionalRecommendedBump(
optionsArgument,
parserOptsArgument,
cbArgument
) {
if (typeof optionsArgument !== "object") {
throw new Error("The 'options' argument must be an object.");
}

const options = Object.assign({ ignoreReverted: true }, optionsArgument);

const cb =
typeof parserOptsArgument === "function" ? parserOptsArgument : cbArgument;

if (typeof cb !== "function") {
throw new Error("You must provide a callback function.");
}

let presetPackage = options.config || {};
if (options.preset) {
try {
presetPackage = conventionalChangelogPresetLoader(options.preset);
} catch (err) {
if (err.message === "does not exist") {
const preset =
typeof options.preset === "object"
? options.preset.name
: options.preset;
return cb(
new Error(
`Unable to load the "${preset}" preset package. Please make sure it's installed.`
)
);
} else {
return cb(err);
}
}
}

presetResolver(presetPackage)
.then((config) => {
const whatBump =
options.whatBump ||
(config.recommendedBumpOpts && config.recommendedBumpOpts.whatBump
? config.recommendedBumpOpts.whatBump
: noop);

if (typeof whatBump !== "function") {
throw Error("whatBump must be a function");
}

// TODO: For now we defer to `config.recommendedBumpOpts.parserOpts` if it exists, as our initial refactor
// efforts created a `parserOpts` object under the `recommendedBumpOpts` object in each preset package.
// In the future we want to merge differences found in `recommendedBumpOpts.parserOpts` into the top-level
// `parserOpts` object and remove `recommendedBumpOpts.parserOpts` from each preset package if it exists.
const parserOpts = Object.assign(
{},
config.recommendedBumpOpts && config.recommendedBumpOpts.parserOpts
? config.recommendedBumpOpts.parserOpts
: config.parserOpts,
parserOptsArgument
);

const warn =
typeof parserOpts.warn === "function" ? parserOpts.warn : noop;

gitSemverTags(
{
lernaTags: !!options.lernaPackage,
package: options.lernaPackage,
tagPrefix: options.tagPrefix,
skipUnstable: options.skipUnstable,
},
(err, tags) => {
if (err) {
return cb(err);
}

gitRawCommits({
format: "%B%n-hash-%n%H",
from: tags[0] || "",
path: options.path,
})
.pipe(conventionalCommitsParser(parserOpts))
.pipe(
concat((data) => {
const commits = options.ignoreReverted
? conventionalCommitsFilter(data)
: data;

console.log("Tags", JSON.stringify(tags, undefined, 4));
console.log("Commits", JSON.stringify(commits, undefined, 4));

if (!commits || !commits.length) {
warn("No commits since last release");
}

let result = whatBump(commits, options);

console.log("Result", result);

if (result && result.level != null) {
result.releaseType = VERSIONS[result.level];
} else if (result == null) {
result = {};
}

cb(null, result);
})
);
}
);
})
.catch((err) => cb(err));
}

function noop() {}
22 changes: 22 additions & 0 deletions scripts/conventional-tmp/preset-resolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"use strict";

const Q = require("q");

module.exports = presetResolver;

function presetResolver(presetPackage) {
// start the chain as a Q.Promise
return Q.resolve().then(() => {
// handle traditional node-style callbacks
if (typeof presetPackage === "function") {
return Q.nfcall(presetPackage);
}

// handle object literal or Promise instance
if (typeof presetPackage === "object") {
return Q(presetPackage);
}

throw new Error("preset package must be a promise, function, or object");
});
}

0 comments on commit 74faee1

Please sign in to comment.