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
31 changes: 29 additions & 2 deletions packages/sui-mono/src/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
const conventionalChangelog = require('conventional-changelog')
const {readJsonSync} = require('fs-extra')

const {promisify} = require('util')

const {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 @@ -13,6 +16,10 @@ const PACKAGE_VERSION_INCREMENT = {
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
Expand Down Expand Up @@ -49,13 +56,32 @@ const getOverride = ({overrides, header}) => {

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 = 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(`git diff --name-only ${updateHash} master`)
const changedFiles = rawChangedFiles.split('\n').filter(Boolean)
const pkgToUpdate = changedFiles.find(file => file.match(SCOPE_REGEX))?.match(SCOPE_REGEX)[0]

if (!pkgToUpdate) return cb()

status[pkgToUpdate].increment = Math.max(status[pkgToUpdate].increment, PACKAGE_VERSION_INCREMENT.MINOR)
toPush = commit
}

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

if (pkgToOverride) {
Expand Down Expand Up @@ -92,6 +118,7 @@ const check = () =>
*/
const packagesWithChangelog = getWorkspaces().filter(pkg => {
const {private: privateField} = readJsonSync(`${pkg}/package.json`)

return privateField !== true
})

Expand Down
Loading