diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cca630e..e581848 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -864,3 +864,36 @@ jobs: env: FILES: "test-file-pre-release.json" EXPECTED_VERSION: "1.5.0" + + test-input-file: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + path: "./" + + - run: npm ci --prod + + - run: "git config --global user.email 'changelog@github.com'" + - run: "git config --global user.name 'Awesome Github action'" + - run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'" + + - name: Generate changelog + id: changelog + uses: ./ + env: + ENV: "dont-use-git" + EXPECTED_TAG: "v6.5.0" + with: + input-file: "./test-input-file.md" + github-token: ${{ secrets.github_token }} + version-file: "./test-file-empty.toml" + version-path: "package.version" + fallback-version: "6.5.0" + + - name: Test output + run: node ./test-file-content.js + env: + OUTPUT_FILE: "CHANGELOG.md" + EXPECTED_FILE: "test-input-file.md" diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index 34868f0..5f4e450 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "conventional-changelog-action", - "version": "3.17.0", + "version": "3.18.1", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/test-file-content.js b/test-file-content.js new file mode 100644 index 0000000..48579be --- /dev/null +++ b/test-file-content.js @@ -0,0 +1,30 @@ +const fs = require('fs') +const assert = require('assert') +const yaml = require('yaml') + +const actionConfig = yaml.parse(fs.readFileSync('./action.yml', 'utf8')) + +const { + OUTPUT_FILE = 'CHANGELOG.md', + EXPECTED_FILE = 'test-input-file.md', +} = process.env + +assert.ok(OUTPUT_FILE, 'Output file is not defined!') +assert.ok(EXPECTED_FILE, 'Expected file is not defined!') + +/** + * Test that the generated logs match the expected output + */ +console.log(`Going to test file "${OUTPUT_FILE}" against expected "${EXPECTED_FILE}"`) + +const outputFileContent = fs.readFileSync(OUTPUT_FILE.trim(), 'utf8').split('\n'); +assert.ok(outputFileContent, 'Content could not be parsed!') +console.log(`"${OUTPUT_FILE}" has valid content`, outputFileContent) + +const expectedFileContent = fs.readFileSync(EXPECTED_FILE.trim(), 'utf8').split('\n'); +assert.ok(expectedFileContent, 'Content could not be parsed!') +console.log(`"${EXPECTED_FILE}" has valid content`, expectedFileContent) + +const linesToCompare = 11 +assert.deepStrictEqual(outputFileContent.slice(linesToCompare * -1), expectedFileContent.slice(linesToCompare * -1), 'Output-file does not contain the expected input-file content') +console.log('The input-file\'s content exists at the end of the generated logs') diff --git a/test-input-file.md b/test-input-file.md new file mode 100644 index 0000000..6efdfd3 --- /dev/null +++ b/test-input-file.md @@ -0,0 +1,11 @@ +# This is content that will remain in the changelogs throughout all future releases + +## [1.0.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.18.0...v3.18.1) (2023-05-18) + +### Features + +* Make another commit + +### Bug Fixes + +* Make a preexisting commit