From 21799260d920bd30cfdb4b87e07256e129faf7f0 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Tue, 10 Sep 2024 13:47:13 +0200 Subject: [PATCH] fix: Create changelog (#378) fix create_changelog.sh --- .github/scripts/release/create_changelog.sh | 49 +++++++-------------- .github/workflows/create-release.yaml | 2 +- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/.github/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh index 17ca56a0..44c3314d 100755 --- a/.github/scripts/release/create_changelog.sh +++ b/.github/scripts/release/create_changelog.sh @@ -5,49 +5,32 @@ set -o errexit set -E set -o pipefail -RELEASE_VERSION=$1 -PREVIOUS_RELEASE=$2 +CURRENT_RELEASE_TAG=$1 +DOCKER_IMAGE_URL=$2 +LAST_RELEASE_TAG=$3 - -if [ "${PREVIOUS_RELEASE}" == "" ] +if [ "${LAST_RELEASE_TAG}" == "" ] then - PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) + LAST_RELEASE_TAG=$(git describe --tags --abbrev=0) fi -REPOSITORY=${REPOSITORY:-kyma-project/template-operator} -GITHUB_URL=https://api.github.com/repos/${REPOSITORY} -GITHUB_AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" +GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY +GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" CHANGELOG_FILE="CHANGELOG.md" -echo "## What has changed" >> ${CHANGELOG_FILE} -git log "${PREVIOUS_RELEASE}"..HEAD --pretty=tformat:"%h" --reverse | while read -r commit +git log "$LAST_RELEASE_TAG"..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') + 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}" ] - then - 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_VERSION}" >> ${CHANGELOG_FILE} +{ + echo -e "\n**Full changelog**: $GITHUB_URL/compare/$LAST_RELEASE_TAG...$CURRENT_RELEASE_TAG" + echo -e "\n" + echo "## Docker image URL" + echo "$DOCKER_IMAGE_URL" +} >> $CHANGELOG_FILE -rm ${NEW_CONTRIB} || echo "cleaned up" \ No newline at end of file +cat $CHANGELOG_FILE \ No newline at end of file diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index 9fe24da6..3407b030 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -42,7 +42,7 @@ jobs: id: generate_changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./.github/scripts/release/create_changelog.sh ${{ github.event.inputs.name }} ${{ github.event.inputs.since }} + run: ./.github/scripts/release/create_changelog.sh ${{ github.event.inputs.name }} ${{ env.IMAGE_REPO }}:${{ github.event.inputs.name }} ${{ github.event.inputs.since }} - name: Draft release id: draft-release env: