From f7e2a3cf987230870e5384f6af823cdc66bf2664 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Thu, 5 Sep 2024 16:58:11 +0200 Subject: [PATCH 1/6] refactor create release github action --- .github/scripts/release/create_changelog.sh | 53 +++++++++ .../scripts/release/draft_release.sh | 14 +-- .../scripts}/release/get_last_release.sh | 0 .../scripts}/release/get_release_by_tag.sh | 2 + .../scripts}/release/publish_release.sh | 14 +-- .../scripts}/release/validate_release_tag.sh | 3 +- .../scripts}/release/wait_for_image.sh | 0 .github/workflows/build-image.yml | 46 ++++++++ .github/workflows/create-release.yaml | 104 ++++++------------ scripts/release/create_changelog.sh | 31 ------ 10 files changed, 147 insertions(+), 120 deletions(-) create mode 100755 .github/scripts/release/create_changelog.sh rename scripts/release/create_draft_release.sh => .github/scripts/release/draft_release.sh (66%) rename {scripts => .github/scripts}/release/get_last_release.sh (100%) rename {scripts => .github/scripts}/release/get_release_by_tag.sh (96%) rename {scripts => .github/scripts}/release/publish_release.sh (52%) rename {scripts => .github/scripts}/release/validate_release_tag.sh (98%) rename {scripts => .github/scripts}/release/wait_for_image.sh (100%) create mode 100644 .github/workflows/build-image.yml delete mode 100755 scripts/release/create_changelog.sh diff --git a/.github/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh new file mode 100755 index 0000000000..c4d10cb28f --- /dev/null +++ b/.github/scripts/release/create_changelog.sh @@ -0,0 +1,53 @@ +#!/usr/bin/env bash + + +set -o nounset +set -o errexit +set -E +set -o pipefail + +RELEASE_VERSION=$1 +PREVIOUS_RELEASE=$2 + + +if [ "${PREVIOUS_RELEASE}" == "" ] +then + PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) +fi + +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} +GITHUB_AUTH_HEADER="Authorization: token ${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 +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}" ] + 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} + +rm ${NEW_CONTRIB} || echo "cleaned up" diff --git a/scripts/release/create_draft_release.sh b/.github/scripts/release/draft_release.sh similarity index 66% rename from scripts/release/create_draft_release.sh rename to .github/scripts/release/draft_release.sh index d0d5348130..80e19b11ce 100755 --- a/scripts/release/create_draft_release.sh +++ b/.github/scripts/release/draft_release.sh @@ -6,11 +6,10 @@ set -E set -o pipefail RELEASE_TAG=$1 -CHANGELOG_FILE_NAME=$2 -CHANGELOG_FILE=$(cat "$CHANGELOG_FILE_NAME") -GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY -GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} +GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" +CHANGELOG_FILE=$(cat CHANGELOG.md) JSON_PAYLOAD=$(jq -n \ --arg tag_name "$RELEASE_TAG" \ @@ -24,15 +23,14 @@ JSON_PAYLOAD=$(jq -n \ }') CURL_RESPONSE=$(curl -L \ - -s \ - --fail-with-body \ -X POST \ -H "Accept: application/vnd.github+json" \ - -H "$GITHUB_AUTH_HEADER" \ + -H "${GITHUB_AUTH_HEADER}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "$GITHUB_URL"/releases \ + "${GITHUB_URL}"/releases \ -d "$JSON_PAYLOAD") # return the id of the release draft echo "$CURL_RESPONSE" | jq -r ".id" + diff --git a/scripts/release/get_last_release.sh b/.github/scripts/release/get_last_release.sh similarity index 100% rename from scripts/release/get_last_release.sh rename to .github/scripts/release/get_last_release.sh diff --git a/scripts/release/get_release_by_tag.sh b/.github/scripts/release/get_release_by_tag.sh similarity index 96% rename from scripts/release/get_release_by_tag.sh rename to .github/scripts/release/get_release_by_tag.sh index 5c1a499d5f..9ef7036848 100755 --- a/scripts/release/get_release_by_tag.sh +++ b/.github/scripts/release/get_release_by_tag.sh @@ -4,6 +4,7 @@ set -o nounset set -o pipefail RELEASE_TAG=$1 +GITHUB_TOKEN=$2 GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" @@ -23,3 +24,4 @@ if [[ $CURL_EXIT_CODE == 0 ]]; then exit 1 fi + diff --git a/scripts/release/publish_release.sh b/.github/scripts/release/publish_release.sh similarity index 52% rename from scripts/release/publish_release.sh rename to .github/scripts/release/publish_release.sh index 5c3684495a..f666815aaa 100755 --- a/scripts/release/publish_release.sh +++ b/.github/scripts/release/publish_release.sh @@ -5,20 +5,16 @@ set -o errexit set -E set -o pipefail -RELEASE_ID=$1 +RELEASE_VERSION=$1 -GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY -GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} +GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" CURL_RESPONSE=$(curl -L \ - -s \ - --fail-with-body \ -X POST \ -H "Accept: application/vnd.github+json" \ - -H "$GITHUB_AUTH_HEADER" \ + -H "${GITHUB_AUTH_HEADER}" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - "$GITHUB_URL"/releases/"$RELEASE_ID" \ + "${GITHUB_URL}"/releases/"${RELEASE_VERSION}" \ -d '{"draft":false}') - echo "$CURL_RESPONSE" - diff --git a/scripts/release/validate_release_tag.sh b/.github/scripts/release/validate_release_tag.sh similarity index 98% rename from scripts/release/validate_release_tag.sh rename to .github/scripts/release/validate_release_tag.sh index e50533506a..48a6bc08ff 100755 --- a/scripts/release/validate_release_tag.sh +++ b/.github/scripts/release/validate_release_tag.sh @@ -12,5 +12,4 @@ semver_pattern="^([0-9]|[1-9][0-9]*)[.]([0-9]|[1-9][0-9]*)[.]([0-9]|[1-9][0-9]*) if ! [[ $CURRENT_RELEASE_TAG =~ $semver_pattern ]]; then echo "Given tag \"$CURRENT_RELEASE_TAG\" does not match the expected semantic version pattern: \"$semver_pattern\"." exit 1 -fi - +fi \ No newline at end of file diff --git a/scripts/release/wait_for_image.sh b/.github/scripts/release/wait_for_image.sh similarity index 100% rename from scripts/release/wait_for_image.sh rename to .github/scripts/release/wait_for_image.sh diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000000..085bc3843c --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,46 @@ +name: Build Lifecycle Manager + +on: + push: + branches: + - main # This will get tagged with `latest` and `v{{DATE}}-{{COMMIT_HASH_SHORT}}` + workflow_call: + inputs: + tag: + description: 'Additional tag for built images' + required: false + type: string + default: "" + pull_request_target: + types: [ opened, edited, synchronize, reopened, ready_for_review ] + +permissions: + id-token: write # This is required for requesting the JWT token + contents: read # This is required for actions/checkout + +jobs: + compute-tag: + runs-on: ubuntu-latest + outputs: + tag: ${{ steps.get_tag.outputs.tag }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Get the latest tag + id: get_tag + run: | + if [[ "${{ inputs.tag }}" != "" ]]; then + echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT + elif [[ "${{ github.event_name }}" == "push" ]]; then + echo "tag=latest" >> $GITHUB_OUTPUT + fi + - name: Echo the tag + run: echo ${{ steps.get_tag.outputs.tag }} + build-image: + needs: compute-tag + uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main + with: + name: lifecycle-manager + dockerfile: Dockerfile + context: . + tags: ${{ needs.compute-tag.outputs.tag }} diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index 47ad297326..627e17f5e3 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -6,111 +6,75 @@ env: on: workflow_dispatch: inputs: - tagName: - description: "Release tag. Example: 1.2.3" + name: + description: "Release name" default: "" required: true - commitHash: - description: "full commit hash or branch name to tag" - default: "main" - required: true + since: + description: "Changelog since" + default: "" + required: false + jobs: validate-release: name: Validate release runs-on: ubuntu-latest - outputs: - last_release_tag: ${{ steps.get_last_release_tag.outputs.last_release_tag }} steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Validate the release tag - run: ./scripts/release/validate_release_tag.sh ${{ github.event.inputs.tagName }} + run: ./.github/scripts/release/validate_release_tag.sh ${{ github.event.inputs.name }} - name: Check if release doesn't exist yet - env: - CURRENT_RELEASE_TAG: ${{ github.event.inputs.tagName }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/release/get_release_by_tag.sh $CURRENT_RELEASE_TAG - - name: Get last release version - id: get_last_release_tag - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - set +e - SCRIPT_OUTPUT=$(./scripts/release/get_last_release.sh) - SCRIPT_EXIT_CODE=$? - if [[ $SCRIPT_EXIT_CODE != 0 ]]; then - echo "$SCRIPT_OUTPUT" - exit $SCRIPT_EXIT_CODE - fi - set -e - echo "Last Release version: $SCRIPT_OUTPUT" - echo "last_release_tag=$SCRIPT_OUTPUT" >> $GITHUB_OUTPUT - create-tag: - name: Create lightweight tag - runs-on: ubuntu-latest - needs: validate-release - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Create lightweight tag - run: | - git tag ${{ github.event.inputs.tagName }} ${{ github.event.inputs.commitHash }} - git push origin ${{ github.event.inputs.tagName }} - - name: Wait for the Docker image - timeout-minutes: 20 - env: - ITERATIONS: 40 - SLEEP_SECONDS: 30 - run: ./scripts/release/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.tagName }} $ITERATIONS $SLEEP_SECONDS + run: ./.github/scripts/release/get_release_by_tag.sh ${{ github.event.inputs.name }} ${{ secrets.GITHUB_TOKEN }} draft-release: name: Create draft release runs-on: ubuntu-latest - needs: [validate-release, create-tag] - outputs: - release_id: ${{ steps.draft_release.outputs.release_id }} + needs: validate-release steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Generate changelog - id: generate_changelog + - name: Create changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CURRENT_RELEASE_TAG: ${{ github.event.inputs.tagName }} - LAST_RELEASE_TAG: ${{ needs.validate-release.outputs.last_release_tag }} - DOCKER_IMAGE_URL: ${{ env.IMAGE_REPO }}:${{ github.event.inputs.tagName }} - run: | - echo "Generating changelog for version: $CURRENT_RELEASE_TAG" - CHANGELOG_FILE_NAME=$(./scripts/release/create_changelog.sh $CURRENT_RELEASE_TAG $LAST_RELEASE_TAG $DOCKER_IMAGE_URL) - echo "changelog_file_name=$CHANGELOG_FILE_NAME" >> $GITHUB_OUTPUT - - name: Create draft release - id: draft_release + run: ./.github/scripts/release/create_changelog.sh ${{ github.event.inputs.name }} ${{ github.event.inputs.since }} + - name: Draft release + id: draft-release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CURRENT_RELEASE_TAG: ${{ github.event.inputs.tagName }} - CHANGELOG_FILE_NAME: ${{ steps.generate_changelog.outputs.changelog_file_name }} run: | - RELEASE_ID=$(./scripts/release/create_draft_release.sh $CURRENT_RELEASE_TAG $CHANGELOG_FILE_NAME) - echo "RELEASE_ID=$RELEASE_ID" + RELEASE_ID=$(./.github/scripts/release/draft_release.sh ${{ github.event.inputs.name }}) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT + - name: Create tag + run: | + git tag ${{ github.event.inputs.name }} + git push origin ${{ github.event.inputs.name }} --tags + outputs: + release_id: ${{ steps.draft-release.outputs.release_id }} + builds: + needs: draft-release + uses: ./.github/workflows/build-image.yml + with: + tag: "${{ github.event.inputs.name }}" publish_release: name: Publish release + needs: [ validate-release, draft-release, builds ] runs-on: ubuntu-latest - needs: draft-release steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Wait for the Docker image + timeout-minutes: 20 + env: + ITERATIONS: 40 + SLEEP_SECONDS: 30 + run: ./.github/scripts/release/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.name }} $ITERATIONS $SLEEP_SECONDS - name: Publish release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - RELEASE_ID: ${{ needs.draft-release.outputs.release_id }} - run: | - echo "RELEASE_ID=$RELEASE_ID" - ./scripts/release/publish_release.sh $RELEASE_ID + run: ./.github/scripts/release/publish_release.sh ${{ needs.draft-release.outputs.release_id }} \ No newline at end of file diff --git a/scripts/release/create_changelog.sh b/scripts/release/create_changelog.sh deleted file mode 100755 index 0e1e92b2ed..0000000000 --- a/scripts/release/create_changelog.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -set -o nounset -set -o errexit -set -E -set -o pipefail - -CURRENT_RELEASE_TAG=$1 -LAST_RELEASE_TAG=$2 -DOCKER_IMAGE_URL=$3 - -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 "$LAST_RELEASE_TAG..$CURRENT_RELEASE_TAG" --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') - git show -s "$commit" --format="* %s by @$COMMIT_AUTHOR" >> $CHANGELOG_FILE -done - -{ - 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 - -echo $CHANGELOG_FILE From 3ac6a473e2a1f8189e14e71824afbf609da2eef5 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Thu, 5 Sep 2024 19:15:48 +0200 Subject: [PATCH 2/6] Wait for image build depends on workflow_run --- .github/workflows/build-image.yml | 2 +- .github/workflows/test-e2e.yaml | 21 ++++++--------------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 085bc3843c..23f29cd2c3 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -1,4 +1,4 @@ -name: Build Lifecycle Manager +name: Build Image on: push: diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index 5e5edca5ac..4c02b23465 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -1,29 +1,20 @@ name: TestSuite E2E on: - pull_request: - branches: - - main - - feat/** workflow_dispatch: inputs: k8s_version: description: With Kubernetes version required: false - + workflow_run: + workflows: [ "Build Image" ] + types: + - completed + branches-ignore: + - main jobs: - wait-for-image-build: - name: Wait for image build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/wait-for-image-build - with: - token: ${{ secrets.GITHUB_TOKEN }} - statusName: ${{ (github.event_name == 'pull_request') && 'pull-lifecycle-mgr-build' || 'main-lifecycle-mgr-build' }} e2e-integration: name: E2E - needs: wait-for-image-build strategy: matrix: e2e-test: From 52cd73e5a704fe934b848619b447b6e3d7321055 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Mon, 9 Sep 2024 10:02:04 +0200 Subject: [PATCH 3/6] remove workflow_run --- .github/scripts/release/get_last_release.sh | 24 --------------------- .github/workflows/build-image.yml | 2 -- .github/workflows/test-e2e.yaml | 4 ++++ 3 files changed, 4 insertions(+), 26 deletions(-) delete mode 100755 .github/scripts/release/get_last_release.sh diff --git a/.github/scripts/release/get_last_release.sh b/.github/scripts/release/get_last_release.sh deleted file mode 100755 index 7fa33aab17..0000000000 --- a/.github/scripts/release/get_last_release.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bash - -set -o nounset -set -o pipefail - -GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY - -CURL_RESPONSE=$(curl -L \ - -s \ - --fail-with-body \ - -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - "$GITHUB_URL"/releases/latest) - -CURL_EXIT_CODE=$? - -if [[ $CURL_EXIT_CODE == 0 ]]; then - echo "$CURL_RESPONSE" | jq -r .tag_name -else - echo "Can't find any previous release - unable to generate changelog" -fi - -exit $CURL_EXIT_CODE - diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index 23f29cd2c3..3b8d371168 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -11,8 +11,6 @@ on: required: false type: string default: "" - pull_request_target: - types: [ opened, edited, synchronize, reopened, ready_for_review ] permissions: id-token: write # This is required for requesting the JWT token diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index 4c02b23465..6fd215eb39 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -13,8 +13,12 @@ on: branches-ignore: - main jobs: + build-image: + name: Build Image + uses: ./.github/workflows/build-image.yml e2e-integration: name: E2E + needs: build-image strategy: matrix: e2e-test: From ca96df33328d910e58b06ff30c9e2cc1dda6f668 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Mon, 9 Sep 2024 12:55:16 +0200 Subject: [PATCH 4/6] fix smoke test --- .github/workflows/test-e2e.yaml | 7 +------ .github/workflows/test-smoke.yml | 14 ++++---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index 6fd215eb39..6f6a6e956e 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -6,12 +6,7 @@ on: k8s_version: description: With Kubernetes version required: false - workflow_run: - workflows: [ "Build Image" ] - types: - - completed - branches-ignore: - - main + jobs: build-image: name: Build Image diff --git a/.github/workflows/test-smoke.yml b/.github/workflows/test-smoke.yml index c752d542e4..d25ed87226 100644 --- a/.github/workflows/test-smoke.yml +++ b/.github/workflows/test-smoke.yml @@ -6,15 +6,9 @@ on: - main - feat/** jobs: - wait-for-image-build: - name: Wait for image build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/wait-for-image-build - with: - token: ${{ secrets.GITHUB_TOKEN }} - statusName: pull-lifecycle-mgr-build + build-image: + name: Build Image + uses: ./.github/workflows/build-image.yml kustomize: strategy: @@ -44,7 +38,7 @@ jobs: matrix: cli-stability: ["unstable"] target: ["default", "control-plane"] - needs: [kustomize,wait-for-image-build] + needs: [ kustomize,build-image ] name: "kyma (${{ matrix.cli-stability }}) alpha deploy -k config/${{ matrix.target }}" runs-on: ubuntu-latest env: From 3a678fd1b11bb4c428a0ae8993d8d5312b31c80f Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Mon, 9 Sep 2024 15:43:46 +0200 Subject: [PATCH 5/6] remove set -o nounset --- .github/scripts/release/create_changelog.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh index c4d10cb28f..f799083f5e 100755 --- a/.github/scripts/release/create_changelog.sh +++ b/.github/scripts/release/create_changelog.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -set -o nounset set -o errexit set -E set -o pipefail From a4c21cb605fb8629de3a54cd58d580a2f7e3bcf7 Mon Sep 17 00:00:00 2001 From: Xin Ruan Date: Tue, 10 Sep 2024 14:02:44 +0200 Subject: [PATCH 6/6] fix create change log --- .github/scripts/release/create_changelog.sh | 48 +++++++-------------- .github/workflows/create-release.yaml | 2 +- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/.github/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh index f799083f5e..19b9c067c8 100755 --- a/.github/scripts/release/create_changelog.sh +++ b/.github/scripts/release/create_changelog.sh @@ -5,48 +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 -GITHUB_URL=https://api.github.com/repos/${CODE_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" +cat $CHANGELOG_FILE diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index 627e17f5e3..d1cc7e843f 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -40,7 +40,7 @@ jobs: - name: Create 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: