diff --git a/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh similarity index 55% rename from scripts/release/create_changelog.sh rename to .github/scripts/release/create_changelog.sh index 0e1e92b2ed..19b9c067c8 100755 --- a/scripts/release/create_changelog.sh +++ b/.github/scripts/release/create_changelog.sh @@ -1,31 +1,36 @@ #!/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 +DOCKER_IMAGE_URL=$2 +LAST_RELEASE_TAG=$3 + +if [ "${LAST_RELEASE_TAG}" == "" ] +then + LAST_RELEASE_TAG=$(git describe --tags --abbrev=0) +fi 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 +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') - git show -s "$commit" --format="* %s by @$COMMIT_AUTHOR" >> $CHANGELOG_FILE + if [ "${COMMIT_AUTHOR}" != "kyma-bot" ]; then + git show -s "${commit}" --format="* %s by @${COMMIT_AUTHOR}" >> ${CHANGELOG_FILE} + fi 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" + echo "$DOCKER_IMAGE_URL" } >> $CHANGELOG_FILE -echo $CHANGELOG_FILE +cat $CHANGELOG_FILE 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_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..3b8d371168 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,44 @@ +name: Build Image + +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: "" + +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..d1cc7e843f 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 }} ${{ env.IMAGE_REPO }}:${{ 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/.github/workflows/test-e2e.yaml b/.github/workflows/test-e2e.yaml index 4c7cd78468..420e6e5697 100644 --- a/.github/workflows/test-e2e.yaml +++ b/.github/workflows/test-e2e.yaml @@ -1,10 +1,6 @@ name: TestSuite E2E on: - pull_request: - branches: - - main - - feat/** workflow_dispatch: inputs: k8s_version: @@ -12,18 +8,12 @@ on: required: false 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' }} + build-image: + name: Build Image + uses: ./.github/workflows/build-image.yml e2e-integration: name: E2E - needs: wait-for-image-build + needs: build-image strategy: fail-fast: false matrix: 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: diff --git a/scripts/release/get_last_release.sh b/scripts/release/get_last_release.sh deleted file mode 100755 index 7fa33aab17..0000000000 --- a/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 -