forked from kyma-project/busola
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create release process (kyma-project#3485)
* wip * wip * wip * wip * adjust resources * fix * improvement * improvement * improvement * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * adjustment before review * add busola-local build and fix after review * small fix * fix typo * use correct workflow --------- Co-authored-by: Mateusz Wisniewski <[email protected]>
- Loading branch information
1 parent
5ce3857
commit 1695507
Showing
16 changed files
with
248 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
PREVIOUS_RELEASE=$2 # for testability | ||
|
||
# standard bash error handling | ||
set -o nounset # treat unset variables as an error and exit immediately. | ||
set -o errexit # exit immediately when a command fails. | ||
set -E # needs to be set if we want the ERR trap | ||
set -o pipefail # prevents errors in a pipeline from being masked | ||
RELEASE_TAG=$1 | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/busola} | ||
GITHUB_URL=https://api.github.com/repos/${REPOSITORY} | ||
GITHUB_AUTH_HEADER="Authorization: token ${GITHUB_TOKEN}" | ||
CHANGELOG_FILE="CHANGELOG.md" | ||
|
||
if [ "${PREVIOUS_RELEASE}" == "" ] | ||
then | ||
PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) | ||
fi | ||
echo "Previous release: ${PREVIOUS_RELEASE}" | ||
|
||
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=$(mktemp --suffix=.new XXXXX) | ||
|
||
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}" ] #reference found | ||
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_TAG}" >> ${CHANGELOG_FILE} | ||
|
||
# cleanup | ||
rm "${NEW_CONTRIB}" || echo "cleaned up" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script returns the id of the draft release | ||
|
||
# standard bash error handling | ||
set -o nounset # treat unset variables as an error and exit immediately. | ||
set -o errexit # exit immediately when a command fails. | ||
set -E # needs to be set if we want the ERR trap | ||
set -o pipefail # prevents errors in a pipeline from being masked | ||
|
||
RELEASE_TAG=$1 | ||
>&2 echo "Creating draft release: ${RELEASE_TAG}" | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/busola} | ||
GITHUB_URL=https://api.github.com/repos/${REPOSITORY} | ||
GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" | ||
CHANGELOG_FILE=$(cat CHANGELOG.md) | ||
|
||
JSON_PAYLOAD=$(jq -n \ | ||
--arg tag_name "$RELEASE_TAG" \ | ||
--arg name "$RELEASE_TAG" \ | ||
--arg body "$CHANGELOG_FILE" \ | ||
'{ | ||
"tag_name": $tag_name, | ||
"name": $name, | ||
"body": $body, | ||
"draft": true | ||
}') | ||
|
||
CURL_RESPONSE=$(curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "${GITHUB_AUTH_HEADER}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
${GITHUB_URL}/releases \ | ||
-d "$JSON_PAYLOAD") | ||
|
||
echo "$(echo $CURL_RESPONSE | jq -r ".id")" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script publishes a draft release | ||
|
||
# standard bash error handling | ||
set -o nounset # treat unset variables as an error and exit immediately. | ||
set -o errexit # exit immediately when a command fails. | ||
set -E # needs to be set if we want the ERR trap | ||
set -o pipefail # prevents errors in a pipeline from being masked | ||
|
||
RELEASE_ID=${RELEASE_ID?"Release id is not defined"} | ||
IS_LATEST_RELEASE=${IS_LATEST_RELEASE?"latest release not defined"} | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/busola} | ||
GITHUB_URL=https://api.github.com/repos/${REPOSITORY} | ||
GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" | ||
|
||
CURL_RESPONSE=$(curl -w "%{http_code}" -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "${GITHUB_AUTH_HEADER}" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
${GITHUB_URL}/releases/${RELEASE_ID} \ | ||
-d '{"draft": false, "make_latest": '"$IS_LATEST_RELEASE"'}') | ||
|
||
HTTP_CODE=$(tail -n1 <<< "${CURL_RESPONSE}") | ||
if [[ "${HTTP_CODE}" != "200" ]]; then | ||
echo "${CURL_RESPONSE}" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/bash | ||
|
||
# standard bash error handling | ||
set -o nounset # treat unset variables as an error and exit immediately. | ||
set -o errexit # exit immediately when a command fails. | ||
set -E # needs to be set if we want the ERR trap | ||
set -o pipefail # prevents errors in a pipeline from being masked | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/busola} | ||
RELEASE_TAG=${RELEASE_TAG?"Release tag is not defined"} | ||
RELEASE_ID=${RELEASE_ID?"Release id is not defined"} | ||
|
||
|
||
uploadFile() { | ||
filePath=${1} | ||
ghAsset=${2} | ||
|
||
echo "Uploading ${filePath} as ${ghAsset}" | ||
response=$(curl -s -o output.txt -w "%{http_code}" \ | ||
--request POST --data-binary @"$filePath" \ | ||
-H "Authorization: token $GITHUB_TOKEN" \ | ||
-H "Content-Type: text/yaml" \ | ||
$ghAsset) | ||
if [[ "$response" != "201" ]]; then | ||
echo "Unable to upload the asset ($filePath): " | ||
echo "HTTP Status: $response" | ||
cat output.txt | ||
exit 1 | ||
else | ||
echo "$filePath uploaded" | ||
fi | ||
} | ||
|
||
BUSOLA_K8S="busola.yaml" | ||
generate_k8s() { | ||
set -x | ||
cd resources | ||
(cd base/web && kustomize edit set image busola-web=europe-docker.pkg.dev/kyma-project/prod/busola-web:"${RELEASE_TAG}") | ||
(cd base/backend && kustomize edit set image busola-backend=europe-docker.pkg.dev/kyma-project/prod/busola-backend:"${RELEASE_TAG}") | ||
kustomize build base/ > ../"${BUSOLA_K8S}" | ||
cd - | ||
} | ||
|
||
echo "Updating github release with assets" | ||
UPLOAD_URL="https://uploads.github.com/repos/${REPOSITORY}/releases/${RELEASE_ID}/assets" | ||
|
||
generate_k8s | ||
uploadFile ${BUSOLA_K8S} "${UPLOAD_URL}?name=${BUSOLA_K8S}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.