📌 changelog.sh
This script automates the generation and updating of a CHANGELOG.md
file using release information fetched from GitHub. It facilitates updating the changelog based on the latest release, and optionally commits and pushes the changes to the Git repository if specified.
The script carries out the following operations:
- Load base script: Sources the
base.sh
script from thescripts
directory to leverage utility functions. - Load environment variables: Loads environment variables from a
.env
file if it exists in the project root, which may override default values. - GitHub CLI check: Ensures that the GitHub CLI (
gh
) is installed and authenticated; if not, it prompts the user to log in. - Variables Setup:
CHANGELOG_FILE_PATH
specifies the path of the changelog file, defaulting toCHANGELOG.md
. - Input Parsing:
- Flags:
-c
or--commit
: Indicates whether to commit the changelog updates.-p
or--push
: Indicates whether to push the changelog updates after committing.
- Flags:
- Changelog Update:
- Release Tag and Notes: Fetches the latest release tag and release notes using
gh release view
. - File Update: Adds or updates the changelog header, appending a new section for the latest release with its tag, release date, and notes.
- File Commit and Push (optional):
- Commits the changelog updates to the Git repository if
-c
is provided. - Pushes the changes if
-p
is also provided.
- Commits the changelog updates to the Git repository if
- Release Tag and Notes: Fetches the latest release tag and release notes using
Usage
To execute changelog.sh
, run: