From 6eaf80dea6d31d3e903707fe78d2272f65d1e0de Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Fri, 7 Feb 2025 10:40:56 -0500 Subject: [PATCH] Get the increment level to the new semver Signed-off-by: Kyle Harding --- .github/workflows/flowzone.yml | 48 +++++++++++++++++++++++++++++- flowzone.yml | 54 +++++++++++++++++++++++++++++++++- 2 files changed, 100 insertions(+), 2 deletions(-) diff --git a/.github/workflows/flowzone.yml b/.github/workflows/flowzone.yml index a26680095..1cf225ff4 100644 --- a/.github/workflows/flowzone.yml +++ b/.github/workflows/flowzone.yml @@ -481,7 +481,8 @@ jobs: run: | npm install -g \ balena-versionist@~0.15.0 \ - versionist@^7.0.3 + versionist@^7.0.3 \ + semver@^7.7.1 npm ls -g - name: Generate changelog @@ -493,6 +494,30 @@ jobs: then "$(npm root -g)"/versionist/scripts/generate-changelog.sh . fi + - name: Get current version + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea + if: inputs.disable_versioning != true + id: current_version + with: + result-encoding: json + script: | + const path = require('path'); + const { execSync } = require('child_process'); + + const runPath = process.env.GITHUB_WORKSPACE; + + let version; + try { + version = await execSync('versionist get version', { + cwd: runPath, + }); + version = version.toString().trim(); + } catch (e) { + core.setFailed(e.message); + } + + console.log('Current version: ', version); + return version; - name: Run balena-versionist uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea if: inputs.disable_versioning != true @@ -524,6 +549,27 @@ jobs: core.setOutput('semver', version); core.setOutput('tag', `v${version}`); return version; + - name: Tag increment level + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea + if: inputs.disable_versioning != true + id: increment + env: + PREVIOUS_VERSION: ${{ steps.current_version.outputs.result }} + NEW_VERSION: ${{ steps.versionist.outputs.result }} + with: + result-encoding: json + script: | + const path = require('path'); + const { execSync } = require('child_process'); + + // Get global node_modules path + const globalNodeModules = execSync('npm root -g').toString().trim(); + const semver = require(path.join(globalNodeModules, 'semver')); + + const increment = semver.diff(process.env.PREVIOUS_VERSION, process.env.NEW_VERSION); + + console.log('Increment: ', increment); + return increment; - name: Create blobs and tree objects if: inputs.disable_versioning != true id: create_tree diff --git a/flowzone.yml b/flowzone.yml index aba6913e7..885143edb 100644 --- a/flowzone.yml +++ b/flowzone.yml @@ -1199,7 +1199,8 @@ jobs: run: | npm install -g \ balena-versionist@~0.15.0 \ - versionist@^7.0.3 + versionist@^7.0.3 \ + semver@^7.7.1 npm ls -g @@ -1213,6 +1214,34 @@ jobs: "$(npm root -g)"/versionist/scripts/generate-changelog.sh . fi + # Get the current version with versionist. + # Note that this does NOT include the config generated by the balena-versionist wrapper. + # Is that going to be a problem for any project types? + - name: Get current version + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 + if: inputs.disable_versioning != true + id: current_version + with: + result-encoding: json + script: | + const path = require('path'); + const { execSync } = require('child_process'); + + const runPath = process.env.GITHUB_WORKSPACE; + + let version; + try { + version = await execSync('versionist get version', { + cwd: runPath, + }); + version = version.toString().trim(); + } catch (e) { + core.setFailed(e.message); + } + + console.log('Current version: ', version); + return version; + # https://github.com/actions/github-script - name: Run balena-versionist uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 @@ -1247,6 +1276,29 @@ jobs: core.setOutput('tag', `v${version}`); return version; + # https://github.com/actions/github-script + - name: Tag increment level + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 + if: inputs.disable_versioning != true + id: increment + env: + PREVIOUS_VERSION: ${{ steps.current_version.outputs.result }} + NEW_VERSION: ${{ steps.versionist.outputs.result }} + with: + result-encoding: json + script: | + const path = require('path'); + const { execSync } = require('child_process'); + + // Get global node_modules path + const globalNodeModules = execSync('npm root -g').toString().trim(); + const semver = require(path.join(globalNodeModules, 'semver')); + + const increment = semver.diff(process.env.PREVIOUS_VERSION, process.env.NEW_VERSION); + + console.log('Increment: ', increment); + return increment; + # https://github.com/orgs/community/discussions/50055 # https://www.levibotelho.com/development/commit-a-file-with-the-github-api/ # https://octokit.github.io/rest.js/v21/#git-create-blob