From 109042f6b16ee30ba4a6e0cbc3801aa9ea316e0a Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Fri, 9 Feb 2024 14:33:55 +0100 Subject: [PATCH] clean up scripts --- hack/ci/bump-kustomize-file.sh | 6 ++-- hack/ci/create_changelog.sh | 52 ++++++++++++++---------------- hack/ci/get-version-from-branch.sh | 2 +- hack/ci/publish_release.sh | 17 +++++----- 4 files changed, 39 insertions(+), 38 deletions(-) diff --git a/hack/ci/bump-kustomize-file.sh b/hack/ci/bump-kustomize-file.sh index 366998a7..5f0f51d8 100755 --- a/hack/ci/bump-kustomize-file.sh +++ b/hack/ci/bump-kustomize-file.sh @@ -1,13 +1,15 @@ #!/usr/bin/env bash +# This script bumps the tag for the eventing-manager image in the kustomization file. + # 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 -VERSION=$1 +TAG=$1 KUSTOMIZATION_FILE=${2-"config/manager/kustomization.yaml"} # Bump kustomization file -awk -v ntv="$VERSION" '/newTag:/ {sub(/newTag:[[:space:]]*[^[:space:]]*/, "newTag: " ntv)} {print}' "$KUSTOMIZATION_FILE" >tmp_file && mv tmp_file "$KUSTOMIZATION_FILE" +awk -v ntv="$TAG" '/newTag:/ {sub(/newTag:[[:space:]]*[^[:space:]]*/, "newTag: " ntv)} {print}' "$KUSTOMIZATION_FILE" >tmp_file && mv tmp_file "$KUSTOMIZATION_FILE" diff --git a/hack/ci/create_changelog.sh b/hack/ci/create_changelog.sh index 3a063adc..f5c3084a 100755 --- a/hack/ci/create_changelog.sh +++ b/hack/ci/create_changelog.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# This script will create a changelog for a release based on the latest commits. + PREVIOUS_RELEASE=$2 # for testability # standard bash error handling @@ -15,42 +17,38 @@ GITHUB_URL=https://api.github.com/repos/${REPOSITORY} GITHUB_AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" CHANGELOG_FILE="CHANGELOG.md" -if [ "${PREVIOUS_RELEASE}" == "" ] -then - PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) +if [ "${PREVIOUS_RELEASE}" == "" ]; then + PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) fi -echo "## What has changed" >> ${CHANGELOG_FILE} +echo "## What has changed" >>${CHANGELOG_FILE} -git log ${PREVIOUS_RELEASE}..HEAD --pretty=tformat:"%h" --reverse | while read -r commit -do - 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 +git log ${PREVIOUS_RELEASE}..HEAD --pretty=tformat:"%h" --reverse | while read -r commit; do + 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 NEW_CONTRIB=$$.new 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} - -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}" ] #reference found - then - REF_PR=" in ${REF_PR}" - fi - echo "* @${user} made first contribution${REF_PR}" >> ${CHANGELOG_FILE} - done <${NEW_CONTRIB} + <(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} + +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 -echo -e "\n**Full changelog**: https://github.com/$REPOSITORY/compare/${PREVIOUS_RELEASE}...${RELEASE_TAG}" >> ${CHANGELOG_FILE} +echo -e "\n**Full changelog**: https://github.com/$REPOSITORY/compare/${PREVIOUS_RELEASE}...${RELEASE_TAG}" >>${CHANGELOG_FILE} # cleanup -rm ${NEW_CONTRIB} || echo "cleaned up" \ No newline at end of file +rm ${NEW_CONTRIB} || echo "cleaned up" + diff --git a/hack/ci/get-version-from-branch.sh b/hack/ci/get-version-from-branch.sh index 7da5e3c6..35d3ead8 100755 --- a/hack/ci/get-version-from-branch.sh +++ b/hack/ci/get-version-from-branch.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# This script will generate the version. +# This script will generate the version for a release from the current branch name and the exisitng tags. # # First it verifies, that the current branch name is 'release-x.y', # where x and y are multi-digit integers. diff --git a/hack/ci/publish_release.sh b/hack/ci/publish_release.sh index 681fc54b..f4d7dfdb 100755 --- a/hack/ci/publish_release.sh +++ b/hack/ci/publish_release.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# This script publishes a draft release +# This script publishes a draft release on GitHub.com # standard bash error handling set -o nounset # treat unset variables as an error and exit immediately. @@ -14,10 +14,11 @@ REPOSITORY=${REPOSITORY:-kyma-project/eventing-manager} GITHUB_URL=https://api.github.com/repos/${REPOSITORY} GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" -CURL_RESPONSE=$(curl -L \ - -X POST \ - -H "Accept: application/vnd.github+json" \ - -H "${GITHUB_AUTH_HEADER}" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - ${GITHUB_URL}/releases/${RELEASE_ID} \ - -d '{"draft":false}') \ No newline at end of file +curl -L \ + -X POST \ + -H "Accept: application/vnd.github+json" \ + -H "${GITHUB_AUTH_HEADER}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "${GITHUB_URL}/releases/${RELEASE_ID}" \ + -d '{"draft":false}' +