Skip to content

Commit

Permalink
fix: Use github action create release (#1835)
Browse files Browse the repository at this point in the history
* refactor create release github action
---------

Co-authored-by: Jeremy Harisch <[email protected]>
Co-authored-by: Tomasz Smelcerz <[email protected]>
  • Loading branch information
3 people authored Sep 11, 2024
1 parent 8474607 commit 9dee979
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 146 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand All @@ -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"


Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -23,3 +24,4 @@ if [[ $CURL_EXIT_CODE == 0 ]]; then
exit 1
fi


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

Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
44 changes: 44 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -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 }}
104 changes: 34 additions & 70 deletions .github/workflows/create-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
18 changes: 4 additions & 14 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
name: TestSuite E2E

on:
pull_request:
branches:
- main
- feat/**
workflow_dispatch:
inputs:
k8s_version:
description: With Kubernetes version
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:
Expand Down
14 changes: 4 additions & 10 deletions .github/workflows/test-smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 9dee979

Please sign in to comment.