Skip to content

Commit af5898d

Browse files
authored
Merge pull request #1460 from mikepenz/feature/1459
Add new `offlineMode`
2 parents 9d52499 + 6c979ed commit af5898d

16 files changed

Lines changed: 581 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ jobs:
1616
steps:
1717
- name: Checkout
1818
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 100
21+
fetch-tags: true
1922

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

38+
- name: Publish Test Report
39+
uses: mikepenz/action-junit-report@v5
40+
if: success() || failure() # always run even if the previous step fails
41+
with:
42+
report_paths: 'junit.xml'
43+
comment: true
44+
detailed_summary: true
45+
3546
test:
3647
if: github.event_name == 'pull_request'
3748
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ Depending on the use-case additional settings can be provided to the action
227227
| `fetchReleaseInformation` | Will enable fetching additional release information from tags. Default: false |
228228
| `fetchReviews` | Will enable fetching the reviews on of the PR. Default: false |
229229
| `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. |
230+
| `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 |
230231
| `exportCache` | Will enable exporting the fetched PR information to a cache, which can be re-used by later runs. Default: false |
231232
| `exportOnly` | When enabled, will result in only exporting the cache, without generating a changelog. Default: false (Requires `exportCache` to be enabled) |
232233
| `cache` | The file path to write/read the cache to/from. |

__tests__/main.test.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ clear()
1212
const __filename = fileURLToPath(import.meta.url); // get the resolved path to the file
1313
const __dirname = path.dirname(__filename); // get the name of the directory
1414

