Compare commits
21 Commits
v3.18.0
...
releases/v
Author | SHA1 | Date |
---|---|---|
|
2cd15c0459 | |
|
77a8952a0f | |
|
271d0f7c49 | |
|
9962c3267b | |
|
dd19d7c07e | |
|
3c841f364e | |
|
69dad781b9 | |
|
b2bec20afa | |
|
a858fade68 | |
|
84d56d6ef8 | |
|
b7f32a8347 | |
|
d479ae227c | |
|
bbae9470db | |
|
1607ac70d5 | |
|
48193b9a39 | |
|
997a172ef5 | |
|
acd95e2b8f | |
|
8a32db0dc1 | |
|
c3a1c6e042 | |
|
5a79ccfd3b | |
|
b4327fa923 |
|
@ -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"
|
||||
|
|
36
CHANGELOG.md
36
CHANGELOG.md
|
@ -1,3 +1,21 @@
|
|||
# [3.19.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.18.1...v3.19.0) (2023-06-22)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add 'infile' option ([a858fad](https://github.com/TriPSs/conventional-changelog-action/commit/a858fade68261d33b8c91977bbe3c77f1d39521d))
|
||||
|
||||
|
||||
|
||||
## [3.18.1](https://github.com/TriPSs/conventional-changelog-action/compare/v3.18.0...v3.18.1) (2023-05-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* execute git config commands synchronously ([1607ac7](https://github.com/TriPSs/conventional-changelog-action/commit/1607ac70d5942487fb67e1d412d57868d8decca9))
|
||||
|
||||
|
||||
|
||||
# [3.18.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.17.2...v3.18.0) (2022-11-29)
|
||||
|
||||
|
||||
|
@ -33,21 +51,3 @@
|
|||
|
||||
|
||||
|
||||
# [3.17.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.16.0...v3.17.0) (2022-11-02)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Add pre-release support ([14cc315](https://github.com/TriPSs/conventional-changelog-action/commit/14cc315abe788497f54c3eb3c734963ffbf6cc3e))
|
||||
|
||||
|
||||
|
||||
# [3.16.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.15.0...v3.16.0) (2022-11-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* Update action to node 16 ([08c1b12](https://github.com/TriPSs/conventional-changelog-action/commit/08c1b1237bb2dbed93fa7ecba9c334f094cb6b0b))
|
||||
|
||||
|
||||
|
||||
|
|
47
README.md
47
README.md
|
@ -15,9 +15,10 @@ This action will bump version, tag commit and generate a changelog with conventi
|
|||
- **Optional** `git-path`: Path filter for the logs. If set, only commits that match the path filter will be considered. By default, we won't use this feature(empty string).
|
||||
- **Optional** `preset`: Preset that is used from conventional commits. Default `angular`.
|
||||
- **Optional** `tag-prefix`: Prefix for the git tags. Default `v`.
|
||||
- **Optional** `input-file`: Read the changelog from this file. This will prepend the newly generated changelogs to the file's content.
|
||||
- **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `'false'` no file will be generated / updated.
|
||||
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all.
|
||||
- **Optional** `version-file`: The path to the file that contains the version to bump. Default `./package.json`.
|
||||
- **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. This input has no effect if `input-file` is used.
|
||||
- **Optional** `version-file`: The path to the file that contains the version to bump (supports comma-separated list of file paths). Default `./package.json`.
|
||||
- **Optional** `version-path`: The place inside the version file to bump. Default `version`.
|
||||
- **Optional** `skip-git-pull`: Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags. Default `'false'`.
|
||||
- **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occurred when you push `chore` commit with `angular` for example. Default `'true'`.
|
||||
|
@ -113,12 +114,19 @@ Make sure to install all required packages in the workflow before executing this
|
|||
Uses all the defaults
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
- name: Conventional Changelog Action
|
||||
uses: TriPSs/conventional-changelog-action@v3
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
```
|
||||
|
||||
Write permissions are required in order to enable `git push` when a new version is generated. In some configurations, the
|
||||
default `secrets.github_token` may not have the correct permissions. You can check your default permissions by looking at
|
||||
"Set up job" section of your GitHub action run log.
|
||||
|
||||
Overwrite everything
|
||||
|
||||
```yaml
|
||||
|
@ -234,41 +242,18 @@ Use a deploy key
|
|||
|
||||
If you'd like to contribute to this project, all you need to do is clone and install [act](https://github.com/nektos/act) this project and run:
|
||||
|
||||
> Make sure that `main: 'src/index.js'` is updated to `main: '../src/index.js'` inside the `action.yml`
|
||||
> Note: The image used is 18 gb!
|
||||
|
||||
```shell
|
||||
$ yarn install
|
||||
|
||||
# To run / test json versioning
|
||||
$ act -j test-json -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
# To run / test one specific job
|
||||
$ act -j <workflow job name> -P ubuntu-latest=catthehacker/ubuntu:full-20.04 --quiet
|
||||
# Example
|
||||
$ act -j test-json -P ubuntu-latest=catthehacker/ubuntu:full-20.04 --quiet
|
||||
|
||||
# To run / test git versioning
|
||||
$ act -j test-git -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / test git fallback versioning
|
||||
$ act -j test-git-fallback -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / test yaml versioning
|
||||
$ act -j test-yaml -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / test toml versioning
|
||||
$ act -j test-toml -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / test empty / new files test
|
||||
$ act -j test-[json/toml/yaml]-[empty/new] -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run pre-commit test
|
||||
$ act -j test-pre-commit -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / multiple files test
|
||||
$ act -j multiple-files -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run / config file path test
|
||||
$ act -j test-config-file-path -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
|
||||
# To run pre-changelog-generation test
|
||||
$ act -j test-pre-changelog-generation -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||
# To run all tests
|
||||
$ act pull_request -P ubuntu-latest=catthehacker/ubuntu:full-20.04 --quiet
|
||||
```
|
||||
|
||||
## [License](./LICENSE)
|
||||
|
|
|
@ -56,13 +56,17 @@ inputs:
|
|||
default: "v"
|
||||
required: false
|
||||
|
||||
input-file:
|
||||
description: "Read the changelog from this file. This will prepend the newly generated changelogs to the file's content"
|
||||
required: false
|
||||
|
||||
output-file:
|
||||
description: "File to output the changelog to"
|
||||
default: "CHANGELOG.md"
|
||||
required: false
|
||||
|
||||
release-count:
|
||||
description: "Number of releases to preserve in changelog"
|
||||
description: "Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. This input has no effect if input-file is used"
|
||||
default: "5"
|
||||
required: false
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "conventional-changelog-action",
|
||||
"version": "3.17.0",
|
||||
"lockfileVersion": 2,
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@actions/core": {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "conventional-changelog-action",
|
||||
"version": "3.18.0",
|
||||
"version": "3.19.0",
|
||||
"description": "Github Action that generates a changelog with the Conventional Changelog CLI",
|
||||
"keywords": [
|
||||
"actions",
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const fs = require('fs')
|
||||
const { Readable } = require('stream');
|
||||
const conventionalChangelog = require('conventional-changelog')
|
||||
|
||||
/**
|
||||
|
@ -67,12 +68,45 @@ module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCou
|
|||
* @param releaseCount
|
||||
* @param config
|
||||
* @param gitPath
|
||||
* @param infile
|
||||
* @returns {Promise<>}
|
||||
*/
|
||||
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath) => new Promise((resolve) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath)
|
||||
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath, infile) => new Promise((resolve) => {
|
||||
const changelogStream = getChangelogStream(tagPrefix, preset, version, infile ? 1 : releaseCount, config, gitPath)
|
||||
|
||||
// The default changelog output to be streamed first
|
||||
const readStreams = [changelogStream]
|
||||
|
||||
// If an input-file is provided and release count is not 0
|
||||
if (infile) {
|
||||
// The infile is read synchronously to avoid repeatedly reading newly written content while it is being written
|
||||
const buffer = fs.readFileSync(infile);
|
||||
const readableStream = Readable.from(buffer);
|
||||
// We add the stream as the next item for later pipe
|
||||
readStreams.push(readableStream)
|
||||
}
|
||||
|
||||
const writeStream = fs.createWriteStream(fileName)
|
||||
|
||||
let currentIndex = 0;
|
||||
|
||||
function pipeNextStream() {
|
||||
if (currentIndex < readStreams.length) {
|
||||
const currentStream = readStreams[currentIndex];
|
||||
|
||||
currentStream.pipe(writeStream, { end: false });
|
||||
|
||||
currentStream.once('end', () => {
|
||||
currentIndex++;
|
||||
pipeNextStream();
|
||||
});
|
||||
} else {
|
||||
// All stream pipes have completed
|
||||
writeStream.end();
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
pipeNextStream();
|
||||
|
||||
changelogStream
|
||||
.pipe(fs.createWriteStream(fileName))
|
||||
.on('finish', resolve)
|
||||
})
|
||||
|
|
|
@ -14,30 +14,33 @@ module.exports = new (class Git {
|
|||
// Make the Github token secret
|
||||
core.setSecret(githubToken)
|
||||
|
||||
const gitUserName = core.getInput('git-user-name')
|
||||
const gitUserEmail = core.getInput('git-user-email')
|
||||
const gitUrl = core.getInput('git-url')
|
||||
|
||||
// if the env is dont-use-git then we mock exec as we are testing a workflow
|
||||
if (ENV === 'dont-use-git') {
|
||||
this.exec = (command) => {
|
||||
const fullCommand = `git ${command}`
|
||||
|
||||
|
||||
console.log(`Skipping "${fullCommand}" because of test env`)
|
||||
|
||||
|
||||
if (!fullCommand.includes('git remote set-url origin')) {
|
||||
this.commandsRun.push(fullCommand)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init = async () => {
|
||||
const gitUserName = core.getInput('git-user-name')
|
||||
const gitUserEmail = core.getInput('git-user-email')
|
||||
const gitUrl = core.getInput('git-url')
|
||||
const githubToken = core.getInput('github-token')
|
||||
|
||||
// Set config
|
||||
this.config('user.name', gitUserName)
|
||||
this.config('user.email', gitUserEmail)
|
||||
await this.config('user.name', gitUserName)
|
||||
await this.config('user.email', gitUserEmail)
|
||||
|
||||
// Update the origin
|
||||
if (githubToken) {
|
||||
this.updateOrigin(`https://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`)
|
||||
await this.updateOrigin(`http://x-access-token:${githubToken}@${gitUrl}/${GITHUB_REPOSITORY}.git`)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const core = require('@actions/core')
|
||||
|
||||
const packageJsonLoc = path.resolve(core.getInput('package-json'))
|
||||
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
* Get's the project package.json
|
||||
* @return {any}
|
||||
*/
|
||||
get: () => {
|
||||
return JSON.parse(fs.readFileSync(packageJsonLoc))
|
||||
},
|
||||
|
||||
/**
|
||||
* Bumps the version in the package.json
|
||||
*
|
||||
* @param packageJson
|
||||
* @param releaseType
|
||||
* @return {*}
|
||||
*/
|
||||
bump: (packageJson, releaseType) => {
|
||||
let [major, minor, patch] = packageJson.version.split('.')
|
||||
|
||||
switch (releaseType) {
|
||||
case 'major':
|
||||
major = parseInt(major, 10) + 1
|
||||
minor = 0
|
||||
patch = 0
|
||||
break
|
||||
|
||||
case 'minor':
|
||||
minor = parseInt(minor, 10) + 1
|
||||
patch = 0
|
||||
break
|
||||
|
||||
default:
|
||||
patch = parseInt(patch, 10) + 1
|
||||
}
|
||||
|
||||
// Update the package.json with the new version
|
||||
packageJson.version = `${major}.${minor}.${patch}`
|
||||
|
||||
return packageJson
|
||||
},
|
||||
|
||||
/**
|
||||
* Update package.json
|
||||
*
|
||||
* @param packageJson
|
||||
* @return {*}
|
||||
*/
|
||||
update: (packageJson) => (
|
||||
fs.writeFileSync(packageJsonLoc, JSON.stringify(packageJson, null, 2))
|
||||
),
|
||||
|
||||
}
|
|
@ -46,6 +46,7 @@ async function run() {
|
|||
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
|
||||
const gitUrl = core.getInput('git-url')
|
||||
const gitPath = core.getInput('git-path')
|
||||
const infile = core.getInput('input-file')
|
||||
const skipCi = core.getBooleanInput('skip-ci')
|
||||
const createSummary = core.getBooleanInput('create-summary')
|
||||
const prerelease = core.getBooleanInput('pre-release')
|
||||
|
@ -72,6 +73,10 @@ async function run() {
|
|||
core.info(`Using "${preCommitFile}" as pre-commit script`)
|
||||
}
|
||||
|
||||
if (infile) {
|
||||
core.info(`Using "${infile}" as input file`)
|
||||
}
|
||||
|
||||
if (preChangelogGenerationFile) {
|
||||
core.info(`Using "${preChangelogGenerationFile}" as pre-changelog-generation script`)
|
||||
}
|
||||
|
@ -79,6 +84,8 @@ async function run() {
|
|||
core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`)
|
||||
core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`)
|
||||
|
||||
await git.init()
|
||||
|
||||
if (!skipGitPull) {
|
||||
core.info('Pull to make sure we have the full git history')
|
||||
await git.pull()
|
||||
|
@ -170,7 +177,7 @@ async function run() {
|
|||
// If output file === 'false' we don't write it to file
|
||||
if (outputFile !== 'false') {
|
||||
// Generate the changelog
|
||||
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config, gitPath)
|
||||
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config, gitPath, infile)
|
||||
}
|
||||
|
||||
if (!skipCommit) {
|
||||
|
|
|
@ -18,6 +18,7 @@ module.exports = class Json extends BaseVersioning {
|
|||
|
||||
// Parse the file
|
||||
let jsonContent
|
||||
let eol = fileContent.endsWith('\n') ? '\n' : ''
|
||||
try {
|
||||
jsonContent = JSON.parse(fileContent)
|
||||
} catch (error) {
|
||||
|
@ -45,7 +46,7 @@ module.exports = class Json extends BaseVersioning {
|
|||
|
||||
// Update the file
|
||||
this.update(
|
||||
JSON.stringify(jsonContent, null, 2),
|
||||
JSON.stringify(jsonContent, null, 2) + eol
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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')
|
|
@ -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
|
Loading…
Reference in New Issue