diff --git a/.github/dependabot.yml b/.github/dependabot.yml index abe3a3b..b1ba7ff 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 3043890..0000000 --- a/Dockerfile +++ /dev/null @@ -1,18 +0,0 @@ -FROM orhunp/git-cliff:2.5.0@sha256:1decc44f731f4f95777429ead823a0a6df8159c877c8a59ac79c34d45f899105 - -LABEL maintainer="orhun " -LABEL repository="https://github.com/orhun/git-cliff-action" -LABEL homepage="https://github.com/orhun/git-cliff" - -LABEL com.github.actions.name="Changelog Generator" -LABEL com.github.actions.description="Generate changelog based on your Git history" -LABEL com.github.actions.icon="triangle" -LABEL com.github.actions.color="green" - -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"] diff --git a/README.md b/README.md index e2ab31d..11985b6 100644 --- a/README.md +++ b/README.md @@ -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"`) @@ -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: @@ -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 @@ -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 diff --git a/action.yml b/action.yml index d5042b1..0b42671 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..fd9fe87 --- /dev/null +++ b/install.sh @@ -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 diff --git a/entrypoint.sh b/run.sh similarity index 84% rename from entrypoint.sh rename to run.sh index 2d60754..3c699e2 100755 --- a/entrypoint.sh +++ b/run.sh @@ -1,4 +1,5 @@ -#!/bin/bash -l +#!/bin/bash + set -uxo pipefail # Avoid file expansion when passing parameters like with '*' @@ -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" @@ -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 \ No newline at end of file