Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (e) {
error(`An error occured creating Jira Release version: ${jiraVersionName}!`)
error(e)
}
// result = {
// "self":"https://instructure.atlassian.net/rest/api/2/version/46639",
// "id":"46639",
// "name":"instructure-ui v5.10.0",
// "archived":false,
// "released":true,
// "projectId":17900
// }
if (result && result.id) {
info(`Created ${result.name}:`, JSON.stringify(result))
return {
...result,
url: `https://${config.jira_host}/projects/${config.jira_project_key}/versions/${result.id}`
}
}
}
exports.createJiraVersion = createJiraVersion
try {
result = runGitCommand(['log', `${previousReleaseTag}..${currentReleaseTag}`])
} catch (e) {
error(e)
process.exit(1)
}
let issueKeys = result.match(jiraMatcher) || []
issueKeys = issueKeys
.filter(key => key.indexOf(jiraProjectKey) != -1)
if (issueKeys.length > 0) {
issueKeys = Array.from(new Set(issueKeys))
info(`Issues in this release: ${issueKeys.join(', ')}`)
}
return issueKeys
}
exports.publishGithubPages = function publishGithubPages (config = {
gh_pages_dir: '.',
gh_pages_branch: 'gh-pages'
}) {
if (!fs.existsSync(`${config.gh_pages_dir}`)) {
error(`GH pages directory doesn't exist! Do you need to build the documentation?`)
process.exit(1)
}
info(`📖 Deploying '${config.gh_pages_dir}' to Github pages...`)
info(`📖 Repository: ${GIT_REMOTE_URL}...`)
info(`📖 Branch: ${config.gh_pages_branch}...`)
runCommandSync('touch', [`${config.gh_pages_dir}/.nojekyll`])
if (config.gh_pages_cname) {
fs.writeFileSync(`${config.gh_pages_dir}/CNAME`, config.gh_pages_cname)
}
return new Promise((resolve, reject) => {
ghpages.publish(config.gh_pages_dir, {
branch: config.gh_pages_branch,
repo: GIT_REMOTE_URL,
user: {
name: GIT_USERNAME,
email: GIT_EMAIL
},
async function publish (packageName, currentVersion, preidAndTag, config = {}) {
setupGit()
createNPMRCFile(config)
checkWorkingDirectory()
let versionToRelease, tag
if (isReleaseCommit(currentVersion)) {
checkIfGitTagExists(currentVersion)
checkIfCommitIsReviewed()
info(`📦 Currently on release commit for ${currentVersion} of ${packageName}.`)
versionToRelease = currentVersion
tag = preidAndTag || 'latest'
} else {
info(`📦 Not on a release commit--publishing a pre-release...`)
versionToRelease = 'prerelease'
tag = preidAndTag || 'rc'
}
let releasedVersion
try {
releasedVersion = await publishPackages(packageName, versionToRelease, tag)
} catch (e) {
error(e)
process.exit(1)
}
if (GERRIT_CHANGE_NUMBER && GERRIT_PATCHSET_NUMBER) {
try {
await postGerritReview(
`${GERRIT_CHANGE_NUMBER},${GERRIT_PATCHSET_NUMBER}`,
let releaseVersion
try {
await runCommandAsync('lerna', [
'version',
...args,
'--include-merged-tags',
'--no-push',
'--no-git-tag-version',
'--force-publish=*',
'--conventional-commits'
])
releaseVersion = await syncRootPackageVersion(true)
info(`📦 Done bumping ${packageName} to ${releaseVersion}!`)
} catch (err) {
error(err)
process.exit(1)
}
return releaseVersion
}
exports.bumpPackages = bumpPackages
function deployDocs (packageName, currentVersion, config = {}) {
setupGit()
if (isReleaseCommit(currentVersion)) {
checkWorkingDirectory()
info(`📖 Deploying documentation for ${currentVersion} of ${packageName}...`)
try {
publishGithubPages(config)
} catch (err) {
error(err)
process.exit(1)
}
info(`📖 Documentation for ${currentVersion} of ${packageName} was successfully deployed!`)
} else {
info(`📦 Not on a release commit--skipping documentation publish.`)
}
}
async function updateCrossPackageDependencies (packageName, releaseVersion, dependencyVersion) {
const changedPackages = getChangedPackages()
const changedPackageNames = changedPackages.map(pkg => pkg.name)
info(`📦 Updating cross-package dependencies for ${packageName} to ${dependencyVersion}...`)
await Promise.all(
changedPackages.map(changedPackage => {
const pkg = changedPackage.toJSON()
let packageChanged = false
const depCollections = [
'dependencies',
'devDependencies',
'optionalDependencies',
'peerDependencies'
]
depCollections.forEach(depCollection => {
if (!pkg[depCollection]) return
const newDependencies = Object.keys(pkg[depCollection])
function postSlackMessage (message, issueKeys = [], config = { slack_emoji: ':robot_face:'}) {
if (config.slack_channel && SLACK_WEBHOOK) {
info(`💬 Pinging slack channel: ${config.slack_channel}`)
const issues = (issueKeys.length > 0) ? `\n\nIssues in this release: ${issueKeys.join(', ')}` : ''
const payload = {
'channel': config.slack_channel,
'username': SLACK_USERNAME,
'icon_emoji': config.slack_emoji,
'text': message + issues,
'link_names': 1
}
const req = https.request({
path: `/services/${SLACK_WEBHOOK}`,
hostname: 'hooks.slack.com',
method: 'POST'
})
async function findJiraVersion (jiraVersionName, config = {}) {
let result = []
try {
info(`Looking for ${jiraVersionName} in Jira project: ${config.jira_project_key}...`)
result = await jiraClient(config).getVersions(config.jira_project_key)
} catch (e) {
error(`Could not get Jira versions for project: ${config.jira_project_key}`)
error(e)
}
return result[result.findIndex(version => version.name === jiraVersionName)]
}
exports.findJiraVersion = findJiraVersion
getPackages().map(async pkg => {
let packageIsUsed = false
try {
const { stdout } = await runCommandAsync('yarn', ['why', pkg.name, '--cwd', appDir], [], { stdio: 'pipe'})
info(stdout)
packageIsUsed = stdout.includes(' Found')
} catch (err) {
info(`${pkg.name} is not used. ${err}`)
}
if (packageIsUsed) return pkg
})
)).filter(Boolean)