-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
273 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ name: Publish canary release | |
on: | ||
push: | ||
branches: | ||
- "main" | ||
- "fix-canary-releases" | ||
|
||
jobs: | ||
tag-and-publish-to-npm: | ||
|
@@ -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 | ||
|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); | ||
} |