From f2a1dd22e5c605cb500f78c2a7c555c12cb9a46a Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Fri, 26 Mar 2021 18:20:56 -0300 Subject: [PATCH 1/5] feat: adds the option to pass from and to tags to generate changelog instead of just using latest and latest-1 --- README.md | 6 ++++++ action.yml | 11 +++++++++++ entrypoint.sh | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 81febbb..76feddb 100644 --- a/README.md +++ b/README.md @@ -59,3 +59,9 @@ If your `package.json` isn't available in root, you can pass the directory of th 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..1bc2e61 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,8 +5,8 @@ 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) +[ -z "$FROM_TAG" ] && { echo "No from-tag passed. Fallbacking to git previous tag."; previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1); } || { echo "From-tag detected. Using it's value."; previous_tag=$FROM_TAG; } +[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "From-tag detected. Using it's value."; new_tag=$FROM_TAG; } changelog=$(generate-changelog -t "$previous_tag..$new_tag" --file -) changelog="${changelog//'%'/'%25'}" From c08b29d18788078e5ef79c315a5dff51f7e717b1 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Fri, 26 Mar 2021 18:33:36 -0300 Subject: [PATCH 2/5] docs: adds advanced usage example --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 76feddb..89a842c 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,18 @@ 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) From 6664bd045d3b752fa01a893d48bf5a9912e5fa48 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Fri, 26 Mar 2021 19:21:36 -0300 Subject: [PATCH 3/5] fix: fixes message when to-tag is found --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 1bc2e61..af1cba0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ if [ "$1" ] && [ "$1" != "package.json" ]; then fi [ -z "$FROM_TAG" ] && { echo "No from-tag passed. Fallbacking to git previous tag."; previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1); } || { echo "From-tag detected. Using it's value."; previous_tag=$FROM_TAG; } -[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "From-tag detected. Using it's value."; new_tag=$FROM_TAG; } +[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "To-tag detected. Using it's value."; new_tag=$FROM_TAG; } changelog=$(generate-changelog -t "$previous_tag..$new_tag" --file -) changelog="${changelog//'%'/'%25'}" From c6739e727bd7e03b9b9edcf3bb4307ac0fe9e8ce Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Fri, 26 Mar 2021 19:24:32 -0300 Subject: [PATCH 4/5] fix: fixes variable value when to-tag is found --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index af1cba0..0549d7b 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,7 +6,7 @@ if [ "$1" ] && [ "$1" != "package.json" ]; then fi [ -z "$FROM_TAG" ] && { echo "No from-tag passed. Fallbacking to git previous tag."; previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1); } || { echo "From-tag detected. Using it's value."; previous_tag=$FROM_TAG; } -[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "To-tag detected. Using it's value."; new_tag=$FROM_TAG; } +[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "To-tag detected. Using it's value."; new_tag=$TO_TAG; } changelog=$(generate-changelog -t "$previous_tag..$new_tag" --file -) changelog="${changelog//'%'/'%25'}" From 7ad3931bf44050287ef5b31d12e475912569a194 Mon Sep 17 00:00:00 2001 From: Fabricio Sander Date: Tue, 30 Mar 2021 15:44:01 -0300 Subject: [PATCH 5/5] fix: fixes shell linting errors --- entrypoint.sh | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 0549d7b..7a10af6 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,8 +5,22 @@ if [ "$1" ] && [ "$1" != "package.json" ]; then cp "$1" package.json fi -[ -z "$FROM_TAG" ] && { echo "No from-tag passed. Fallbacking to git previous tag."; previous_tag=$(git tag --sort version:refname | tail -n 2 | head -n 1); } || { echo "From-tag detected. Using it's value."; previous_tag=$FROM_TAG; } -[ -z "$TO_TAG" ] && { echo "No to-tag passed. Fallbacking to git previous tag." ; new_tag=$(git tag --sort version:refname | tail -n 1); } || { echo "To-tag detected. Using it's value."; new_tag=$TO_TAG; } +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'}"