Code Monkey home page Code Monkey logo

changelog-slack-action's Introduction

changelog-updater Action

A GitHub Action to update a changelog with the latest release notes.

The Action …

  • adds a new second level heading for the new release
  • pastes your release notes in the appropriate place in CHANGELOG.md

If your changelog follows the "Keep a Changelog" format and contains an "Unreleased"-heading, the Action will update the heading to point to the compare view between the latest version and HEAD. (Read more about this here)

Don't want to use GitHub Actions? Checkout the changelog-updater CLI that powers this Action. Want to learn more about this Action? Read my introduction blog post.

Usage

The Action is best used in a Workflow that listens to the release-event and the type released. This way, the name and body of your release will be added to the CHANGELOG.

The following is an example Workflow ready to be used.

The Workflow checks out the target branch of the release, updates the ./CHANGELOG.md-file with the name and the contents of the just released release and commits the changes back to your repository using git-auto-commit.

# .github/workflows/update-changelog.yaml
name: "Update Changelog"

on:
  release:
    types: [released]

jobs:
  update:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.release.target_commitish }}

      - name: Update Changelog
        uses: stefanzweifel/changelog-updater-action@v1
        with:
          latest-version: ${{ github.event.release.tag_name }}
          release-notes: ${{ github.event.release.body }}

      - name: Commit updated CHANGELOG
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          branch: ${{ github.event.release.target_commitish }}
          commit_message: Update CHANGELOG
          file_pattern: CHANGELOG.md

To generate the release notes automatically for you, I can recommend using the release-drafter Action.

Advanced Usage

Use Tag Date as Release Date

The following workflow is a bit more advanced. It …

  • extracts the exact release date from the git tag
  • uses the target branch of the release in the "Unreleased" compare URL
  • pushes the created commit to the target branch of the commit
Show update-changelog.yaml
# .github/workflows/update-changelog.yaml
name: "Update Changelog"

on:
  release:
    types: [released]

jobs:
  update:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        with:
          # Fetch entire history of repository to ensure relase date can be
          # extracted from commit of the given tag.
          fetch-depth: 0
          # Checkout target branch of this release. Ensures that the CHANGELOG
          # is not out of date.
          ref: ${{ github.event.release.target_commitish }}

      - name: Extract release date from git tag
        id: release_date
        run: |
          echo "::set-output name=date::$(git log -1 --date=short --format=%ad '${{ github.event.release.tag_name }}')"

      - name: Update Changelog
        uses: stefanzweifel/changelog-updater-action@v1
        with:
          # Pass extracted release date, release notes and version to the Action.
          release-date: ${{ steps.release_date.outputs.date }}
          release-notes: ${{ github.event.release.body }}
          latest-version: ${{ github.event.release.tag_name }}
          compare-url-target-revision: ${{ github.event.release.target_commitish }}

      - name: Commit updated CHANGELOG
        uses: stefanzweifel/git-auto-commit-action@v4
        with:
          # Push updated CHANGELOG to release target branch.
          branch: ${{ github.event.release.target_commitish }}
          commit_message: Update CHANGELOG
          file_pattern: CHANGELOG.md

Trigger Action on workflow_dispatch event

HannesWell uses the Action in a worfklow triggered by the workflow_dispatch: See workflow.

The workflow …

  • is manually triggered
  • builds a Java project
  • uses the content between the Unreleased and Previous Release heading as relase notes and updates the CHANGELOG.md
  • commits the changes and pushes them to GitHub
  • creates a new GitHub release and points in the release notes to the right heading for the just released version

This workflow uses the output variables generated by this Action to accomplish this task.

Inputs

Checkout action.yml for a full list of supported inputs.

Expected Changelog Formats

At minimum, the Action requires an empty CHANGELOG.md file to exist in your repository. When executed, the Action will place the release notes at the bottom of the document. If your changelog already contains a second level heading, the Action will put the release notes above previous release notes in the document.

Your changelog will look something like this:

# Changelog

## v1.1.0 - 2021-02-01

### Added

- New Feature A

## v1.0.0 - 2021-01-01

- Initial Release

If you want to learn more on how the Action determines the place for the release notes, read the the notes in the README of the CLI that powers this Action.

Outputs

The Action exposes some outputs you can further use in your workflow. The Action currently supports the following outputs:

release_compare_url

The generated compare URL for the just created relase. For example https://github.com/org/repo/compare/v1.0.0...v1.1.0. The value is only available, if the Action could generate a compare URL based on the available CHANGELOG data.

release_url_fragment

The URL fragment for the just created release. For example '#v100---2021-02-01'. You can use this to generate URLs that point to the newly created release in your CHANGELOG.

unreleased_compare_url

The generated compare URL between the latest version and the target revision. For example https://github.com/org/repo/compare/v1.0.0...HEAD. The value is only available, if the Action could generate a compare URL based on the available CHANGELOG data.

See action.yml for details.

See workflow below on how to use these output values in your workflow.

- name: Update Changelog
  uses: stefanzweifel/changelog-updater-action@v1
  id: "changelog-updater"
  with:
    # Pass extracted release date, release notes and version to the Action.
    release-date: ${{ steps.release_date.outputs.date }}
    release-notes: ${{ github.event.release.body }}
    latest-version: ${{ github.event.release.tag_name }}
    compare-url-target-revision: ${{ github.event.release.target_commitish }}

- name: "release_compare_url"
  # https://github.com/org/repo/compare/v1.0.0...v1.1.0
  run: "echo ${{ steps.changelog-updater.outputs.release_compare_url }}"

- name: "release_url_fragment"
  # #v100---2021-02-01
  run: "echo ${{ steps.changelog-updater.outputs.release_url_fragment }}"

- name: "unreleased_compare_url"
  # https://github.com/org/repo/compare/v1.0.0...HEAD
  run: "echo ${{ steps.changelog-updater.outputs.unreleased_compare_url }}"

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

We also provide major version tags to make it easier to always use the latest release of a major version. For example you can use stefanzweifel/changelog-updater-action@v1 to always use the latest release of the current major version. (More information about this here.)

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details.

changelog-slack-action's People

Contributors

stefanzweifel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.