Skip to content

Commit

Permalink
chore: Check if release already exists (#256)
Browse files Browse the repository at this point in the history
<!-- Thank you for your contribution. Before you submit the pull
request:
1. Follow contributing guidelines, templates, the recommended Git
workflow, and any related documentation.
2. Read and submit the required Contributor Licence Agreements
(https://github.com/kyma-project/community/blob/main/CONTRIBUTING.md#agreements-and-licenses).
3. Test your changes and attach their results to the pull request.
4. Update the relevant documentation.

If the pull request requires a decision, follow the [decision-making
process](https://github.com/kyma-project/community/blob/main/governance.md)
and replace the PR template with the [decision record
template](https://github.com/kyma-project/community/blob/main/.github/ISSUE_TEMPLATE/decision-record.md).
-->

**Description**


**Related issue(s)**
<!-- If you refer to a particular issue, provide its number. For
example, `Resolves #123`, `Fixes #43`, or `See also #33`. -->
  • Loading branch information
ruanxin authored Sep 6, 2024
1 parent cce831f commit 43f4e97
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
#!/usr/bin/env bash

PREVIOUS_RELEASE=$2

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

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"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
26 changes: 26 additions & 0 deletions .github/scripts/release/get_release_by_tag.sh
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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: |
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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 }}

0 comments on commit 43f4e97

Please sign in to comment.