diff --git a/.github/workflows/create-draft-release-reusable.yml b/.github/workflows/create-draft-release-reusable.yml index 1c71f18..81cee0e 100644 --- a/.github/workflows/create-draft-release-reusable.yml +++ b/.github/workflows/create-draft-release-reusable.yml @@ -28,9 +28,9 @@ jobs: GH_TOKEN: ${{ secrets.GH_TOKEN }} shell: bash run: | - # Note: your repository needs to have this script. - # Running this script should result in a file named CHANGELOG.md, located in the base directory. - ./hack/scripts/create_changelog.sh "${VERSION}" + # todo once the script was merged replace main with a commit sha: + # curl -sSL https://raw.githubusercontent.com/kyma-project/eventing-tools//hack/scripts/create_changelog.sh | bash "${VERSION}" + curl -sL https://raw.githubusercontent.com/kyma-project/eventing-tools/main/hack/scripts/create_changelog.sh | bash "${VERSION}" - name: Print out changelog run: cat CHANGELOG.md diff --git a/.github/workflows/render-and-upload-manifests-reusable.yml b/.github/workflows/render-and-upload-manifests-reusable.yml index f185156..14ffa99 100644 --- a/.github/workflows/render-and-upload-manifests-reusable.yml +++ b/.github/workflows/render-and-upload-manifests-reusable.yml @@ -35,6 +35,14 @@ jobs: # Note: your repository needs to have this script. run: ./hack/scripts/render_crd.sh "${VERSION}" + - name: Create Symlink for CR file + # `gh release upload ` cannot rename files so we create a symlink with the desired name for the CR. + shell: bash + env: + CR_FILE: ${{ inputs.CR_FILE }} + run: | + ln -sf config/samples/default.yaml "./${CR_FILE}" + - name: Print out CR file env: CR_FILE: ${{ inputs.CR_FILE }} diff --git a/hack/scripts/create_changelog.sh b/hack/scripts/create_changelog.sh new file mode 100755 index 0000000..7955691 --- /dev/null +++ b/hack/scripts/create_changelog.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + +# Error handling. +set -o nounset # treat unset variables as an error and exit immediately. +set -o errexit # exit immediately when a command fails. +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=${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) + +# Generate the changelog in the CHANGELOG.md. +echo "## What has changed" >>${CHANGELOG_FILE} + +# Iterate over all commits since the previous release. +git log "${PREVIOUS_RELEASE}"..HEAD --pretty=tformat:"%h" --reverse | while read -r commit; do + # If the author of the commit is not kyma-bot, append the commit message to the changelog. + COMMIT_AUTHOR=$(curl -H "${GITHUB_AUTH_HEADER}" -sS "${GITHUB_URL}/commits/${commit}" | jq -r '.author.login') + if [ "${COMMIT_AUTHOR}" != "kyma-bot" ]; then + git show -s "${commit}" --format="* %s by @${COMMIT_AUTHOR}" >>${CHANGELOG_FILE} + fi +done + +# Create a new contibutors file (with a unique name based on the process ID of the current shell). +NEW_CONTRIB=$$.authors + +# Find unique authors who contributed since the last release, but not before it, and add them to the NEW_CONTRIB file. +join -v2 \ + <(curl -H "${GITHUB_AUTH_HEADER}" -sS "${GITHUB_URL}/compare/$(git rev-list --max-parents=0 HEAD)...${PREVIOUS_RELEASE}" | jq -r '.commits[].author.login' | sort -u) \ + <(curl -H "${GITHUB_AUTH_HEADER}" -sS "${GITHUB_URL}/compare/${PREVIOUS_RELEASE}...HEAD" | jq -r '.commits[].author.login' | sort -u) >${NEW_CONTRIB} + +# Add new contributors to the 'new contributors' section of the changelog. +if [ -s ${NEW_CONTRIB} ]; then + echo -e "\n## New contributors" >>${CHANGELOG_FILE} + 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 + REF_PR=" in ${REF_PR}" + fi + echo "* @${user} made first contribution${REF_PR}" >>${CHANGELOG_FILE} + done <${NEW_CONTRIB} +fi + +# Append link to the full-changelog this changelog. +echo -e "\n**Full changelog**: https://github.com/$REPOSITORY/compare/${PREVIOUS_RELEASE}...${RELEASE_TAG}" >>${CHANGELOG_FILE} diff --git a/hack/scripts/get-version-from-branch.sh b/hack/scripts/get-version-from-branch.sh deleted file mode 100644 index 244411d..0000000 --- a/hack/scripts/get-version-from-branch.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# This script will generate the version. -# -# First it verifies, that the current branch name is 'release-x.y', -# where x and y are multi-digit integers. -# It further looks into the existing tags, looking for ones that start with x.y. -# If there is none, it will return x.y.0. Otherwise it will return x.y.z where z -# is the highest existing value increase by one. -# -# Examples: -# 1. The current git branch is 'release-1.0' and git has the tags '1.0.1', '1.0.2', 1.0.3': -# $ ./get-version-from-branch.sh -# 1.0.4 -# -# 2. The current branch is 'release-1.1' and git has no tags that start with '1.1': -# $ ./get-version-from-branch.sh -# 1.0.0 -# -# 3. The current branch is 'main': -# $ ./get-version-from-branch.sh -# Not on a release branch. -# -# Please note that this will exit with an error: -# ./get-version-from-branch.sh || echo "exit with error" -# Not on a release branch. -# exit with error -# - -# Get the current branch name. -current_branch=$(git rev-parse --abbrev-ref HEAD) - -# Check if the current branch is a release branch. -if [[ $current_branch =~ ^release-([0-9]+)\.([0-9]+)$ ]]; then - # Extract x and y from the branch name. BASH_REMATCH is an array variable - # automatically generated by pattern matching ([[ ... ]]). - x=${BASH_REMATCH[1]} - y=${BASH_REMATCH[2]} - - # Find the highest z value for the matching tags. - highest_z=$(git tag -l "$x.$y.*" | cut -d '.' -f 3 | sort -n | tail -n 1) - - # Increment the highest z value by 1 or set to 0 if no matching tags are found. - if [ -z "$highest_z" ]; then - next_z=0 - else - next_z=$((highest_z + 1)) - fi - - # Return the new version. - new_version="${x}.${y}.${next_z}" - echo "${new_version}" - exit 0 -else - echo "Not on a release branch." - exit 1 -fi