15-
test('missing values should result in failure', () => {
16-
expect.assertions(1)
15+
function resetEnv(): void {
16+
process.env['INPUT_CONFIGURATION'] = ''
17+
process.env['INPUT_OWNER'] = ''
18+
process.env['INPUT_REPO'] = ''
19+
process.env['INPUT_MODE'] = ''
20+
process.env['INPUT_OFFLINEMODE'] = ''
21+
process.env['INPUT_OUTPUTFILE'] = ''
22+
process.env['INPUT_CACHE'] = ''
23+
process.env['GITHUB_WORKSPACE'] = ''
24+
process.env['INPUT_FROMTAG'] = ''
25+
process.env['INPUT_TOTAG'] = ''
26+
}
1727

28+
test('missing values should result in failure', () => {
29+
resetEnv()
1830
process.env['GITHUB_WORKSPACE'] = '.'
1931
process.env['INPUT_OWNER'] = undefined
2032
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
@@ -23,13 +35,14 @@ test('missing values should result in failure', () => {
2335
env: process.env
2436
}
2537
try {
26-
cp.execSync(`node ${ip}`, options).toString()
38+
cp.execFileSync('node', [ip], options).toString()
2739
} catch (error: unknown) {
2840
expect(true).toBe(true)
2941
}
3042
})
3143

3244
test('complete input should succeed', () => {
45+
resetEnv()
3346
process.env['GITHUB_WORKSPACE'] = '.'
3447
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
3548
process.env['INPUT_OWNER'] = 'mikepenz'
@@ -48,8 +61,9 @@ test('complete input should succeed', () => {
4861
})
4962

5063
test('should write result to file', () => {
64+
resetEnv()
5165
process.env['GITHUB_WORKSPACE'] = '.'
52-
process.env['INPUT_CONFIGURATION'] = 'configuration.json'
66+
process.env['INPUT_CONFIGURATION'] = 'configs/configuration.json'
5367
process.env['INPUT_OWNER'] = 'mikepenz'
5468
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
5569
process.env['INPUT_FROMTAG'] = 'v0.3.0'
@@ -61,7 +75,7 @@ test('should write result to file', () => {
6175
const options: cp.ExecSyncOptions = {
6276
env: process.env
6377
}
64-
const result = cp.execSync(`node ${ip}`, options).toString()
78+
const result = cp.execFileSync('node', [ip], options).toString()
6579
// should succeed
6680
expect(result).toBeDefined()
6781

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

7286
expect(readOutput.toString()).not.toBe('')
7387
})
88+
89+
test('offline mode should work with commit mode', () => {
90+
resetEnv()
91+
// This test verifies that the offlineMode parameter is correctly passed to the configuration
92+
// and that the OfflineRepository is used when offlineMode is enabled.
93+
94+
// Set up environment variables for the test
95+
process.env['GITHUB_WORKSPACE'] = '.'
96+
process.env['INPUT_CONFIGURATION'] = 'configs/configuration_commit.json'
97+
process.env['INPUT_OWNER'] = 'mikepenz'
98+
process.env['INPUT_REPO'] = 'release-changelog-builder-action'
99+
process.env['INPUT_MODE'] = 'PR'
100+
process.env['INPUT_OFFLINEMODE'] = 'true'
101+
process.env['INPUT_OUTPUTFILE'] = 'test.md'
102+
process.env['INPUT_CACHE'] = ''
103+
104+
const ip = path.join(__dirname, '..', 'lib', 'main.js')
105+
const options: cp.ExecSyncOptions = {
106+
env: process.env
107+
}
108+
109+
const result = cp.execFileSync('node', [ip], options).toString()
110+
// should succeed
111+
expect(result).toBeDefined()
112+
113+
const readOutput = fs.readFileSync('test.md')
114+
fs.unlinkSync('test.md')
115+
116+
expect(readOutput.toString()).not.toBe("- no changes")
117+
expect(readOutput.toString()).not.toBe('')
118+
119+
console.log('Offline mode test succeeded')
120+
})
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
* @file offlineMode.test.ts
3+
* @description Test file for validating the behavior of the new offline mode feature.
4+
*
5+
* This test verifies that:
6+
* 1. The offlineMode parameter is correctly passed to the configuration
7+
* 2. The OfflineRepository is used when offlineMode is enabled
8+
* 3. Local tag and diff retrieval works correctly
9+
*
10+
* To run this test:
11+
* npm run test-offline
12+
*
13+
* Note: This test requires a local git repository with tags to work properly.
14+
*/
15+
16+
import {mergeConfiguration, resolveConfiguration} from '../../src/utils.js'
17+
import {ReleaseNotesBuilder} from '../../src/releaseNotesBuilder.js'
18+
import {OfflineRepository} from '../../src/repositories/OfflineRepository.js'
19+
import {jest} from '@jest/globals'
20+
21+
jest.setTimeout(180000)
22+
23+
// This test validates the behavior of the new offline mode
24+
test('Test offline mode functionality', async () => {
25+
// Define the configuration file to use
26+
const configuration = mergeConfiguration(undefined, resolveConfiguration('', 'configs/configuration_commit.json'))
27+
28+
// Set offlineMode to true in the configuration
29+
configuration.offlineMode = true
30+
31+
// Create an instance of OfflineRepository
32+
const offlineRepository = new OfflineRepository( '.')
33+
34+
const releaseNotesBuilder = new ReleaseNotesBuilder(
35+
null, // The base url used for the API requests (not needed for offline mode)
36+
offlineRepository, // Use the OfflineRepository implementation
37+
'.', // Root path to the checked out sources
38+
'mikepenz', // The owner of the repo to test
39+
'release-changelog-builder-action', // The repository name - using this repo itself for the test
40+
null, // fromTag - will be resolved automatically
41+
null, // toTag - will be resolved automatically
42+
false, // includeOpen - not supported in offline mode
43+
false, // failOnError
44+
false, // ignorePrePrerelease
45+
false, // fetchViaCommits - not needed in offline mode
46+
false, // fetchReviewers - not supported in offline mode
47+
false, // fetchReleaseInformation
48+
false, // fetchReviews - not supported in offline mode
49+
'COMMIT', // mode - must be COMMIT for offline mode
50+
false, // exportCache
51+
false, // exportOnly
52+
null, // cache
53+
configuration // The configuration to use
54+
)
55+
56+
// Build the changelog
57+
const changeLog = await releaseNotesBuilder.build()
58+
59+
// Verify that a changelog was generated
60+
expect(changeLog).toBeDefined()
61+
expect(changeLog).not.toBe("- no changes")
62+
expect(changeLog?.length).toBeGreaterThan(0)
63+
64+
// Log the changelog for inspection
65+
console.log('Generated changelog in offline mode:')
66+
console.log(changeLog)
67+
})

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ inputs:
4545
commitMode:
4646
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.'
4747
default: "false"
48+
offlineMode:
49+
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.'
50+
default: "false"
4851
outputFile:
4952
description: 'If defined, the changelog will get written to this file. (relative to the checkout dir)'
5053
token:

configs/configuration_commit.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"categories": [
3+
{
4+
"title": "## 🚀 Features",
5+
"labels": ["feature"]
6+
},
7+
{
8+
"title": "## 🐛 Fixes",
9+
"labels": ["fix"]
10+
},
11+
{
12+
"title": "## 🧪 Tests",
13+
"labels": ["test"]
14+
},
15+
{
16+
"title": "## Other",
17+
"labels": []
18+
}
19+
],
20+
"sort": "ASC",
21+
"template": "${{CHANGELOG}}",
22+
"pr_template": "- ${{TITLE}}",
23+
"empty_template": "- no changes",
24+
"max_pull_requests": 1000,
25+
"max_back_track_time_days": 1000
26+
}

0 commit comments

Comments
 (0)