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

feat: adds custom tags values to generate changelog #26

Merged
merged 5 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
11 changes: 11 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
18 changes: 16 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'}"
Expand Down