Skip to content

Commit

Permalink
fix: korjaa seuraavan versionumeron päättely patchaamalla semantic-re…
Browse files Browse the repository at this point in the history
…lease (#571)
  • Loading branch information
haapamakim committed Jan 31, 2023
1 parent ccbbddc commit 48dd343
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions deployment/bin/patchSemanticRelease.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# Kopioi korjaus bugiin, jonka takia useammat alpha-channelit menevät sekaisin uutta versiota päätellessä.
# Korjaus on PR:ssä https://github.com/semantic-release/semantic-release/pull/2416.
# Koska korjausta ei ole valmiiksi saatavilla, tämä skripti patchaa semantic-releasen.

cp ./deployment/patch/get-last-release.js_patch ./deployment/node_modules/semantic-release/lib/get-last-release.js
47 changes: 47 additions & 0 deletions deployment/patch/get-last-release.js_patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const {isUndefined} = require('lodash');
const semver = require('semver');
const {makeTag, isSameChannel} = require('./utils');

/**
* Last release.
*
* @typedef {Object} LastRelease
* @property {string} version The version number of the last release.
* @property {string} gitHead The Git reference used to make the last release.
* @property {string} gitTag The git tag associated with the last release.
* @property {string} channel The channel on which of the last release was published.
* @property {string} name The name of the last release.
*/

/**
* Determine the Git tag and version of the last tagged release.
*
* - Filter out the branch tags that are not valid semantic version
* - Sort the versions
* - Retrive the highest version
*
* @param {Object} context semantic-release context.
* @param {Object} params Function parameters.
* @param {Object} params.before Find only releases with version number lower than this version.
*
* @return {LastRelease} The last tagged release or empty object if none is found.
*/
module.exports = ({branch, options: {tagFormat}}, {before} = {}) => {
const [{version, gitTag, channels} = {}] = branch.tags
.filter(
(tag) =>
((branch.type === 'prerelease' && tag.channels.some((channel) => isSameChannel(branch.channel, channel)) &&
semver
.parse(tag.version)
.prerelease.includes(branch.prerelease === true ? branch.name : branch.prerelease)) ||
!semver.prerelease(tag.version)) &&
(isUndefined(before) || semver.lt(tag.version, before))
)
.sort((a, b) => semver.rcompare(a.version, b.version));

if (gitTag) {
return {version, gitTag, channels, gitHead: gitTag, name: makeTag(tagFormat, version)};
}

return {};
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
"presynth": "rimraf build cdk.out .next",
"synth": "./deployment/node_modules/.bin/cdk $NODE_DEBUG_OPTION --app \"ts-node --project=tsconfig.cdk.json ./deployment/bin/hassu\" synth",
"destroy": "./deployment/node_modules/.bin/cdk --app \"ts-node --project=tsconfig.cdk.json ./deployment/bin/hassu\" destroy \"*\" --require-approval never",
"get-next-version": "./deployment/node_modules/.bin/semantic-release --no-ci --dryRun",
"release": "cross-env HUSKY=0 ./deployment/node_modules/.bin/semantic-release --no-ci",
"get-next-version": "./deployment/bin/patchSemanticRelease.sh && ./deployment/node_modules/.bin/semantic-release --no-ci --dryRun",
"release": "./deployment/bin/patchSemanticRelease.sh && cross-env HUSKY=0 ./deployment/node_modules/.bin/semantic-release --no-ci",
"createVelhoProjekti": "ts-node --project=backend/tsconfig.json -r dotenv/config ./backend/bin/createVelhoProjekti dotenv_config_path=.env.test",
"deleteVelhoProjekti": "ts-node --project=backend/tsconfig.json -r dotenv/config ./backend/bin/deleteVelhoProjekti dotenv_config_path=.env.test",
"e2e:test:run": "cypress run -b chrome",
Expand Down

0 comments on commit 48dd343

Please sign in to comment.