- add new experimental OFFLINE mode which will only generate changelogs based on commits

- FIX https://github.com/mikepenz/release-changelog-builder-action/issues/1459
This commit is contained in:
Mike Penz
2025-07-13 15:05:13 +02:00
parent 9d5249982e
commit 86dff767a7
11 changed files with 336 additions and 3 deletions
+34
View File
@@ -5,6 +5,9 @@ import * as fs from 'fs'
import {clear} from '../src/transform.js'
import {jest} from '@jest/globals'
import { fileURLToPath } from 'url';
import {mergeConfiguration, resolveConfiguration} from '../src/utils.js'
import {ReleaseNotesBuilder} from '../src/releaseNotesBuilder.js'
import {OfflineRepository} from '../src/repositories/OfflineRepository.js'
jest.setTimeout(180000)
clear()
@@ -71,3 +74,34 @@ test('should write result to file', () => {
expect(readOutput.toString()).not.toBe('')
})
test('offline mode should work with commit mode', () => {
// This test verifies that the offlineMode parameter is correctly passed to the configuration
// and that the OfflineRepository is used when offlineMode is enabled.
// Set up environment variables for the test
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_OWNER'] = 'mikepenz'
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
process.env['INPUT_MODE'] = 'PR'
process.env['INPUT_OFFLINEMODE'] = 'true'
process.env['INPUT_OUTPUTFILE'] = 'test.md'
const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: process.env
}
const result = cp.execSync(`node ${ip}`, options).toString()
// should succeed
expect(result).toBeDefined()
const readOutput = fs.readFileSync('test.md')
fs.unlinkSync('test.md')
expect(readOutput.toString()).not.toBe("- no changes")
expect(readOutput.toString()).not.toBe('')
console.log('Offline mode test succeeded')
})
+67
View File
@@ -0,0 +1,67 @@
/**
* @file offlineMode.test.ts
* @description Test file for validating the behavior of the new offline mode feature.
*
* This test verifies that:
* 1. The offlineMode parameter is correctly passed to the configuration
* 2. The OfflineRepository is used when offlineMode is enabled
* 3. Local tag and diff retrieval works correctly
*
* To run this test:
* npm run test-offline
*
* Note: This test requires a local git repository with tags to work properly.
*/
import {mergeConfiguration, resolveConfiguration} from '../../src/utils.js'
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder.js'
import {OfflineRepository} from '../../src/repositories/OfflineRepository.js'
import {jest} from '@jest/globals'
jest.setTimeout(180000)
// This test validates the behavior of the new offline mode
test('Test offline mode functionality', async () => {
// Define the configuration file to use
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration_commit.json'))
// Set offlineMode to true in the configuration
configuration.offlineMode = true
// Create an instance of OfflineRepository
const offlineRepository = new OfflineRepository( '.')
const releaseNotesBuilder = new ReleaseNotesBuilder(
null, // The base url used for the API requests (not needed for offline mode)
offlineRepository, // Use the OfflineRepository implementation
'.', // Root path to the checked out sources
'mikepenz', // The owner of the repo to test
'release-changelog-builder-action', // The repository name - using this repo itself for the test
null, // fromTag - will be resolved automatically
null, // toTag - will be resolved automatically
false, // includeOpen - not supported in offline mode
false, // failOnError
false, // ignorePrePrerelease
false, // fetchViaCommits - not needed in offline mode
false, // fetchReviewers - not supported in offline mode
false, // fetchReleaseInformation
false, // fetchReviews - not supported in offline mode
'COMMIT', // mode - must be COMMIT for offline mode
false, // exportCache
false, // exportOnly
null, // cache
configuration // The configuration to use
)
// Build the changelog
const changeLog = await releaseNotesBuilder.build()
// Verify that a changelog was generated
expect(changeLog).toBeDefined()
expect(changeLog).not.toBe("- no changes")
expect(changeLog?.length).toBeGreaterThan(0)
// Log the changelog for inspection
console.log('Generated changelog in offline mode:')
console.log(changeLog)
})