feat: Create a custom action to verify chart version

This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-07-28 17:01:37 +02:00 committed by GitHub
parent c598d8a00a
commit b4b335ca6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 25241 additions and 51 deletions

View file

@ -1,4 +1,9 @@
# See https://pre-commit.com for more information
exclude: |
(?x)^(
.github\/actions\/.*\/dist\/.*
)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1

View file

@ -1,38 +0,0 @@
#!/usr/bin/env zx
import 'zx/globals'
const chart = argv["_"][0]
argv.debug ? $.verbose = true : $.verbose = false
if (chart == undefined) {
console.log(chalk.redBright(`ERROR: `) + `No chart provided to validate!`)
process.exit(1)
}
const defaultBranch = argv.default_branch || await $`git remote show origin | awk '/HEAD branch/ {print $NF}'`
const chartYamlPath = `${chart}/Chart.yaml`
if (!await fs.pathExists(chartYamlPath)) {
console.log(chalk.redBright(`ERROR: `) + `${chartYamlPath} does not exist!`)
process.exit(1)
}
const getOriginalChartYamlProcessOutput = await $`git show origin/${defaultBranch}:./${chartYamlPath}`
const originalChartYamlContent = Buffer.from(getOriginalChartYamlProcessOutput.stdout, 'utf-8').toString();
const originalChartYaml = await YAML.parse(originalChartYamlContent)
echo `Original version: ${originalChartYaml.version}`
const updatedChartYamlContent = await fs.readFile(chartYamlPath, 'utf8')
const updatedChartYaml = await YAML.parse(updatedChartYamlContent)
if (!updatedChartYaml.version) {
console.log(chalk.redBright(`ERROR: `) + `${chartYamlPath} does not contain a version!`)
process.exit(1)
}
echo `New version: ${updatedChartYaml.version}`
if (updatedChartYaml.version == originalChartYaml.version) {
console.log(chalk.redBright(`ERROR: `) + `Chart version has not been updated!`)
process.exit(1)
} else {
console.log(chalk.greenBright(`OK: `) + `Chart version has been updated!`)
}