Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add version input variable #27

Merged
merged 12 commits into from
Aug 26, 2024
13 changes: 0 additions & 13 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,3 @@ updates:
patch:
update-types:
- "patch"
# Maintain dependencies for docker
- package-ecosystem: docker
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
groups:
minor:
update-types:
- "minor"
patch:
update-types:
- "patch"
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This action generates a changelog based on your Git history using [git-cliff](ht

### Input variables

- `version`: `git-cliff` version to use (Default: `"latest"`)
- `config`: Path of the configuration file. (Default: `"cliff.toml"`)
- `args`: [Arguments](https://github.com/orhun/git-cliff#usage) to pass to git-cliff. (Default: `"-v"`)

Expand Down Expand Up @@ -49,9 +50,10 @@ jobs:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@v3
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
version: latest
config: cliff.toml
args: --verbose
env:
Expand Down Expand Up @@ -81,7 +83,7 @@ jobs:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@v3
uses: orhun/git-cliff-action@v4
id: git-cliff
with:
config: cliff.toml
Expand Down Expand Up @@ -130,7 +132,7 @@ jobs:
fetch-depth: 0

- name: Generate a changelog
uses: orhun/git-cliff-action@v3
uses: orhun/git-cliff-action@v4
with:
config: cliff.toml
args: --verbose
Expand Down
28 changes: 23 additions & 5 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: "git-cliff - Changelog Generator"
description: "Generate changelog based on your Git history"
inputs:
version:
description: "git-cliff version"
required: false
default: "latest"
config:
description: "config file location"
required: false
Expand All @@ -12,16 +16,30 @@ inputs:
outputs:
changelog:
description: "output file"
value: ${{ steps.run-git-cliff.outputs.changelog }}
content:
description: "content of the changelog"
value: ${{ steps.run-git-cliff.outputs.content }}
version:
description: "version of the latest release"
value: ${{ steps.run-git-cliff.outputs.version }}
runs:
using: "docker"
image: "Dockerfile"
args:
- --config=${{ inputs.config }}
- ${{ inputs.args }}
using: "composite"
steps:
- name: Download git-cliff
shell: bash
run: ${{ github.action_path }}/install.sh
env:
RUNNER_OS: ${{ runner.os }}
RUNNER_ARCH: ${{ runner.arch }}
VERSION: ${{ inputs.version }}
GITHUB_TOKEN: ${{ github.token }}

- name: Run git-cliff
id: run-git-cliff
shell: bash
run: ${{ github.action_path }}/run.sh --config=${{ inputs.config }} ${{ inputs.args }}

branding:
icon: "triangle"
color: "green"
41 changes: 41 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -uxo pipefail

case "${RUNNER_OS}" in
macOS) OS=apple-darwin ;;
Windows) OS=pc-windows-msvc ;;
*) OS=unknown-linux-gnu ;;
esac
case "${RUNNER_ARCH}" in
ARM64) ARCH=aarch64 ;;
ARM) ARCH=pc-windows-msvc ;;
X86) ARCH=i686 ;;
*) ARCH=x86_64 ;;
esac

RELEASE_URL='https://api.github.com/repos/orhun/git-cliff/releases/latest'
if [[ "${VERSION}" != 'latest' ]]; then
RELEASE_URL="https://api.github.com/repos/orhun/git-cliff/releases/tags/${VERSION}"
fi

# Although releases endpoint is available without authentication, the current github.token is still passed
# in order to increase the limit of 60 requests per hour per IP address to a higher value that's also counted
# per GitHub account.
# Caching is disabled in order not to receive stale responses from Varnish cache fronting GitHub API.
RELEASE_INFO="$(curl --silent --show-error --fail \
--header "authorization: Bearer ${GITHUB_TOKEN}" \
--header 'Cache-Control: no-cache, must-revalidate' \
"${RELEASE_URL}")"
TAG_NAME="$(echo "${RELEASE_INFO}" | jq --raw-output ".tag_name")"
TARGET="git-cliff-${TAG_NAME:1}-${ARCH}-${OS}.tar.gz"
LOCATION="$(echo "${RELEASE_INFO}" \
| jq --raw-output ".assets[].browser_download_url" \
| grep "${TARGET}$")"

# Skip downloading release if downloaded already, e.g. when the action is used multiple times.
if [[ ! -e "$TARGET" ]]; then
curl --silent --show-error --fail --location --output "$TARGET" "$LOCATION"
tar -xf "$TARGET"
mv git-cliff-${TAG_NAME:1}/git-cliff .
fi
9 changes: 5 additions & 4 deletions entrypoint.sh → run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash -l
#!/bin/bash

set -uxo pipefail

# Avoid file expansion when passing parameters like with '*'
Expand All @@ -16,12 +17,12 @@ mkdir -p "$(dirname $OUTPUT)"
args=$(echo "$@" | xargs)

# Execute git-cliff
GIT_CLIFF_OUTPUT="$OUTPUT" git-cliff $args
GIT_CLIFF_OUTPUT="$OUTPUT" ./git-cliff $args
exit_code=$?

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

# Output to console
cat "$OUTPUT"
Expand All @@ -41,4 +42,4 @@ echo "changelog=$OUTPUT" >>$GITHUB_OUTPUT
echo "version=$(jq -r '.[0].version' $CONTEXT)" >>$GITHUB_OUTPUT

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