From b134318854a1f3ac933a0e78c89ee2cbdad8a157 Mon Sep 17 00:00:00 2001 From: Fabricio Sander <79223916+fsz-codeshop@users.noreply.github.com> Date: Thu, 1 Apr 2021 20:44:32 -0300 Subject: [PATCH] feat: adds custom tags values to generate changelog (#26) * feat: adds the option to pass from and to tags to generate changelog instead of just using latest and latest-1 * docs: adds advanced usage example * fix: fixes message when to-tag is found * fix: fixes variable value when to-tag is found * fix: fixes shell linting errors --- README.md | 18 ++++++++++++++++++ action.yml | 11 +++++++++++ entrypoint.sh | 18 ++++++++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81febbb..89a842c 100644 --- a/README.md +++ b/README.md @@ -57,5 +57,23 @@ If your `package.json` isn't available in root, you can pass the directory of th package-dir: 'root/to/my/package.json' ``` +If your use case does not need to generate changelog from latest and latest-1 tags, you can pass the custom flags. An example is when your release tag on git is generated after the changelog so you must use something like _git log v1..HEAD_ --oneline: + +```yaml + - name: Changelog + uses: scottbrenner/generate-changelog-action@master + id: Changelog + with: + package-dir: 'root/to/my/package.json' + from-tag: v1.0 + to-tag: HEAD +``` + For more information, see [actions/create-release: Usage](https://github.com/actions/create-release#usage) and [lob/generate-changelog: Usage](https://github.com/lob/generate-changelog#usage) + +| Property | Default | Description | +| ------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------- | +| 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 | diff --git a/action.yml b/action.yml index f38d459..edbd4e0 100644 --- a/action.yml +++ b/action.yml @@ -9,11 +9,22 @@ inputs: description: 'The path for the package.json if it is not in root' required: false default: 'package.json' + from-tag: + description: 'The tag to generate changelog from' + required: false + default: '' + to-tag: + description: 'The tag to generate changelog up to' + required: false + default: '' runs: using: 'docker' image: 'Dockerfile' args: - ${{ inputs.package-dir }} + env: + FROM_TAG: ${{ inputs.from-tag }} + TO_TAG: ${{ inputs.to-tag }} branding: icon: 'edit' color: 'gray-dark' diff --git a/entrypoint.sh b/entrypoint.sh index 61cc7b1..7a10af6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,8 +5,22 @@ if [ "$1" ] && [ "$1" != "package.json" ]; then cp "$1" package.json fi -previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1) -new_tag=$(git tag --sort version:refname | tail -n 1) +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." + previous_tag=$FROM_TAG +fi + +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." + new_tag=$TO_TAG +fi + changelog=$(generate-changelog -t "$previous_tag..$new_tag" --file -) changelog="${changelog//'%'/'%25'}"