Skip to content

Commit

Permalink
Get the increment level to the new semver
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Harding <[email protected]>
  • Loading branch information
klutchell committed Feb 7, 2025
1 parent 08dbbca commit ff981f5
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
47 changes: 45 additions & 2 deletions .github/workflows/flowzone.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 56 additions & 2 deletions flowzone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
echo "NODE_PATH=$(npm root --quiet -g)" >>"${GITHUB_ENV}"
Expand All @@ -1214,6 +1215,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: string
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
Expand All @@ -1223,7 +1252,7 @@ jobs:
# Use to authenticate with GitHub for private nested changelogs
GITHUB_TOKEN: ${{ steps.gh_app_token.outputs.token || secrets.FLOWZONE_TOKEN }}
with:
result-encoding: json
result-encoding: string
script: |
const { runBalenaVersionist } = require('balena-versionist');
Expand All @@ -1243,6 +1272,31 @@ jobs:
core.setOutput('tag', `v${version}`);
return version;
# Get the increment level between the previous and new versions.
# For example, if the previous version is 1.2.3 and the new version is 1.2.4,
# the increment level will be 'patch'.
# For rev bumps, like 1.2.3+rev1 -> 1.2.3+rev2, the increment level will be null.
# and we should default to 'patch' in this case.
# https://github.com/actions/github-script
- name: Get 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: string
script: |
const path = require('path');
const { execSync } = require('child_process');
const semver = require('semver');
const increment = semver.diff(process.env.PREVIOUS_VERSION, process.env.NEW_VERSION);
console.log('Increment: ', increment);
return increment || 'patch';
# 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
Expand Down

0 comments on commit ff981f5

Please sign in to comment.