dev: add helm support to release cli (#31364)

This commit is contained in:
Michael Lin 2022-02-17 13:16:27 -08:00 committed by GitHub
parent f9ef00ff4b
commit 52c46a1e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 1 deletions

17
dev/release/src/chart.ts Normal file
View File

@ -0,0 +1,17 @@
import { readFileSync } from 'fs'
import { load as loadYAML } from 'js-yaml'
export interface Metadata {
apiVersion: string
name: string
description: string
type: string
version: string
appVersion: string
}
export function parseChartMetadata(chartYamlPath: string): Metadata {
const chartYamlContents = readFileSync(chartYamlPath, 'utf8').toString()
return loadYAML(chartYamlContents) as Metadata
}

View File

@ -3,9 +3,12 @@ import * as path from 'path'
import commandExists from 'command-exists'
import { addMinutes } from 'date-fns'
import * as execa from 'execa'
import * as semver from 'semver'
import * as batchChanges from './batchChanges'
import * as changelog from './changelog'
import * as chart from './chart'
import { Config, releaseVersions } from './config'
import {
getAuthenticatedGitHubClient,
@ -371,7 +374,7 @@ cc @${config.captainGitHubUsername}
// Render changes
const createdChanges = await createChangesets({
requiredCommands: ['comby', sed, 'find', 'go', 'src'],
requiredCommands: ['comby', sed, 'find', 'go', 'src', 'sg'],
changes: [
{
owner: 'sourcegraph',
@ -497,6 +500,38 @@ cc @${config.captainGitHubUsername}
],
...prBodyAndDraftState([]),
},
{
owner: 'sourcegraph',
repo: 'deploy-sourcegraph-helm',
base: 'main',
head: `publish-${release.version}`,
commitMessage: defaultPRMessage,
title: defaultPRMessage,
edits: [
`sg ops update-images -kind helm -pin-tag ${release.version} charts/sourcegraph/.`,
`${sed} -i 's/appVersion:.*/appVersion: "${release.version}"/g' charts/sourcegraph/Chart.yaml`,
(directory: string) => {
const chartYamlPath = path.join(directory, 'charts/sourcegraph/Chart.yaml')
const metadata = chart.parseChartMetadata(chartYamlPath)
const parsedPreviousVersion = semver.parse(metadata.version)
if (!parsedPreviousVersion) {
throw new Error('`version` field in Chart.yaml is not valid semver')
}
const nextVersion = notPatchRelease
? parsedPreviousVersion.inc('minor')
: parsedPreviousVersion.inc('patch')
execa.sync(
'bash',
[
'-c',
`${sed} -i 's/version:.*/version: ${nextVersion.version}/g' charts/sourcegraph/Chart.yaml`,
],
{ stdio: 'inherit', cwd: directory }
)
},
],
...prBodyAndDraftState([]),
},
],
dryRun: dryRun.changesets,
})