Skip to content

Commit

Permalink
[FIX] config: Fix the action version extractor
Browse files Browse the repository at this point in the history
the tool 'parse_message' was using an incorrect regex to capture the
version of the release. It specifically pose problem with the master
release for which the `alpha` tag was not considered, implying that 2
consecutive master release would have the same tag, which crashes and
ultimately prevent further steps of the github action, like the
publication on NPM.

We can rather rely on the information of the package.json file since
it's properly updated.

closes #2134

X-original-commit: 5d7964c
Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
Signed-off-by: Rémi Rahir (rar) <[email protected]>
  • Loading branch information
rrahir committed Mar 1, 2023
1 parent 162451a commit 38af160
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions tools/parse_message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
/**
* This script is used to parse the a commit message and extract the release version as well as the changelog
* in the form of the commit body. It is therefore the responsibility of the developer that creates the release
* commit to properly document the changes in the commit message.
*
* The commit message should follow the following format:
* - the first line should contain the version number in the form of (saas-)<major>.<minor>.<patch>
* - each subsequent line should contain a tag in the form of [TAG]
*
* Note that every line that does not match the above format will be ignored.
*
*
* The script is used in the release workflow and as such, relies on the GitHub API to retrieve the commit message.
* It uses @action/core and @action/github in order to access to the workflow commands
* and octokit REST client to interact with the GitHub API.
*
* See https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action
* https://docs.github.com/en/actions/creating-actions/creating-a-javascript-action#adding-actions-toolkit-packages
*
* This script and the parent workflow can be tested locally by using the test environment provided here:
* https://github.com/nektos/act
*/

const core = require("@actions/core");
const github = require("@actions/github");
const path = require("path");

const package = require(path.join(__dirname, "../package.json"));

function trim(array) {
while (["", "\n"].includes(array[0])) {
Expand All @@ -9,26 +35,23 @@ function trim(array) {
array.pop();
}
}

const COMMIT_REGEX = /\[[A-Z]{3}\]/;
const RELEASE_REGEX = /(?:saas-)?\d+\.\d+\.\d+/;

/** wrap in try catch for early exit */
try {
/** @type {String} */
const commit_message = github.context.payload.head_commit.message;
let lines = commit_message.split("\n");
//pop title
const title = lines.shift();

let version = title.match(RELEASE_REGEX);
// throw if no version
version = version[0];

// purge non commit lines
lines = lines.filter((line) => {
return !!line.match(COMMIT_REGEX);
});
trim(lines);
const commitLines = lines.filter((line) => !!line.match(COMMIT_REGEX));
trim(commitLines);

// find version
const version = package.version;

console.log(
JSON.stringify({
title,
Expand Down

0 comments on commit 38af160

Please sign in to comment.