Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use github action create release #1835

Merged
merged 9 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/scripts/release/create_changelog.sh
Original file line number Diff line number Diff line change
@@ -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"
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"


ruanxin marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
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
46 changes: 46 additions & 0 deletions .github/workflows/build-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: ""
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 }}
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 }} ${{ 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 }}
21 changes: 6 additions & 15 deletions .github/workflows/test-e2e.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
31 changes: 0 additions & 31 deletions scripts/release/create_changelog.sh

This file was deleted.

Loading