Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(packages/sui-mono): allow to release dependabot upgrades #1667

Merged
merged 6 commits into from
Dec 5, 2023
39 changes: 37 additions & 2 deletions packages/sui-mono/src/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
const conventionalChangelog = require('conventional-changelog')
const {readJsonSync} = require('fs-extra')

const {promisify} = require('util')

const {

Check failure on line 8 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎··checkIsMonoPackage,⏎··getProjectName,⏎··getWorkspaces,⏎··getOverrides⏎` with `checkIsMonoPackage,·getProjectName,·getWorkspaces,·getOverrides`
checkIsMonoPackage,
getProjectName,
getWorkspaces,
getOverrides
} = require('./config.js')

const exec = promisify(require('child_process').exec)
const gitRawCommitsOpts = {reverse: true, topoOrder: true}

const PACKAGE_VERSION_INCREMENT = {
Expand All @@ -18,11 +21,15 @@
MINOR: 2,
MAJOR: 3
}
const DEPS_UPGRADE_COMMIT_TYPE = 'upgrade'
const DEPS_UPGRADE_PACKAGES = ['deps', 'deps-dev']
const DEPS_UPGRADE_BRANCH_PREFIX = 'dependabot/npm_and_yan/'
const SCOPE_REGEX = /packages\/[a-z]+-[a-z]+/

const isCommitBreakingChange = commit => {
const {body, footer} = commit

return [body, footer].some(

Check failure on line 32 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎····msg·=>·typeof·msg·===·'string'·&&·msg.includes('BREAKING·CHANGE')⏎··` with `msg·=>·typeof·msg·===·'string'·&&·msg.includes('BREAKING·CHANGE')`
msg => typeof msg === 'string' && msg.includes('BREAKING CHANGE')
)
}
Expand All @@ -32,7 +39,7 @@
return COMMIT_TYPES_WITH_RELEASE.includes(commit.type)
}

const flattenForMonopackage = status =>

Check failure on line 42 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎··checkIsMonoPackage()·?·{[getProjectName()]:·flatten(status)}·:·status` with `·(checkIsMonoPackage()·?·{[getProjectName()]:·flatten(status)}·:·status)`
checkIsMonoPackage() ? {[getProjectName()]: flatten(status)} : status

const flatten = status =>
Expand All @@ -57,17 +64,44 @@

const getTransform =
({status, packages, overrides = getOverrides()} = {}) =>
(commit, cb) => {
const {scope, header} = commit
async (commit, cb) => {
const {scope, header, type} = commit
const [pkgToOverride] = getOverride({overrides, header}) ?? []
const pkg = pkgToOverride ?? getPkgFromScope(scope)
const isDepsUpdate =

Check failure on line 71 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Delete `⏎·····`
type === DEPS_UPGRADE_COMMIT_TYPE && DEPS_UPGRADE_PACKAGES.includes(pkg)

let toPush = null

if (isDepsUpdate) {
const {stdout: rawUpdateHash} = await exec(
`git log --oneline --grep=${DEPS_UPGRADE_BRANCH_PREFIX} | awk '{print $1}' | head -n 1`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤩

)
const updateHash = rawUpdateHash.trim()

if (!updateHash) return cb()

const {stdout: rawChangedFiles} = await exec(

Check failure on line 84 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········`git·diff·--name-only·${updateHash}·master`⏎······` with ``git·diff·--name-only·${updateHash}·master``
`git diff --name-only ${updateHash} master`
)
const changedFiles = rawChangedFiles.split('\n').filter(Boolean)
const pkgToUpdate = changedFiles

Check failure on line 88 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········.find(file·=>·file.match(SCOPE_REGEX))⏎········` with `.find(file·=>·file.match(SCOPE_REGEX))`
.find(file => file.match(SCOPE_REGEX))
?.match(SCOPE_REGEX)[0]

if (!pkgToUpdate) return cb()

status[pkgToUpdate].increment = Math.max(

Check failure on line 94 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········status[pkgToUpdate].increment,⏎········PACKAGE_VERSION_INCREMENT.MINOR⏎······` with `status[pkgToUpdate].increment,·PACKAGE_VERSION_INCREMENT.MINOR`
status[pkgToUpdate].increment,
PACKAGE_VERSION_INCREMENT.MINOR
)
toPush = commit
}

if (!packages.includes(pkg)) return cb()

if (pkgToOverride) {
status[pkgToOverride].increment = Math.max(

Check failure on line 104 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········status[pkgToOverride].increment,⏎········PACKAGE_VERSION_INCREMENT.MINOR⏎······` with `status[pkgToOverride].increment,·PACKAGE_VERSION_INCREMENT.MINOR`
status[pkgToOverride].increment,
PACKAGE_VERSION_INCREMENT.MINOR
)
Expand All @@ -75,7 +109,7 @@
}

if (isCommitReleaseTrigger(commit)) {
status[pkg].increment = Math.max(

Check failure on line 112 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········status[pkg].increment,⏎········PACKAGE_VERSION_INCREMENT.MINOR⏎······` with `status[pkg].increment,·PACKAGE_VERSION_INCREMENT.MINOR`
status[pkg].increment,
PACKAGE_VERSION_INCREMENT.MINOR
)
Expand All @@ -83,7 +117,7 @@
}

if (isCommitBreakingChange(commit)) {
status[pkg].increment = Math.max(

Check failure on line 120 in packages/sui-mono/src/check.js

View workflow job for this annotation

GitHub Actions / build

Replace `⏎········status[pkg].increment,⏎········PACKAGE_VERSION_INCREMENT.MAJOR⏎······` with `status[pkg].increment,·PACKAGE_VERSION_INCREMENT.MAJOR`
status[pkg].increment,
PACKAGE_VERSION_INCREMENT.MAJOR
)
Expand All @@ -109,6 +143,7 @@
*/
const packagesWithChangelog = getWorkspaces().filter(pkg => {
const {private: privateField} = readJsonSync(`${pkg}/package.json`)

return privateField !== true
})

Expand Down
Loading