diff --git a/.github/workflows/get-version-from-release-branch-reusable.yml b/.github/workflows/get-version-from-release-branch-reusable.yml index 40a1811..532fef8 100644 --- a/.github/workflows/get-version-from-release-branch-reusable.yml +++ b/.github/workflows/get-version-from-release-branch-reusable.yml @@ -35,11 +35,15 @@ jobs: MINOR: ${{ env.MINOR }} run: | TAGS=$(git tag -l "$MAJOR.$MINOR.*") - if [[ -z $TAGS ]]; then - PATCH=0 + if [[ -n $TAGS ]]; then + # -n tests for a non-zero-length string + LAST_PATCH=$(echo "$TAGS" | cut -d '.' -f 3 | sort -n | tail -n 1) + PATCH=$((LAST_PATCH + 1)) else - PATCH=$(( $(echo $TAGS | cut -d '.' -f 3 | sort -n | tail -n 1) + 1)) + # If TAGS is empty, PATCH defaults to 0 + PATCH=0 fi - VERSION="${MAJOR}.${MINOR}.${PATCH:-0}" + VERSION="${MAJOR}.${MINOR}.${PATCH}" + echo "version: ${VERSION}" echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT exit 0 diff --git a/hack/scripts/create_changelog.sh b/hack/scripts/create_changelog.sh index 7955691..aa7990c 100755 --- a/hack/scripts/create_changelog.sh +++ b/hack/scripts/create_changelog.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Optional args need to be handled before 'set -o nonset'. +PREVIOUS_RELEASE=$3 # for testability + # Error handling. set -o nounset # treat unset variables as an error and exit immediately. set -o errexit # exit immediately when a command fails. @@ -7,18 +10,22 @@ set -E # needs to be set if we want the ERR trap set -o pipefail # prevents errors in a pipeline from being masked RELEASE_TAG=$1 +REPOSITORY=$2 -REPOSITORY=${REPOSITORY:-kyma-project/eventing-manager} GITHUB_URL=https://api.github.com/repos/${REPOSITORY} GITHUB_AUTH_HEADER="Authorization: token ${GH_TOKEN}" CHANGELOG_FILE="CHANGELOG.md" -# The git describe --tag --abbrev=0 command is used to find the most recent tag that is reachable from a commit. -# The --tag option tells git describe to consider any tag found in the refs/tags namespace, enabling matching a lightweight (non-annotated) tag. -PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) +# If the previous release was not passed, we will +if [ "${PREVIOUS_RELEASE}" == "" ]; then + # The git describe --tag --abbrev=0 command is used to find the most recent tag that is reachable from a commit. + # The --tag option tells git describe to consider any tag found in the refs/tags namespace, enabling matching a lightweight (non-annotated) tag. + PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) +fi # Generate the changelog in the CHANGELOG.md. echo "## What has changed" >>${CHANGELOG_FILE} +echo >>${CHANGELOG_FILE} # add newline # Iterate over all commits since the previous release. git log "${PREVIOUS_RELEASE}"..HEAD --pretty=tformat:"%h" --reverse | while read -r commit; do @@ -30,7 +37,7 @@ git log "${PREVIOUS_RELEASE}"..HEAD --pretty=tformat:"%h" --reverse | while read done # Create a new contibutors file (with a unique name based on the process ID of the current shell). -NEW_CONTRIB=$$.authors +NEW_CONTRIB=$$.new # Find unique authors who contributed since the last release, but not before it, and add them to the NEW_CONTRIB file. join -v2 \ @@ -40,6 +47,7 @@ join -v2 \ # Add new contributors to the 'new contributors' section of the changelog. if [ -s ${NEW_CONTRIB} ]; then echo -e "\n## New contributors" >>${CHANGELOG_FILE} + echo >>${CHANGELOG_FILE} # add newline while read -r user; do REF_PR=$(grep "@${user}" ${CHANGELOG_FILE} | head -1 | grep -o " (#[0-9]\+)" || true) if [ -n "${REF_PR}" ]; then #reference found