feat(action): add output for the latest version (#12)

* feat: output `version` of the latest release

* update readme
This commit is contained in:
Nicolas Hedger
2023-11-12 23:16:39 +01:00
committed by GitHub
parent 9158b31444
commit b7913b6646
5 changed files with 15 additions and 1 deletions

View File

@@ -16,8 +16,10 @@ jobs:
uses: ./ uses: ./
with: with:
config: fixtures/cliff.toml config: fixtures/cliff.toml
args: --verbose --strip 'footer' --exclude-path '.github/**' args: --verbose --strip 'footer' --exclude-path '.github/**' --tag 0.0.0
env: env:
OUTPUT: fixtures/CHANGELOG.md OUTPUT: fixtures/CHANGELOG.md
- name: Print the changelog - name: Print the changelog
run: cat "${{ steps.git-cliff.outputs.changelog }}" run: cat "${{ steps.git-cliff.outputs.changelog }}"
- name: Print the version
run: echo "${{ steps.git-cliff.outputs.version }}"

View File

@@ -13,4 +13,6 @@ COPY README.md /
COPY LICENSE / COPY LICENSE /
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["/entrypoint.sh"] ENTRYPOINT ["/entrypoint.sh"]

View File

@@ -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. - `changelog`: Output file that contains the generated changelog.
- `content`: Content of the changelog. - `content`: Content of the changelog.
- `version`: Version of the latest release.
### Environment variables ### Environment variables

View File

@@ -14,6 +14,8 @@ outputs:
description: "output file" description: "output file"
content: content:
description: "content of the changelog" description: "content of the changelog"
version:
description: "version of the latest release"
runs: runs:
using: "docker" using: "docker"
image: "Dockerfile" image: "Dockerfile"

View File

@@ -19,6 +19,10 @@ args=$(echo "$@" | xargs)
GIT_CLIFF_OUTPUT="$OUTPUT" git-cliff $args GIT_CLIFF_OUTPUT="$OUTPUT" git-cliff $args
exit_code=$? exit_code=$?
# Retrieve context
CONTEXT="$(mktemp)"
GIT_CLIFF_OUTPUT="$CONTEXT" git-cliff $args --context
# Output to console # Output to console
cat "$OUTPUT" cat "$OUTPUT"
@@ -33,5 +37,8 @@ echo "EOF" >>$GITHUB_OUTPUT
# Set output file # Set output file
echo "changelog=$OUTPUT" >>$GITHUB_OUTPUT 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 # Pass exit code to the next step
echo "exit_code=$exit_code" >>$GITHUB_OUTPUT echo "exit_code=$exit_code" >>$GITHUB_OUTPUT