diff --git a/README.md b/README.md index 89a842c..1d9fecb 100644 --- a/README.md +++ b/README.md @@ -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. | diff --git a/action.yml b/action.yml index edbd4e0..6a2172e 100644 --- a/action.yml +++ b/action.yml @@ -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' diff --git a/entrypoint.sh b/entrypoint.sh index d919668..d5d9204 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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'}"