Skip to content

Commit

Permalink
feat(action): add output for the latest version (#12)
Browse files Browse the repository at this point in the history
* feat: output `version` of the latest release

* update readme
  • Loading branch information
nhedger committed Nov 12, 2023
1 parent 9158b31 commit b7913b6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
uses: ./
with:
config: fixtures/cliff.toml
args: --verbose --strip 'footer' --exclude-path '.github/**'
args: --verbose --strip 'footer' --exclude-path '.github/**' --tag 0.0.0
env:
OUTPUT: fixtures/CHANGELOG.md
- name: Print the changelog
run: cat "${{ steps.git-cliff.outputs.changelog }}"
- name: Print the version
run: echo "${{ steps.git-cliff.outputs.version }}"
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ COPY README.md /
COPY LICENSE /
COPY entrypoint.sh /entrypoint.sh

RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/*

ENTRYPOINT ["/entrypoint.sh"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This action generates a changelog based on your Git history using [git-cliff](ht

- `changelog`: Output file that contains the generated changelog.
- `content`: Content of the changelog.
- `version`: Version of the latest release.

### Environment variables

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ outputs:
description: "output file"
content:
description: "content of the changelog"
version:
description: "version of the latest release"
runs:
using: "docker"
image: "Dockerfile"
Expand Down
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ args=$(echo "$@" | xargs)
GIT_CLIFF_OUTPUT="$OUTPUT" git-cliff $args
exit_code=$?

# Retrieve context
CONTEXT="$(mktemp)"
GIT_CLIFF_OUTPUT="$CONTEXT" git-cliff $args --context

# Output to console
cat "$OUTPUT"

Expand All @@ -33,5 +37,8 @@ echo "EOF" >>$GITHUB_OUTPUT
# Set output file
echo "changelog=$OUTPUT" >>$GITHUB_OUTPUT

# Set the version output to the version of the latest release
echo "version=$(jq -r '.[0].version' $CONTEXT)" >>$GITHUB_OUTPUT

# Pass exit code to the next step
echo "exit_code=$exit_code" >>$GITHUB_OUTPUT

0 comments on commit b7913b6

Please sign in to comment.