From 0f3b74ae16829b8c2662757966b3cd1b1eb81d05 Mon Sep 17 00:00:00 2001 From: aesoft <43991222+aeppling@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:49:02 +0200 Subject: [PATCH 1/2] fix: versioning workflow semantic + helm releaser --- .github/workflows/fullrelease.yaml | 56 ++++++++++++++++++++++++++++++ charts/kexa-chart/Chart.yaml | 9 +++-- package-lock.json | 9 +++-- package.json | 9 +++++ update-chart-version.js | 42 ++++++++++++++++++++++ 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/fullrelease.yaml create mode 100644 update-chart-version.js diff --git a/.github/workflows/fullrelease.yaml b/.github/workflows/fullrelease.yaml new file mode 100644 index 00000000..da35f10c --- /dev/null +++ b/.github/workflows/fullrelease.yaml @@ -0,0 +1,56 @@ +name: Release Workflow (Semantic + Helm) + +on: + push: + branches: + - dev + +jobs: + semantic-release: + permissions: + contents: write + issues: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Prep plugins + run: | + npm install -D @semantic-release/changelog @semantic-release/git @semantic-release/exec + - name: Run semantic release + id: ver + run: npx semantic-release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + helm-release: + needs: semantic-release + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Helm + run: | + helm repo add bitnami https://charts.bitnami.com/bitnami + helm repo add grafana https://grafana.github.io/helm-charts + helm repo update + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + with: + config: "cr.yaml" diff --git a/charts/kexa-chart/Chart.yaml b/charts/kexa-chart/Chart.yaml index 3b8743d2..d9c261e4 100644 --- a/charts/kexa-chart/Chart.yaml +++ b/charts/kexa-chart/Chart.yaml @@ -1,14 +1,13 @@ apiVersion: v2 -name: "helm-kexa-grafana-postgres" +name: helm-kexa-grafana-postgres description: A Helm chart that installs PostgreSQL and Grafana version: 1.4.0 -appVersion: "1.0" +appVersion: '1.0' icon: https://kexa.io/kexa-no-background-color.png - dependencies: - name: postgresql version: 15.0.0 - repository: "https://charts.bitnami.com/bitnami" + repository: https://charts.bitnami.com/bitnami - name: grafana version: 8.5.1 - repository: "https://grafana.github.io/helm-charts" \ No newline at end of file + repository: https://grafana.github.io/helm-charts diff --git a/package-lock.json b/package-lock.json index 9b08218e..9388e67b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,6 +4,9 @@ "requires": true, "packages": { "": { + "dependencies": { + "js-yaml": "^4.1.0" + }, "devDependencies": { "@semantic-release/changelog": "^6.0.3", "@semantic-release/exec": "^6.0.3", @@ -879,9 +882,7 @@ "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true, - "peer": true + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, "node_modules/argv-formatter": { "version": "1.0.0", @@ -2221,8 +2222,6 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "peer": true, "dependencies": { "argparse": "^2.0.1" }, diff --git a/package.json b/package.json index 9ae70cac..5ea07381 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,16 @@ { "publishCmd": "echo ::set-output name=nextVer::${nextRelease.version}" } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "node update-chart-version.js ${nextRelease.version}" + } ] ] + }, + "dependencies": { + "js-yaml": "^4.1.0" } } diff --git a/update-chart-version.js b/update-chart-version.js new file mode 100644 index 00000000..e6443d1f --- /dev/null +++ b/update-chart-version.js @@ -0,0 +1,42 @@ +// YAML TO JSON +// CHANGE VERSION +// THEN JSON TO YAML AND WRITE TO FILE + +const fs = require('fs'); +const path = require('path'); +const yaml = require('js-yaml'); + +const newVersion = process.argv[2]; +if (!newVersion) { + console.error('Error: No version specified.'); + process.exit(1); +} + +const chartFilePath = 'charts/kexa-chart/Chart.yaml'; + +if (!fs.existsSync(chartFilePath)) { + console.error(`Error: ${chartFilePath} not found.`); + process.exit(1); +} + +let fileContent = fs.readFileSync(chartFilePath, 'utf8'); +let chartData; + +try { + chartData = yaml.load(fileContent); +} catch (e) { + console.error('Error parsing YAML:', e); + process.exit(1); +} + +if (chartData.version) { + chartData.version = newVersion; + console.log(`Updating version to ${newVersion}`); +} else { + console.error('Version field not found in Chart.yaml.'); + process.exit(1); +} + +const updatedYaml = yaml.dump(chartData); +fs.writeFileSync(chartFilePath, updatedYaml, 'utf8'); +console.log(`Updated ${chartFilePath} to version ${newVersion}`); \ No newline at end of file From ef554df123ee70db9d634920284d193c907f8dbe Mon Sep 17 00:00:00 2001 From: aesoft <43991222+aeppling@users.noreply.github.com> Date: Tue, 17 Sep 2024 13:51:20 +0200 Subject: [PATCH 2/2] fix: workflow OK, commit on main --- .github/workflows/fullrelease.yaml | 2 +- .github/workflows/release.yaml | 3 --- .github/workflows/versioning.yaml | 4 +--- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/fullrelease.yaml b/.github/workflows/fullrelease.yaml index da35f10c..8ce9d241 100644 --- a/.github/workflows/fullrelease.yaml +++ b/.github/workflows/fullrelease.yaml @@ -3,7 +3,7 @@ name: Release Workflow (Semantic + Helm) on: push: branches: - - dev + - main jobs: semantic-release: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 73e33aa9..0f8c7e67 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,9 +2,6 @@ name: Release Charts on: workflow_dispatch: - push: - branches: - - main jobs: release: diff --git a/.github/workflows/versioning.yaml b/.github/workflows/versioning.yaml index 5921a22d..d0c00775 100644 --- a/.github/workflows/versioning.yaml +++ b/.github/workflows/versioning.yaml @@ -1,9 +1,7 @@ name: Release on: - push: - branches: - - main + workflow_dispatch: jobs: release: