Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1f7cfd2
Make sure the header for Job Token matches the type of Tokens
gpickin Aug 25, 2023
6baecae
Reset PreRelease and BuildID when getting last version
gpickin Aug 25, 2023
0e91ac7
Fix the BuildID
gpickin Aug 26, 2023
ed339ec
Add default buildID of 0
gpickin Aug 26, 2023
64ec70f
Add more verbose debugging
gpickin Aug 26, 2023
a54ced5
Fix Verbose issue in versionInfo
gpickin Aug 26, 2023
94bf58b
Update Private-Token to Job-Token
gpickin Aug 26, 2023
36d5cad
Test different token
gpickin Aug 26, 2023
57c062a
Update gitlab token
gpickin Aug 26, 2023
00bd867
Update gitlab tokens
gpickin Aug 26, 2023
8120bb8
Clean up duplicate config
gpickin Aug 26, 2023
1f9fe31
Ensure the targetBranch is passed to ConditionsVerifier
gpickin Aug 26, 2023
22c396c
Change gitlab tokens back to CI_JOB_TOKEN
gpickin Aug 27, 2023
f7d68d6
Add NullNotesGenerator to plugins
gpickin Aug 27, 2023
f6ba53e
Add Null Notes Generator to config - reordered to sync plugins.
gpickin Aug 27, 2023
48e11aa
Clean up ReadMe
gpickin Aug 27, 2023
76c989d
Add NullChangeLogCommitter
gpickin Aug 28, 2023
693eb60
Add optional config for skipping box.json updates
gpickin Sep 5, 2023
5f45c49
Add gitlab box,json fix
gpickin Sep 6, 2023
177d469
Add options Injection
gpickin Sep 6, 2023
16fef1c
added getPackageVersion to create better starting version
gpickin Sep 22, 2023
cc8b267
Update for first versions to allow preReleaseID and buildID
gpickin Sep 22, 2023
27faff0
Fix the prerelease an buildID from past versions
gpickin Sep 22, 2023
7202acc
Fix Gitlab Fetcher Array Syntax
gpickin Sep 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ component {
"changelogFileName" = "CHANGELOG.md",
"targetBranch" = "master",
"buildCommitMessage" = "__SEMANTIC RELEASE VERSION UPDATE__",

"plugins-VerifyConditions" = "GitHubActionsConditionsVerifier@commandbox-semantic-release",
"plugins-VerifyConditions-buildTimeout" = 600, // seconds
"plugins-VerifyConditions-pollingInterval" = 5, // seconds
Expand All @@ -25,55 +24,59 @@ component {
"plugins-CommitArtifacts" = "GitHubArtifactsCommitter@commandbox-semantic-release",
"plugins-CommitArtifacts-authorName" = "CommandBox Semantic Release",
"plugins-CommitArtifacts-authorEmail" = "[email protected]",
"plugins-CommitArtifacts-commitBoxJson" = true,
"plugins-PublishRelease" = "ForgeBoxReleasePublisher@commandbox-semantic-release",
"plugins-PublicizeRelease" = "GitHubReleasePublicizer@commandbox-semantic-release"
};

binder.map( "TravisConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.TravisConditionsVerifier" );
binder.map( "NullConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullConditionsVerifier" );
binder.map( "GitLabConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabConditionsVerifier" );
binder.map( "GitHubActionsConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubActionsConditionsVerifier" );
binder.map( "ForgeBoxReleaseFetcher@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.ForgeBoxReleaseFetcher" );
binder.map( "JGitCommitsRetriever@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.JGitCommitsRetriever" );
binder.map( "ConventionalChangelogParser@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.ConventionalChangelogParser" );
binder.map( "EmojiLogCommitParser@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.EmojiLogCommitParser" );
binder.map( "DefaultCommitFilterer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.DefaultCommitFilterer" );
binder.map( "DefaultCommitAnalyzer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.DefaultCommitAnalyzer" );
binder.map( "DefaultCommitFilterer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.DefaultCommitFilterer" );
binder.map( "EmojiLogCommitAnalyzer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.EmojiLogCommitAnalyzer" );
binder.map( "NullReleaseVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullReleaseVerifier" );
binder.map( "GitHubMarkdownNotesGenerator@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubMarkdownNotesGenerator" );
binder.map( "EmojiLogCommitParser@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.EmojiLogCommitParser" );
binder.map( "FileAppendChangelogUpdater@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.FileAppendChangelogUpdater" );
binder.map( "NullArtifactsCommitter@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullArtifactsCommitter" );
binder.map( "GitHubArtifactsCommitter@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubArtifactsCommitter" );
binder.map( "ForgeBoxReleaseFetcher@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.ForgeBoxReleaseFetcher" );
binder.map( "ForgeBoxReleasePublisher@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.ForgeBoxReleasePublisher" );
binder.map( "GitHubActionsConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubActionsConditionsVerifier" );
binder.map( "GitHubArtifactsCommitter@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubArtifactsCommitter" );
binder.map( "GitHubMarkdownNotesGenerator@commandbox-semantic-release" ).
to( "#moduleMapping#.models.plugins.GitHubMarkdownNotesGenerator" );
binder.map( "GitHubReleasePublicizer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitHubReleasePublicizer" );

binder.map( "GitLabConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabConditionsVerifier" );
binder.map( "GitLabArtifactsCommitter@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabArtifactsCommitter" );
binder.map( "GitLabConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabConditionsVerifier" );
binder.map( "GitLabReleaseFetcher@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabReleaseFetcher" );
binder.map( "GitLabReleasePublicizer@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.GitLabReleasePublicizer" );
binder.map( "JGitCommitsRetriever@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.JGitCommitsRetriever" );
binder.map( "NullArtifactsCommitter@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullArtifactsCommitter" );
binder.map( "NullChangelogUpdater@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullChangelogUpdater" );
binder.map( "NullConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullConditionsVerifier" );
binder.map( "NullNotesGenerator@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullNotesGenerator" );
binder.map( "NullReleasePublisher@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullReleasePublisher" );
binder.map( "NullReleaseVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.NullReleaseVerifier" );
binder.map( "TravisConditionsVerifier@commandbox-semantic-release" )
.to( "#moduleMapping#.models.plugins.TravisConditionsVerifier" );
}

