Compare commits

...

32 Commits

Author SHA1 Message Date
Lee SangMin 2cd15c0459 https -> http 2023-07-11 10:19:46 +09:00
Tycho Bokdam 77a8952a0f
Merge pull request #221 from iloveitaly/improved-permission-docs
docs: improved github permissions docs
2023-07-05 09:06:32 +02:00
Michael Bianco 271d0f7c49
docs: improved github permissions docs 2023-07-04 11:44:40 -06:00
Tycho Bokdam 9962c3267b
ci: Update versioning.yml 2023-06-22 12:26:08 +02:00
Conventional Changelog Action dd19d7c07e chore(release): v3.19.0 [skip ci] 2023-06-22 10:25:14 +00:00
Tycho Bokdam 3c841f364e
ci: Update release.yml 2023-06-22 12:24:56 +02:00
Tycho Bokdam 69dad781b9
Merge pull request #220 from binomialstew/feature/infile-addition
Add 'infile' option
2023-06-22 12:22:10 +02:00
Charles Lehnert b2bec20afa test: Add test for input-file usage 2023-06-21 18:37:56 -04:00
Charles Lehnert a858fade68 feat: Add 'infile' option 2023-06-16 18:23:59 -04:00
Tycho Bokdam 84d56d6ef8
Merge pull request #203 from TriPSs/improvements
docs: Updated README with how to test action
2023-05-18 15:16:49 +02:00
Conventional Changelog Action b7f32a8347 chore(release): v3.18.1 [skip ci] 2023-05-18 13:16:31 +00:00
Tycho Bokdam d479ae227c
Merge pull request #213 from iloveitaly/sync-git-config
fix: execute git config commands synchronously
2023-05-18 15:16:11 +02:00
Michael Bianco bbae9470db
pull git config init into dedicated method 2023-05-18 06:54:29 -06:00
Michael Bianco 1607ac70d5
fix: execute git config commands synchronously
this fixes the following error I was running into:

error: could not lock config file .git/config: File exists
2023-05-17 19:33:16 -06:00
Tycho Bokdam 48193b9a39
refactor: Remove random text from README 2023-03-02 11:50:21 +01:00
Tycho Bokdam 997a172ef5
docs: Updated README with how to test action 2023-03-02 11:49:44 +01:00
Tycho Bokdam acd95e2b8f
Merge pull request #202 from skhomuti/fix-eol
Fixed end of file in package.json
2023-03-02 09:28:27 +01:00
skhomuti 8a32db0dc1 Fixed bug when end of file in package.json has changed when version bumped 2023-03-02 12:19:28 +05:00
skhomuti c3a1c6e042 Removed unused packageJson.js module 2023-03-02 12:10:01 +05:00
Tycho Bokdam 5a79ccfd3b
Merge pull request #199 from jeronimoek/fix-version-file-input-description
fix version-file input description
2023-02-19 10:53:36 +01:00
jeronimoek b4327fa923 fix version-file input description 2023-02-19 05:12:13 -03:00
Conventional Changelog Action 858fe562a4 chore(release): v3.18.0 [skip ci] 2022-11-29 06:29:57 +00:00
Tycho Bokdam b97c1606dc
Merge pull request #189 from cdotyone/releases/v3
feat: add skip-tag to skip tagging a release
2022-11-29 07:29:31 +01:00
Chris Doty d4e5a72a82 chore: make test work 2022-11-26 11:41:40 -06:00
Chris Doty f0cd1f5e56 chore: test name does not match convention 2022-11-23 17:57:38 -06:00
Chris Doty b44bf77caf chore: add unit test for skip-tag 2022-11-23 17:55:14 -06:00
cdotyab a19765d093 fix: bad reference 2022-11-17 17:00:09 -06:00
cdotyab 5838afaf08 chore: bad reference 2022-11-17 15:26:21 -06:00
cdotyab 35c4da6eed chore: bad reference 2022-11-17 14:58:04 -06:00
cdotyab 6bdc8cae1b chore: carry oldVersion from lib 2022-11-17 14:42:14 -06:00
cdotyab b1e290f44d fix: output current version if there is no new ver 2022-11-17 14:17:18 -06:00
cdotyab 22e862a0ab feat: add skip-tag to skip tagging a release 2022-11-17 14:07:56 -06:00
17 changed files with 265 additions and 157 deletions

View File

@ -295,6 +295,39 @@ jobs:
skip-commit: "true" skip-commit: "true"
git-push: "false" git-push: "false"
test-skip-tag:
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 tag | xargs git tag -d
- name: Create fake tag
run: "git tag -a 'v0.55.8' -m 'v0.55.8'"
- run: "git add . && git commit --allow-empty -m 'fix: Added fake file so version will be bumped'"
- name: Generate changelog
id: changelog
uses: ./
env:
ENV: 'dont-use-git'
EXPECTED_TAG: 'v0.55.8'
SKIPPED_COMMIT: true
EXPECTED_NO_PUSH: true
SKIPPED_TAG: true
with:
github-token: ${{ secrets.github_token }}
skip-commit: 'true'
skip-tag: 'true'
git-push: 'false'
test-yaml: test-yaml:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
@ -831,3 +864,36 @@ jobs:
env: env:
FILES: "test-file-pre-release.json" FILES: "test-file-pre-release.json"
EXPECTED_VERSION: "1.5.0" 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"

View File

@ -1,3 +1,36 @@
# [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)
### Bug Fixes
* bad reference ([a19765d](https://github.com/TriPSs/conventional-changelog-action/commit/a19765d093dc22d5007a1574c6db5d40be9ddf97))
* output current version if there is no new ver ([b1e290f](https://github.com/TriPSs/conventional-changelog-action/commit/b1e290f44d9e4e0a29d536146cf1fb073172cf9d))
### Features
* add skip-tag to skip tagging a release ([22e862a](https://github.com/TriPSs/conventional-changelog-action/commit/22e862a0ab69410642c4182cd9ee27a23d8c63a0))
## [3.17.2](https://github.com/TriPSs/conventional-changelog-action/compare/v3.17.1...v3.17.2) (2022-11-23) ## [3.17.2](https://github.com/TriPSs/conventional-changelog-action/compare/v3.17.1...v3.17.2) (2022-11-23)
@ -18,30 +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))
# [3.15.0](https://github.com/TriPSs/conventional-changelog-action/compare/v3.14.1...v3.15.0) (2022-09-20)
### Features
* Add `git-path` option ([96b4f2c](https://github.com/TriPSs/conventional-changelog-action/commit/96b4f2ca996f2193165c87e184b8a765102c814c)), closes [#178](https://github.com/TriPSs/conventional-changelog-action/issues/178)

View File

@ -15,14 +15,16 @@ 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** `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** `preset`: Preset that is used from conventional commits. Default `angular`.
- **Optional** `tag-prefix`: Prefix for the git tags. Default `v`. - **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** `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** `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. Default `./package.json`. - **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** `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-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'`. - **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'`.
- **Optional** `skip-version-file`: Do not update the version file. Default `'false'`. - **Optional** `skip-version-file`: Do not update the version file. Default `'false'`.
- **Optional** `skip-commit`: Do not create a release commit. Default `'false'`. - **Optional** `skip-commit`: Do not create a release commit. Default `'false'`.
- **Optional** `skip-tag`: Do not tag the release. Helpful for using action to check if a release is going to be made. Default `'false'`.
- **Optional** `pre-commit`: Path to the pre-commit script file. No hook by default. - **Optional** `pre-commit`: Path to the pre-commit script file. No hook by default.
- **Optional** `fallback-version`: The fallback version, if no older one can be detected, or if it is the first one. Default `'0.1.0'`. If `pre-release`is set to `true` it will default to the configured pre-release format (i.e. `'0.1.0-rc.0'`) - **Optional** `fallback-version`: The fallback version, if no older one can be detected, or if it is the first one. Default `'0.1.0'`. If `pre-release`is set to `true` it will default to the configured pre-release format (i.e. `'0.1.0-rc.0'`)
- **Optional** `config-file-path`: Path to the conventional changelog config file. If set, the preset setting will be ignored - **Optional** `config-file-path`: Path to the conventional changelog config file. If set, the preset setting will be ignored
@ -80,9 +82,11 @@ export function preTagGeneration(tag: string): string {}
``` ```
### Config-File-Path ### Config-File-Path
A config file to define the conventional commit settings. Use it if you need to override values like `issuePrefix` or `issueUrlFormat`. If you set a `config-file-path`, the `preset` setting will be ignored. Therefore use an existing config and override the values you want to adjust. A config file to define the conventional commit settings. Use it if you need to override values like `issuePrefix` or `issueUrlFormat`. If you set a `config-file-path`, the `preset` setting will be ignored. Therefore use an existing config and override the values you want to adjust.
example: example:
```javascript ```javascript
'use strict' 'use strict'
const config = require('conventional-changelog-conventionalcommits'); const config = require('conventional-changelog-conventionalcommits');
@ -92,6 +96,7 @@ module.exports = config({
"issueUrlFormat": "https://jira.example.com/browse/{{prefix}}{{id}}" "issueUrlFormat": "https://jira.example.com/browse/{{prefix}}{{id}}"
}) })
``` ```
The specified path can be relative or absolute. If it is relative, then it will be based on the `GITHUB_WORKSPACE` path. The specified path can be relative or absolute. If it is relative, then it will be based on the `GITHUB_WORKSPACE` path.
Make sure to install all required packages in the workflow before executing this action. Make sure to install all required packages in the workflow before executing this action.
@ -109,12 +114,19 @@ Make sure to install all required packages in the workflow before executing this
Uses all the defaults Uses all the defaults
```yaml ```yaml
permissions:
contents: write
- name: Conventional Changelog Action - name: Conventional Changelog Action
uses: TriPSs/conventional-changelog-action@v3 uses: TriPSs/conventional-changelog-action@v3
with: with:
github-token: ${{ secrets.github_token }} 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 Overwrite everything
```yaml ```yaml
@ -230,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: 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! > Note: The image used is 18 gb!
```shell ```shell
$ yarn install $ yarn install
# To run / test json versioning # To run / test one specific job
$ act -j test-json -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token $ 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 # To run all tests
$ act -j test-git -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token $ act pull_request -P ubuntu-latest=catthehacker/ubuntu:full-20.04 --quiet
# 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
``` ```
## [License](./LICENSE) ## [License](./LICENSE)

View File

@ -56,13 +56,17 @@ inputs:
default: "v" default: "v"
required: false 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: output-file:
description: "File to output the changelog to" description: "File to output the changelog to"
default: "CHANGELOG.md" default: "CHANGELOG.md"
required: false required: false
release-count: 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" default: "5"
required: false required: false
@ -96,6 +100,11 @@ inputs:
default: "false" default: "false"
required: false required: false
skip-tag:
description: 'Do not tag the release. Helpful for using action to check if a release is going to be made'
default: 'false'
required: false
pre-commit: pre-commit:
description: "Path to the pre-commit script file" description: "Path to the pre-commit script file"
required: false required: false

2
node_modules/.package-lock.json generated vendored
View File

@ -1,7 +1,7 @@
{ {
"name": "conventional-changelog-action", "name": "conventional-changelog-action",
"version": "3.17.0", "version": "3.17.0",
"lockfileVersion": 2, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"node_modules/@actions/core": { "node_modules/@actions/core": {

View File

@ -1,6 +1,6 @@
{ {
"name": "conventional-changelog-action", "name": "conventional-changelog-action",
"version": "3.17.2", "version": "3.19.0",
"description": "Github Action that generates a changelog with the Conventional Changelog CLI", "description": "Github Action that generates a changelog with the Conventional Changelog CLI",
"keywords": [ "keywords": [
"actions", "actions",

View File

@ -1,4 +1,5 @@
const fs = require('fs') const fs = require('fs')
const { Readable } = require('stream');
const conventionalChangelog = require('conventional-changelog') const conventionalChangelog = require('conventional-changelog')
/** /**
@ -67,12 +68,45 @@ module.exports.generateStringChangelog = (tagPrefix, preset, version, releaseCou
* @param releaseCount * @param releaseCount
* @param config * @param config
* @param gitPath * @param gitPath
* @param infile
* @returns {Promise<>} * @returns {Promise<>}
*/ */
module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath) => new Promise((resolve) => { module.exports.generateFileChangelog = (tagPrefix, preset, version, fileName, releaseCount, config, gitPath, infile) => new Promise((resolve) => {
const changelogStream = getChangelogStream(tagPrefix, preset, version, releaseCount, config, gitPath) 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)
}) })

View File

@ -14,10 +14,6 @@ module.exports = new (class Git {
// Make the Github token secret // Make the Github token secret
core.setSecret(githubToken) 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 the env is dont-use-git then we mock exec as we are testing a workflow
if (ENV === 'dont-use-git') { if (ENV === 'dont-use-git') {
this.exec = (command) => { this.exec = (command) => {
@ -30,14 +26,21 @@ module.exports = new (class Git {
} }
} }
} }
}
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 // Set config
this.config('user.name', gitUserName) await this.config('user.name', gitUserName)
this.config('user.email', gitUserEmail) await this.config('user.email', gitUserEmail)
// Update the origin // Update the origin
if (githubToken) { 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`)
} }
} }
@ -160,7 +163,7 @@ module.exports = new (class Git {
*/ */
testHistory = (branch) => { testHistory = (branch) => {
if (ENV === 'dont-use-git') { if (ENV === 'dont-use-git') {
const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_PULL, SKIP_CI } = process.env const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_TAG, SKIPPED_PULL, SKIP_CI } = process.env
const expectedCommands = [ const expectedCommands = [
'git config user.name "Conventional Changelog Action"', 'git config user.name "Conventional Changelog Action"',
@ -181,7 +184,9 @@ module.exports = new (class Git {
} }
} }
if(!SKIPPED_TAG) {
expectedCommands.push(`git tag -a ${EXPECTED_TAG} -m "${EXPECTED_TAG}"`) expectedCommands.push(`git tag -a ${EXPECTED_TAG} -m "${EXPECTED_TAG}"`)
}
if (!EXPECTED_NO_PUSH) { if (!EXPECTED_NO_PUSH) {
expectedCommands.push(`git push origin ${branch} --follow-tags`) expectedCommands.push(`git push origin ${branch} --follow-tags`)

View File

@ -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))
),
}

View File

@ -41,10 +41,12 @@ async function run() {
const skipVersionFile = core.getBooleanInput('skip-version-file') const skipVersionFile = core.getBooleanInput('skip-version-file')
const skipCommit = core.getBooleanInput('skip-commit') const skipCommit = core.getBooleanInput('skip-commit')
const skipEmptyRelease = core.getBooleanInput('skip-on-empty') const skipEmptyRelease = core.getBooleanInput('skip-on-empty')
const skipTag = core.getBooleanInput('skip-tag')
const conventionalConfigFile = core.getInput('config-file-path') const conventionalConfigFile = core.getInput('config-file-path')
const preChangelogGenerationFile = core.getInput('pre-changelog-generation') const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
const gitUrl = core.getInput('git-url') const gitUrl = core.getInput('git-url')
const gitPath = core.getInput('git-path') const gitPath = core.getInput('git-path')
const infile = core.getInput('input-file')
const skipCi = core.getBooleanInput('skip-ci') const skipCi = core.getBooleanInput('skip-ci')
const createSummary = core.getBooleanInput('create-summary') const createSummary = core.getBooleanInput('create-summary')
const prerelease = core.getBooleanInput('pre-release') const prerelease = core.getBooleanInput('pre-release')
@ -71,6 +73,10 @@ async function run() {
core.info(`Using "${preCommitFile}" as pre-commit script`) core.info(`Using "${preCommitFile}" as pre-commit script`)
} }
if (infile) {
core.info(`Using "${infile}" as input file`)
}
if (preChangelogGenerationFile) { if (preChangelogGenerationFile) {
core.info(`Using "${preChangelogGenerationFile}" as pre-changelog-generation script`) core.info(`Using "${preChangelogGenerationFile}" as pre-changelog-generation script`)
} }
@ -78,6 +84,8 @@ async function run() {
core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`) core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`)
core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`) core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`)
await git.init()
if (!skipGitPull) { if (!skipGitPull) {
core.info('Pull to make sure we have the full git history') core.info('Pull to make sure we have the full git history')
await git.pull() await git.pull()
@ -99,6 +107,7 @@ async function run() {
} }
let newVersion let newVersion
let oldVersion
// If skipVersionFile or skipCommit is true we use GIT to determine the new version because // If skipVersionFile or skipCommit is true we use GIT to determine the new version because
// skipVersionFile can mean there is no version file and skipCommit can mean that the user // skipVersionFile can mean there is no version file and skipCommit can mean that the user
@ -113,6 +122,7 @@ async function run() {
) )
newVersion = versioning.newVersion newVersion = versioning.newVersion
oldVersion = versioning.oldVersion
} else { } else {
const files = versionFile.split(',').map((f) => f.trim()) const files = versionFile.split(',').map((f) => f.trim())
@ -128,6 +138,7 @@ async function run() {
) )
newVersion = versioning[0].newVersion newVersion = versioning[0].newVersion
oldVersion = versioning[0].oldVersion
} }
let gitTag = `${tagPrefix}${newVersion}` let gitTag = `${tagPrefix}${newVersion}`
@ -156,6 +167,7 @@ async function run() {
if (skipEmptyRelease && cleanChangelog === '') { if (skipEmptyRelease && cleanChangelog === '') {
core.info('Generated changelog is empty and skip-on-empty has been activated so we skip this step') core.info('Generated changelog is empty and skip-on-empty has been activated so we skip this step')
core.setOutput('version', oldVersion)
core.setOutput('skipped', 'true') core.setOutput('skipped', 'true')
return return
} }
@ -165,7 +177,7 @@ async function run() {
// If output file === 'false' we don't write it to file // If output file === 'false' we don't write it to file
if (outputFile !== 'false') { if (outputFile !== 'false') {
// Generate the changelog // 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) { if (!skipCommit) {
@ -187,7 +199,10 @@ async function run() {
} }
// Create the new tag // Create the new tag
if (!skipTag)
await git.createTag(gitTag) await git.createTag(gitTag)
else
core.info('We not going to the tag the GIT changes')
if (gitPush) { if (gitPush) {
try { try {

View File

@ -9,6 +9,7 @@ module.exports = class BaseVersioning {
newVersion = null newVersion = null
oldVersion = null
/** /**
* Set some basic configurations * Set some basic configurations
* *

View File

@ -12,12 +12,12 @@ module.exports = class Git extends BaseVersioning {
const prerelease = core.getBooleanInput('pre-release') const prerelease = core.getBooleanInput('pre-release')
gitSemverTags({ tagPrefix, skipUnstable: !prerelease }, async (err, tags) => { gitSemverTags({ tagPrefix, skipUnstable: !prerelease }, async (err, tags) => {
const currentVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null this.oldVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null
// Get the new version // Get the new version
this.newVersion = await bumpVersion( this.newVersion = await bumpVersion(
releaseType, releaseType,
currentVersion, this.oldVersion,
) )
// We are done // We are done

View File

@ -18,6 +18,7 @@ module.exports = class Json extends BaseVersioning {
// Parse the file // Parse the file
let jsonContent let jsonContent
let eol = fileContent.endsWith('\n') ? '\n' : ''
try { try {
jsonContent = JSON.parse(fileContent) jsonContent = JSON.parse(fileContent)
} catch (error) { } catch (error) {
@ -30,22 +31,22 @@ module.exports = class Json extends BaseVersioning {
} }
// Get the old version // Get the old version
const oldVersion = objectPath.get(jsonContent, this.versionPath, null) this.oldVersion = objectPath.get(jsonContent, this.versionPath, null)
// Get the new version // Get the new version
this.newVersion = await bumpVersion( this.newVersion = await bumpVersion(
releaseType, releaseType,
oldVersion, this.oldVersion,
) )
core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`) core.info(`Bumped file "${this.fileLocation}" from "${this.oldVersion}" to "${this.newVersion}"`)
// Update the content with the new version // Update the content with the new version
objectPath.set(jsonContent, this.versionPath, this.newVersion) objectPath.set(jsonContent, this.versionPath, this.newVersion)
// Update the file // Update the file
this.update( this.update(
JSON.stringify(jsonContent, null, 2), JSON.stringify(jsonContent, null, 2) + eol
) )
} }

View File

@ -17,25 +17,25 @@ module.exports = class Toml extends BaseVersioning {
// Read the file // Read the file
const fileContent = this.read() const fileContent = this.read()
const tomlContent = toml.parse(fileContent) const tomlContent = toml.parse(fileContent)
const oldVersion = objectPath.get(tomlContent, this.versionPath, null) this.oldVersion = objectPath.get(tomlContent, this.versionPath, null)
// Get the new version // Get the new version
this.newVersion = await bumpVersion( this.newVersion = await bumpVersion(
releaseType, releaseType,
oldVersion, this.oldVersion,
) )
// Update the file // Update the file
if (oldVersion) { if (this.oldVersion) {
// Get the name of where the version is in // Get the name of where the version is in
const versionName = this.versionPath.split('.').pop() const versionName = this.versionPath.split('.').pop()
core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`) core.info(`Bumped file "${this.fileLocation}" from "${this.oldVersion}" to "${this.newVersion}"`)
this.update( this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments // We use replace instead of yaml.stringify so we can preserve white spaces and comments
fileContent.replace( fileContent.replace(
`${versionName} = "${oldVersion}"`, `${versionName} = "${this.oldVersion}"`,
`${versionName} = "${this.newVersion}"`, `${versionName} = "${this.newVersion}"`,
), ),
) )

View File

@ -17,32 +17,32 @@ module.exports = class Yaml extends BaseVersioning {
// Read the file // Read the file
const fileContent = this.read() const fileContent = this.read()
const yamlContent = yaml.parse(fileContent) || {} const yamlContent = yaml.parse(fileContent) || {}
const oldVersion = objectPath.get(yamlContent, this.versionPath, null) this.oldVersion = objectPath.get(yamlContent, this.versionPath, null)
// Get the new version // Get the new version
this.newVersion = await bumpVersion( this.newVersion = await bumpVersion(
releaseType, releaseType,
oldVersion, this.oldVersion,
) )
// Update the file // Update the file
if (oldVersion) { if (this.oldVersion) {
// Get the name of where the version is in // Get the name of where the version is in
const versionName = this.versionPath.split('.').pop() const versionName = this.versionPath.split('.').pop()
core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`) core.info(`Bumped file "${this.fileLocation}" from "${this.oldVersion}" to "${this.newVersion}"`)
this.update( this.update(
// We use replace instead of yaml.stringify so we can preserve white spaces and comments // We use replace instead of yaml.stringify so we can preserve white spaces and comments
// Replace if version was used with single quotes // Replace if version was used with single quotes
fileContent.replace( fileContent.replace(
`${versionName}: '${oldVersion}'`, `${versionName}: '${this.oldVersion}'`,
`${versionName}: '${this.newVersion}'`, `${versionName}: '${this.newVersion}'`,
).replace( // Replace if version was used with double quotes ).replace( // Replace if version was used with double quotes
`${versionName}: "${oldVersion}"`, `${versionName}: "${this.oldVersion}"`,
`${versionName}: "${this.newVersion}"`, `${versionName}: "${this.newVersion}"`,
).replace( // Replace if version was used with no quotes ).replace( // Replace if version was used with no quotes
`${versionName}: ${oldVersion}`, `${versionName}: ${this.oldVersion}`,
`${versionName}: ${this.newVersion}`, `${versionName}: ${this.newVersion}`,
), ),
) )

View File

@ -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')

11
test-input-file.md 100644
View File

@ -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