Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100
fetch-tags: true

- name: Set Node.js 20.x
uses: actions/setup-node@v4
Expand All @@ -32,6 +35,14 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish Test Report
uses: mikepenz/action-junit-report@v5
if: success() || failure() # always run even if the previous step fails
with:
report_paths: 'junit.xml'
comment: true
detailed_summary: true

test:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ Depending on the use-case additional settings can be provided to the action
| `fetchReleaseInformation` | Will enable fetching additional release information from tags. Default: false |
| `fetchReviews` | Will enable fetching the reviews on of the PR. Default: false |
| `mode` | Defines the mode used to retrieve the information. Available options: [`PR`, `COMMIT`, `HYBRID`]. Defaults to `PR`. Hybrid mode treats commits like pull requests. Commit mode is a special configuration for projects which work without PRs. Uses commit messages as changelog. This mode looses access to information only available for PRs. Formerly set as `commitMode: true`, this setting is now deprecated and should be converted to `mode: "COMMIT"`. Note: the commit or hybrid modes are not fully supported. |
| `offlineMode` | [EXPERIMENTAL] Enables offline mode which disables API requests to GitHub or Gitea. Only works with commitMode and retrieves tags and diffs from the local repository. Default: false |
| `exportCache` | Will enable exporting the fetched PR information to a cache, which can be re-used by later runs. Default: false |
| `exportOnly` | When enabled, will result in only exporting the cache, without generating a changelog. Default: false (Requires `exportCache` to be enabled) |
| `cache` | The file path to write/read the cache to/from. |
Expand Down
57 changes: 52 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@ clear()
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
const __dirname = path.dirname(__filename); // get the name of the directory

test('missing values should result in failure', () => {
expect.assertions(1)
function resetEnv(): void {
process.env['INPUT_CONFIGURATION'] = ''
process.env['INPUT_OWNER'] = ''
process.env['INPUT_REPO'] = ''
process.env['INPUT_MODE'] = ''
process.env['INPUT_OFFLINEMODE'] = ''
process.env['INPUT_OUTPUTFILE'] = ''
process.env['INPUT_CACHE'] = ''
process.env['GITHUB_WORKSPACE'] = ''
process.env['INPUT_FROMTAG'] = ''
process.env['INPUT_TOTAG'] = ''
}

test('missing values should result in failure', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_OWNER'] = undefined
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
Expand All @@ -23,13 +35,14 @@ test('missing values should result in failure', () => {
env: process.env
}
try {
cp.execSync(`node ${ip}`, options).toString()
cp.execFileSync('node', [ip], options).toString()
} catch (error: unknown) {
expect(true).toBe(true)
}
})

test('complete input should succeed', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_OWNER'] = 'mikepenz'
Expand All @@ -48,8 +61,9 @@ test('complete input should succeed', () => {
})

test('should write result to file', () => {
resetEnv()
process.env['GITHUB_WORKSPACE'] = '.'
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
process.env['INPUT_OWNER'] = 'mikepenz'
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
process.env['INPUT_FROMTAG'] = 'v0.3.0'
Expand All @@ -61,7 +75,7 @@ test('should write result to file', () => {
const options: cp.ExecSyncOptions = {
env: process.env
}
const result = cp.execSync(`node ${ip}`, options).toString()
const result = cp.execFileSync('node', [ip], options).toString()
// should succeed
expect(result).toBeDefined()

Expand All @@ -71,3 +85,36 @@ test('should write result to file', () => {

expect(readOutput.toString()).not.toBe('')
})

test('offline mode should work with commit mode', () => {
resetEnv()
// 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'] = 'configs/configuration_commit.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'
process.env['INPUT_CACHE'] = ''

const ip = path.join(__dirname, '..', 'lib', 'main.js')
const options: cp.ExecSyncOptions = {
env: process.env
}

const result = cp.execFileSync('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 changes: 67 additions & 0 deletions __tests__/offline/offlineMode.test.ts
Original file line number Diff line number Diff line change
@@ -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)
})
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ inputs:
commitMode:
description: '[Deprecated] Enables the commit based mode. This mode generates changelogs based on the commits. Please note that this lacks a lot of features only possible with PRs.'
default: "false"
offlineMode:
description: 'Enables offline mode which disables API requests to GitHub or Gitea. Only works with commitMode and retrieves tags and diffs from the local repository.'
default: "false"
outputFile:
description: 'If defined, the changelog will get written to this file. (relative to the checkout dir)'
token:
Expand Down
26 changes: 26 additions & 0 deletions configs/configuration_commit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": ["feature"]
},
{
"title": "## 🐛 Fixes",
"labels": ["fix"]
},
{
"title": "## 🧪 Tests",
"labels": ["test"]
},
{
"title": "## Other",
"labels": []
}
],
"sort": "ASC",
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}}",
"empty_template": "- no changes",
"max_pull_requests": 1000,
"max_back_track_time_days": 1000
}
Loading
Loading