Skip to content
This repository has been archived by the owner on Oct 10, 2021. It is now read-only.

Commit

Permalink
feat: Add support for generate-changelog's CLI options (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottBrenner authored Apr 4, 2021
1 parent 0c61c1f commit 21880ba
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ For more information, see [actions/create-release: Usage](https://github.com/act
| package-dir | package.json | The path for the package.json if it is not in root |
| from-tag | "last tag" | The tag to generate changelog from. If not set, fallbacks to git last tag -1. Ex.: v1.0 |
| to-tag | "current tag" | The tag to generate changelog up to. If not set, fallbacks to git last tag. Ex.: v2.0 |
| type | Unset | The type of changelog to generate: patch, minor, or major. If not set, fallbacks to unset. |
| exclude | Unset | Exclude selected commit types (comma separated). If not set, fallbacks to unset. |
| allow-unknown | Unset | Allow unknown commit types. If not set, fallbacks to unset. |
20 changes: 17 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,29 @@ inputs:
to-tag:
description: 'The tag to generate changelog up to'
required: false
default: ''
default: ''
type:
description: 'Type of changelog: patch, minor, or major'
required: false
default: ''
exclude:
description: 'Exclude selected commit types (comma separated)'
required: false
default: ''
allow-unknown:
description: 'Allow unknown commit types'
required: false
default: ''
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.package-dir }}
env:
PACKAGE_DIR: ${{ inputs.package-dir }}
FROM_TAG: ${{ inputs.from-tag }}
TO_TAG: ${{ inputs.to-tag }}
TYPE: ${{ inputs.type }}
EXCLUDE: ${{ inputs.exclude }}
ALLOW_UNKNOWN: ${{ inputs.allow-unknown }}
branding:
icon: 'edit'
color: 'gray-dark'
46 changes: 40 additions & 6 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,61 @@ if [ "$REPO" = "ScottBrenner/generate-changelog-action" ]; then
cd generate-changelog-action || exit
fi

if [ "$1" ] && [ "$1" != "package.json" ]; then
cp "$1" package.json
if [ -z "$PACKAGE_DIR" ]; then
echo "No path for the package.json passed. Fallbacking to root directory."
else
echo "package-dir detected. Using its value."
cp "$PACKAGE_DIR" package.json
fi

if [ -z "$FROM_TAG" ]; then
echo "No from-tag passed. Fallbacking to git previous tag."
previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1)
else
echo "From-tag detected. Using it's value."
echo "From-tag detected. Using its value."
previous_tag=$FROM_TAG
fi

if [ -z "$TO_TAG" ]; then
if [ -z "$TO_TAG" ]; then
echo "No to-tag passed. Fallbacking to git previous tag."
new_tag=$(git tag --sort version:refname | tail -n 1)
else
echo "To-tag detected. Using it's value."
echo "To-tag detected. Using its value."
new_tag=$TO_TAG
fi

changelog=$(generate-changelog -t "$previous_tag..$new_tag" --file -)
if [ -z "$TYPE" ]; then
echo "No type passed. Fallbacking to unset."
else
echo "Type detected. Using its value."
case $TYPE in
patch)
changelog_type="--patch"
;;
minor)
changelog_type="--minor"
;;
major)
changelog_type="--major"
;;
esac
fi

if [ -z "$EXCLUDE" ]; then
echo "No commit types selected to exclude. Fallbacking to unset."
else
echo "Commit types selected to exclude. Using its value."
exclude_types="--exclude $EXCLUDE"
fi

if [ -z "$ALLOW_UKNOWN" ]; then
echo "Unknown commit types not allowed."
else
echo "Allowing unknown commit types."
unknown_commits="--allow-unknown "
fi

changelog=$(generate-changelog "$changelog_type" -t "$previous_tag..$new_tag" "$exclude_types" "$unknown_commits" --file -)

changelog="${changelog//'%'/'%25'}"
changelog="${changelog//$'\n'/'%0A'}"
Expand Down

0 comments on commit 21880ba

Please sign in to comment.