Conventional Changelog Action

repository·releases/v6·Indexed 43 days ago

https://github.com/tripss/conventional-changelog-action

A GitHub Action (version 6.5.0) that automates the release process by bumping versions, creating git tags, and generating changelogs based on Conventional Commits using the Conventional Changelog CLI.

Tokens
2.9K
Snippets
8
Records
11
Agent score
56%

What's inside Conventional Changelog Action

  1. Quickstart: Use Conventional Changelog Action

    releases/v6

    This GitHub Action automates version bumping, git tagging, and changelog generation based on conventional commits.

    Note: You must grant contents: write permissions to the GITHUB_TOKEN in your workflow to allow the action to push changes and tags back to the repository.

    permissions:
      contents: write
    
    steps:
      - name: Conventional Changelog Action
        uses: TriPSs/conventional-changelog-action@v5
        with:
          github-token: ${{ secrets.github_token }}
  2. Use custom configuration via config-file-path

    releases/v6

    If you need to override specific conventional commit settings (like issuePrefixes or issueUrlFormat), provide a path to a configuration file using the config-file-path input. Note that providing this input will cause the preset input to be ignored. You must ensure the required configuration packages are installed in your workflow before the action runs.

    'use strict'
    const config = require('conventional-changelog-conventionalcommits');
    
    module.exports = config({
        "issuePrefixes": ["TN-"],
        "issueUrlFormat": "https://jira.example.com/browse/{{prefix}}{{id}}"
    })
  3. Example: Create a GitHub Release using action outputs

    releases/v6

    You can use the clean_changelog output to automatically populate the body of a GitHub Release. Use the skipped output to ensure the release step only runs if a new version was actually generated.

    - name: Conventional Changelog Action
      id: changelog
      uses: TriPSs/conventional-changelog-action@v5
      with:
        github-token: ${{ secrets.github_token }}
        output-file: "false"
    
    - name: Create Release
      uses: actions/create-release@v1
      if: ${{ steps.changelog.outputs.skipped == 'false' }}
      env:
        GITHUB_TOKEN: ${{ secrets.github_token }}
      with:
        tag_name: ${{ steps.changelog.outputs.tag }}
        release_name: ${{ steps.changelog.outputs.tag }}
        body: ${{ steps.changelog.outputs.clean_changelog }}
  4. Implement a Pre-Commit hook

    releases/v6

    A pre-commit hook allows you to run custom logic (like chores or file updates) after the version is determined but before the release commit is created.

    Requirements:

    • The script must be a CommonJS module.
    • It must export a single function: exports.preCommit.
    • The function can be async but must not return a value.
    • The script must be bundled with all its dependencies.

    Props passed to preCommit:

    • tag: The next git tag (e.g., v1.12.3).
    • version: The next version (e.g., 1.12.3).
    interface Props {
      tag: string; // Next tag e.g. v1.12.3
      version: string; // Next version e.g. 1.12.3
    }
    
    export function preCommit(props: Props): void {}
  5. Implement Pre-Changelog-Generation hooks

    releases/v6

    These hooks allow you to modify the version or the tag before the changelog is generated. This is useful for manual overrides.

    Requirements:

    • Must be a CommonJS module.
    • Must be bundled with dependencies.

    Exported Functions:

    • preVersionGeneration(version: string): string: Returns the modified version string.
    • preTagGeneration(tag: string): string: Returns the modified tag string.
    // Next version e.g. 1.12.3
    export function preVersionGeneration(version: string): string {}
    
    // Next tag e.g. v1.12.3
    export function preTagGeneration(tag: string): string {}
  6. Access Action Outputs

    releases/v6

    The action provides the following outputs which can be used in subsequent workflow steps:

    • changelog: The full generated changelog for the new version.
    • clean_changelog: The generated changelog without the version header (ideal for GitHub Release bodies).
    • version: The new version string.
    • tag: The name of the generated git tag.
    • skipped: A boolean string ('true' or 'false') indicating if the action was skipped (e.g., due to skip-on-empty).
  7. Configure Conventional Changelog Action inputs

    releases/v6

    The action is highly configurable via the following inputs:

    InputDescription
    github-tokenGitHub token (required for pushing changes).
    git-messageCommit message for the changelog commit.
    git-user-nameGit user name (Default: Conventional Changelog Action).
    git-user-emailGit user email (Default: conventional.changelog.action@github.com).
    git-branchBranch to push to (Default: ${{ github.ref }}).
    git-pushWhether to push changes (Default: true).
    presetConventional commit preset (Default: angular). Supports conventionalcommits if installed.
    tag-prefixPrefix for git tags (Default: v).
    output-fileFile to write the changelog to (Default: CHANGELOG.md). Set to 'false' to skip file generation.
    input-fileFile to prepend new changelogs to.
    release-countNumber of releases to keep (Default: 5). Use 0 to regenerate all.
    version-filePath to version file (Default: ./package.json). Supports .yml, .yaml, .toml, .json, .properties, mix.exs.
    version-pathKey inside the version file to bump (Default: version).
    skip-git-pullIf 'true', prevents pulling remote changes before tagging.
    skip-on-emptyIf 'true', skips release if no changelog is generated (Default: 'true').
    skip-version-fileIf 'true', does not update the version file.
    skip-commitIf 'true', does not create a release commit.
    skip-tagIf 'true', does not create a git tag.
    pre-commitPath to a custom pre-commit script.
    pre-changelog-generationPath to a custom pre-changelog-generation script.
    config-file-pathPath to a custom conventional changelog config file. Overrides preset.
    pre-releaseMarks release as pre-release (Default: false).
    pre-release-identifierIdentifier for pre-releases (Default: rc).
    pre-release-smart-bumpEnables smart bumping for pre-releases.
    skip-bumpPrevents version bumping.
    create-summaryAdds changelog to GitHub Action Summary (Default: false).
    no-verifyUses --no-verify for git commits (Default: 'false').
  8. Select a versioning strategy by file extension

    releases/v6

    The module exports a function that returns a versioning strategy instance based on the provided file extension. This allows the action to handle different configuration formats (like JSON, YAML, or TOML) or versioning sources (like Git or Mix) using a unified interface.

    Supported extensions:

    • json -> Json strategy
    • yaml or yml -> Yaml strategy
    • toml -> Toml strategy
    • git -> Git strategy
    • exs -> Mix strategy
    • properties -> Properties strategy

    If the extension is not recognized, the function throws an error.

    const getVersioningStrategy = require('./src/version/index.js');
    
    // Example usage:
    const strategy = getVersioningStrategy('json', 'package.json');
  9. Generate a changelog as a string with generateStringChangelog

    releases/v6

    Use generateStringChangelog to generate the changelog content as a single string. This is useful when you need to manipulate the changelog text in memory before saving it or sending it elsewhere.

    Parameters:

    • tagPrefix: The prefix used in git tags.
    • preset: The conventional changelog preset to use.
    • version: The version to generate the changelog for.
    • releaseCount: Number of releases to include.
    • config: Configuration object containing parserOpts and writerOpts.
    • gitPath: Path to the git executable.
    • skipUnstable: Boolean flag to skip unstable releases.
    const { generateStringChangelog } = require('./src/helpers/generateChangelog');
    
    const changelog = await generateStringChangelog(
      'v',          // tagPrefix
      'angular',    // preset
      '1.0.0',      // version
      5,            // releaseCount
      {             // config
        parserOpts: {},
        writerOpts: {}
      },
      '',           // gitPath
      false         // skipUnstable
    );
  10. Generate a changelog file with generateFileChangelog

    releases/v6

    Use generateFileChangelog to write the changelog directly to a file. This function supports appending to an existing changelog file if an infile is provided.

    Parameters:

    • tagPrefix: The prefix used in git tags.
    • preset: The conventional changelog preset to use.
    • version: The version to generate the changelog for.
    • fileName: The destination file path where the changelog will be written.
    • releaseCount: Number of releases to include.
    • config: Configuration object containing parserOpts and writerOpts.
    • gitPath: Path to the git executable.
    • skipUnstable: Boolean flag to skip unstable releases.
    • infile: (Optional) The path to an existing changelog file. If provided, the new changelog content will be appended to the content of this file.
    const { generateFileChangelog } = require('./src/helpers/generateChangelog');
    
    // To append to an existing CHANGELOG.md
    await generateFileChangelog(
      'v', 
      'angular', 
      '1.0.0', 
      'CHANGELOG.md', // fileName
      5, 
      { parserOpts: {}, writerOpts: {} }, 
      '', 
      false, 
      'CHANGELOG.md'  // infile
    );
  11. Use Action Outputs in workflows

    releases/v6

    The action provides several outputs that can be used by subsequent steps in your GitHub Actions workflow (e.g., to create a GitHub Release):

    • changelog: The full generated changelog string.
    • clean_changelog: The changelog with the first three lines (usually header/metadata) removed.
    • version: The new version number (e.g., 1.2.3).
    • old_version: The version number before the bump.
    • tag: The full git tag (including prefix, e.g., v1.2.3).
    • skipped: Set to 'true' if the release was skipped because the changelog was empty and skip-on-empty was enabled.