diff --git a/scripts/release/create_changelog.sh b/.github/scripts/release/create_changelog.sh similarity index 93% rename from scripts/release/create_changelog.sh rename to .github/scripts/release/create_changelog.sh index e2dbb85..c4d10cb 100755 --- a/scripts/release/create_changelog.sh +++ b/.github/scripts/release/create_changelog.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -PREVIOUS_RELEASE=$2 set -o nounset set -o errexit @@ -8,14 +7,15 @@ set -E set -o pipefail RELEASE_VERSION=$1 +PREVIOUS_RELEASE=$2 + if [ "${PREVIOUS_RELEASE}" == "" ] then PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) fi -REPOSITORY=${REPOSITORY:-kyma-project/template-operator} -GITHUB_URL=https://api.github.com/repos/${REPOSITORY} +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} GITHUB_AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" CHANGELOG_FILE="CHANGELOG.md" diff --git a/scripts/release/draft_release.sh b/.github/scripts/release/draft_release.sh similarity index 86% rename from scripts/release/draft_release.sh rename to .github/scripts/release/draft_release.sh index bc7cc7b..81b638b 100755 --- a/scripts/release/draft_release.sh +++ b/.github/scripts/release/draft_release.sh @@ -7,8 +7,7 @@ set -o pipefail RELEASE_TAG=$1 -REPOSITORY=${REPOSITORY:-kyma-project/template-operator} -GITHUB_URL=https://api.github.com/repos/${REPOSITORY} +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" CHANGELOG_FILE=$(cat CHANGELOG.md) diff --git a/.github/scripts/release/get_release_by_tag.sh b/.github/scripts/release/get_release_by_tag.sh new file mode 100755 index 0000000..7628cf6 --- /dev/null +++ b/.github/scripts/release/get_release_by_tag.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +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" + +curl -L \ + -s \ + --fail-with-body \ + -H "Accept: application/vnd.github+json" \ + -H "$GITHUB_AUTH_HEADER" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "$GITHUB_URL"/releases/tags/"$RELEASE_TAG" + +CURL_EXIT_CODE=$? + +if [[ $CURL_EXIT_CODE == 0 ]]; then + echo "Release with tag: $RELEASE_TAG already exists!" + exit 1 +fi + diff --git a/scripts/release/publish_release.sh b/.github/scripts/release/publish_release.sh similarity index 78% rename from scripts/release/publish_release.sh rename to .github/scripts/release/publish_release.sh index 9faa6a9..f666815 100755 --- a/scripts/release/publish_release.sh +++ b/.github/scripts/release/publish_release.sh @@ -7,8 +7,7 @@ set -o pipefail RELEASE_VERSION=$1 -REPOSITORY=${REPOSITORY:-kyma-project/template-operator} -GITHUB_URL=https://api.github.com/repos/${REPOSITORY} +GITHUB_URL=https://api.github.com/repos/${CODE_REPOSITORY} GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" CURL_RESPONSE=$(curl -L \ diff --git a/scripts/release/upload_assets.sh b/.github/scripts/release/upload_assets.sh similarity index 100% rename from scripts/release/upload_assets.sh rename to .github/scripts/release/upload_assets.sh diff --git a/scripts/release/validate_release_tag.sh b/.github/scripts/release/validate_release_tag.sh similarity index 100% rename from scripts/release/validate_release_tag.sh rename to .github/scripts/release/validate_release_tag.sh 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 index 6147316..fb36c61 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -22,7 +22,7 @@ jobs: compute-tag: runs-on: ubuntu-latest outputs: - tag: ${{ steps.get_tag.outputs.TAG }} + tag: ${{ steps.get_tag.outputs.tag }} steps: - name: Checkout uses: actions/checkout@v4 @@ -35,7 +35,7 @@ jobs: echo "tag=latest" >> $GITHUB_OUTPUT fi - name: Echo the tag - run: echo ${{ steps.get_tag.outputs.TAG }} + run: echo ${{ steps.get_tag.outputs.tag }} build-image: needs: compute-tag uses: kyma-project/test-infra/.github/workflows/image-builder.yml@main diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index d60ba0e..02be957 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -2,6 +2,7 @@ name: "Create release" env: IMAGE_REPO: europe-docker.pkg.dev/kyma-project/prod/template-operator + CODE_REPOSITORY: kyma-project/template-operator on: workflow_dispatch: inputs: @@ -15,24 +16,21 @@ on: required: false jobs: - validate-head-status: - name: Validate HEAD + validate-release: + name: Validate release runs-on: ubuntu-latest - defaults: - run: - shell: bash - working-directory: ./scripts/release/ steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Validate the release tag - run: ./validate_release_tag.sh ${{ github.event.inputs.name }} - + run: ./.github/scripts/release/validate_release_tag.sh ${{ github.event.inputs.name }} + - name: Check if release doesn't exist yet + run: ./.github/scripts/release/get_release_by_tag.sh ${{ github.event.inputs.name }} ${{ secrets.GITHUB_TOKEN }} draft-release: name: Draft release - needs: validate-head-status + needs: validate-release runs-on: ubuntu-latest steps: - name: Checkout code @@ -42,13 +40,13 @@ jobs: - name: Create changelog env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./scripts/release/create_changelog.sh ${{ github.event.inputs.name }} ${{ github.event.inputs.since }} + 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 }} run: | - RELEASE_ID=$(./scripts/release/draft_release.sh ${{ github.event.inputs.name }}) + RELEASE_ID=$(./.github/scripts/release/draft_release.sh ${{ github.event.inputs.name }}) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT - name: Create tag run: | @@ -59,7 +57,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PULL_BASE_REF: ${{ github.event.inputs.name }} - run: ./scripts/release/upload_assets.sh + run: ./.github/scripts/release/upload_assets.sh outputs: release_id: ${{ steps.draft-release.outputs.release_id }} builds: @@ -69,7 +67,7 @@ jobs: tag: "${{ github.event.inputs.name }}" publish-release: name: Publish release - needs: [validate-head-status, draft-release, builds] + needs: [validate-release, draft-release, builds] runs-on: ubuntu-latest steps: - name: Checkout code @@ -81,8 +79,8 @@ jobs: env: ITERATIONS: 40 SLEEP_SECONDS: 30 - run: ./scripts/release/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.name }} $ITERATIONS $SLEEP_SECONDS + 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 }} - run: ./scripts/release/publish_release.sh ${{ needs.draft-release.outputs.release_id }} + run: ./.github/scripts/release/publish_release.sh ${{ needs.draft-release.outputs.release_id }}