function onLoad() {
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ a struct for each of the plugin interfaces. Arbitrary keys and values can be set
via the command line.

```
box config set modules.settings.commandbox-semantic-release.plugins-VerifyConditions-buildTimeout=1000
box config set modules.commandbox-semantic-release.plugins-VerifyConditions-buildTimeout=1000
```

These values can then be used in your plugins:
Expand Down Expand Up @@ -392,10 +392,9 @@ You set your custom plugins or settings via CommandBox just prior to calling the
after_success:
- box install commandbox-semantic-release
- box config set endpoints.forgebox.APIToken=${FORGEBOX_TOKEN}
- box config set modules.settings.commandbox-semantic-release.versionPrefix = ""
- box config set modules.settings.commandbox-semantic-release.plugins-GenerateNotes = "MyCustomNotesGenerator@commandbox-semantic-release-custom-notes"
- box config set modules.commandbox-semantic-release.versionPrefix = ""
- box config set modules.commandbox-semantic-release.plugins-GenerateNotes = "MyCustomNotesGenerator@commandbox-semantic-release-custom-notes"
- box config set modules.commandbox-semantic-release.plugins-VerifyConditions="GitLabConditionsVerifier@commandbox-semantic-release"
- box config set modules.commandbox-semantic-release.plugins-GenerateNotes="GitHubMarkdownNotesGenerator@commandbox-semantic-release"
- box config set modules.commandbox-semantic-release.plugins-CommitArtifacts="GitLabArtifactsCommitter@commandbox-semantic-release"
- box config set modules.commandbox-semantic-release.plugins-PublicizeRelease="GitLabReleasePublicizer@commandbox-semantic-release"
- box semantic-release
Expand Down
48 changes: 37 additions & 11 deletions commands/semantic-release.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ component {
property name="PublicizeRelease" inject="PublicizeRelease@commandbox-semantic-release";
property name="targetBranch" inject="commandbox:moduleSettings:commandbox-semantic-release:targetBranch";

function run( dryRun = false, verbose = false, force = false, targetBranch = variables.targetBranch, preReleaseID = systemSettings.getSystemSetting( "BUILD_VERSION_PRERELEASEID", "" ), buildID = systemSettings.getSystemSetting( "BUILD_VERSION_BUILDID", "" ) ) {
function run( dryRun = false, verbose = false, force = false, targetBranch = variables.targetBranch, preReleaseID = systemSettings.getSystemSetting( "BUILD_VERSION_PRERELEASEID", "" ), buildID = systemSettings.getSystemSetting( "BUILD_VERSION_BUILDID", 0 ) ) {
if( verbose ){
print.boldWhiteOnBlackLine( "Arguments to Command" ).toConsole();
print.line( serializeJSON( arguments ) ).toConsole();
}

if ( dryRun ) {
print.line()
.boldBlackOnYellowLine( " " )
Expand All @@ -33,7 +38,7 @@ component {
if ( force ) {
print.yellowLine( "Skipping verification checks due to force flag" ).toConsole();
}
else if ( ! VerifyConditions.run( dryRun, verbose ) ) {
else if ( ! VerifyConditions.run( dryRun, verbose, arguments.targetBranch ) ) {
print.yellowLine( "Verify conditions check failed — switching to dry run mode." ).toConsole();
arguments.dryRun = true;
print.line()
Expand Down Expand Up @@ -88,7 +93,7 @@ component {
.indentedWhite( "Next release type: " )
.line( " #type# ", getTypeColor( type ) );

var nextVersion = getNextVersionNumber( lastVersion, type, preReleaseID, buildID );
var nextVersion = getNextVersionNumber( lastVersion, type, arguments.preReleaseID, arguments.buildID );
print.indentedGreen( "✓" )
.indentedWhite( "Next version number: " )
.whiteOnCyanLine( " #nextVersion# " )
Expand Down Expand Up @@ -125,7 +130,7 @@ component {
.indentedWhiteLine( "Release published" )
.toConsole();

CommitArtifacts.run( nextVersion, dryRun, verbose, targetBranch );
CommitArtifacts.run( nextVersion, dryRun, verbose, arguments.targetBranch );
print.indentedGreen( "✓" )
.indentedWhiteLine( "Artifacts committed" )
.toConsole();
Expand All @@ -136,7 +141,7 @@ component {
getPackageRepositoryURL(),
dryRun,
verbose,
targetBranch
arguments.targetBranch
);
print.indentedGreen( "✓" )
.indentedWhiteLine( "Release publicized" )
Expand Down Expand Up @@ -188,15 +193,30 @@ component {
}
}

private string function getNextVersionNumber( required string lastVersion, required string type, string preReleaseID = "", string buildID = "" ) {
private string function getPackageVersion() {
var path = fileSystemUtil.resolvePath( "" );
if ( ! packageService.isPackage( path ) ) {
return "0.0.0";
}
return packageService.readPackageDescriptor( path ).version;
}

private string function getNextVersionNumber( required string lastVersion, required string type, string preReleaseID = "", string buildID = 0 ) {
var versionInfo = semanticVersion.parseVersion( lastVersion );
versionInfo.preReleaseID = ( len( arguments.preReleaseID ) ? arguments.preReleaseID : versionInfo.preReleaseID );
versionInfo.buildID = ( len( arguments.buildID ) ? arguments.buildID : versionInfo.buildID );

if ( lastVersion == "0.0.0" ) {
versionInfo.major = 1;
versionInfo.minor = 0;
versionInfo.revision = 0;
var currentPackageVersion = getPackageVersion();
if ( currentPackageVersion != semanticVersion.parseVersion( currentPackageVersion ).major ) {
versionInfo = semanticVersion.parseVersion( currentPackageVersion );
} else {
versionInfo.major = 1;
versionInfo.minor = 0;
versionInfo.revision = 0;
versionInfo.preReleaseID = "";
versionInfo.buildID = 0;
}
versionInfo.preReleaseID = arguments.preReleaseID;
versionInfo.buildID = arguments.buildID;
return semanticVersion.getVersionAsString( versionInfo );
}

Expand All @@ -222,6 +242,12 @@ component {
versionInfo.revision += 1;
break;
}

print.boldWhiteOnBlackLine( "Version Info" ).toConsole();
print.table( [ versionInfo ] ).toConsole();

versionInfo.preReleaseID = arguments.preReleaseID;
versionInfo.buildID = arguments.buildID;
return semanticVersion.getVersionAsString( versionInfo )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the new preReleaseID and buildID, how does it generate release versions? I don't want my release versions to look like 5.1.0+0. (I don't want a buildID at all.)

As long as the buildID is completely optional, this should be good.

}

Expand Down
7 changes: 6 additions & 1 deletion models/plugins/GitHubArtifactsCommitter.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ component implements="interfaces.ArtifactsCommitter" {
.setName( targetBranch )
.call();

if( options[ "plugins-CommitArtifacts-commitBoxJson" ] == true ) {
jGit.add()
.addFilePattern( "box.json" )
.call();
}

jGit.add()
.addFilePattern( "box.json" )
.addFilePattern( changelogFileName )
.call();

Expand Down
10 changes: 8 additions & 2 deletions models/plugins/GitLabArtifactsCommitter.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ component implements="interfaces.ArtifactsCommitter" {
property name="changelogFileName" inject="commandbox:moduleSettings:commandbox-semantic-release:changelogFileName";
property name="versionPrefix" inject="commandbox:moduleSettings:commandbox-semantic-release:versionPrefix";
property name="targetBranch" inject="commandbox:moduleSettings:commandbox-semantic-release:targetBranch";

property name="options" inject="commandbox:moduleSettings:commandbox-semantic-release";

/**
* Set up jGit for the current repository.
*/
Expand Down Expand Up @@ -45,8 +46,13 @@ component implements="interfaces.ArtifactsCommitter" {
.setName( targetBranch )
.call();

if( options[ "plugins-CommitArtifacts-commitBoxJson" ] == true ) {
jGit.add()
.addFilePattern( "box.json" )
.call();
}

jGit.add()
.addFilePattern( "box.json" )
.addFilePattern( changelogFileName )
.call();

Expand Down
4 changes: 2 additions & 2 deletions models/plugins/GitLabReleaseFetcher.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ component implements="interfaces.ReleaseFetcher" {
) {
cfhttpparam(
type="header",
name="PRIVATE-TOKEN",
name="JOB-TOKEN",
value="#systemSettings.getSystemSetting( "CI_JOB_TOKEN" )#"
);
};
var res = deserializeJSON( httpResponse.filecontent );
var tag = res.isEmpty() ? "0.0.0" : res.tag_name;
var tag = res.isEmpty() ? "0.0.0" : res[1].tag_name;
return left( tag, 1 ) == "v" ? mid( tag, 2, tag.len() - 1 ) : tag;
}

Expand Down
9 changes: 7 additions & 2 deletions models/plugins/GitLabReleasePublicizer.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ component implements="interfaces.ReleasePublicizer" {
) {
cfhttpparam(
type="header",
name="PRIVATE-TOKEN",
name="Content-Type",
value="application/json"
);
cfhttpparam(
type="header",
name="JOB-TOKEN",
value="#systemSettings.getSystemSetting( "CI_JOB_TOKEN" )#"
);
cfhttpparam( type = "body", value = serializeJSON( {
"name": "#versionPrefix##nextVersion#",
"tag_name": "#versionPrefix##nextVersion#",
"ref": targetBranch,
"ref": arguments.targetBranch,
"description": notes
} ) );
}
Expand Down
29 changes: 29 additions & 0 deletions models/plugins/NullChangelogUpdater.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
component implements="interfaces.ChangelogUpdater" {

property name="print" inject="PrintBuffer";

/**
* Updates the current changelog with the new notes.
*
* @notes The notes for the new release.
* @dryRun Flag to indicate a dry run of the release.
* @verbose Flag to indicate printing out extra information.
*/
public void function run(
required string notes,
required string nextVersion,
boolean dryRun = false,
boolean verbose = false
) {

if ( verbose ) {
print.line()
.indented()
.boldBlackOnYellowLine( " NULL CHANGELOG UPDATER - NO CHANGELOG WRITTEN " )
.line()
.toConsole();
}

}

}
28 changes: 28 additions & 0 deletions models/plugins/NullNotesGenerator.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
component implements="interfaces.NotesGenerator" {

/**
* Generates markdown notes for the new release on GitHub
*
* @lastVersion The last version of the package.
* @nextVersion The next version of the package.
* @commits An array of commits between the two versions.
* @type The type of the next release: major, minor, or patch.
* @repositoryUrl The url of the remote repository.
* @dryRun Flag to indicate a dry run of the release.
* @verbose Flag to indicate printing out extra information.
*
* @return A string containing the new notes for the release.
*/
public string function run(
required string lastVersion,
required string nextVersion,
required array commits,
required string type,
required string repositoryUrl,
boolean dryRun = false,
boolean verbose = true
) {
return "";
}

}