From f5c50f275f2ab4cfd3b16fd118ba4aff56c0455d Mon Sep 17 00:00:00 2001 From: aesoft <43991222+aeppling@users.noreply.github.com> Date: Tue, 17 Sep 2024 15:59:11 +0200 Subject: [PATCH] feat: update app version script --- .github/workflows/appversion.yaml | 19 ++++++++++++++ update-app-version.js | 43 +++++++++++++++++++++++++++++++ update-chart-version.js | 2 +- 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 update-app-version.js diff --git a/.github/workflows/appversion.yaml b/.github/workflows/appversion.yaml index 64d42b4..d00a003 100644 --- a/.github/workflows/appversion.yaml +++ b/.github/workflows/appversion.yaml @@ -28,3 +28,22 @@ jobs: - name: print new latest kexa version run: echo ${{ steps.get_latest_release.outputs.release }} + - name: Run Javascript to update local files + uses: actions/setup-node@v4 + with: + node-version: '20' + run: | + npm install + node update-app-version.js "${{ steps.get_latest_release.outputs.release }}" + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + + - name: Commit and push changes to dev + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add charts/kexa-chart/Chart.yaml + git commit -m "chore(release): update Chart.yaml appversion" + git push origin dev + env: + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} diff --git a/update-app-version.js b/update-app-version.js new file mode 100644 index 0000000..f5ba943 --- /dev/null +++ b/update-app-version.js @@ -0,0 +1,43 @@ +// YAML TO JSON +// CHANGE APP 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.appVersion = 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 diff --git a/update-chart-version.js b/update-chart-version.js index e6443d1..5d46d40 100644 --- a/update-chart-version.js +++ b/update-chart-version.js @@ -1,5 +1,5 @@ // YAML TO JSON -// CHANGE VERSION +// CHANGE CHART VERSION // THEN JSON TO YAML AND WRITE TO FILE const fs = require('fs');