From c7923d4e315930f669d832d0ef99f0af1efbbba4 Mon Sep 17 00:00:00 2001 From: Friedrich Wilken Date: Mon, 18 Dec 2023 19:27:09 +0100 Subject: [PATCH] remove module template rendering --- .github/workflows/create-release.yaml | 15 +++++- scripts/release.sh | 69 -------------------------- scripts/render_and_upload_manifests.sh | 62 +++++++++++++++++++++++ 3 files changed, 76 insertions(+), 70 deletions(-) delete mode 100755 scripts/release.sh create mode 100755 scripts/render_and_upload_manifests.sh diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml index c6c3a038..6068465f 100644 --- a/.github/workflows/create-release.yaml +++ b/.github/workflows/create-release.yaml @@ -54,11 +54,24 @@ jobs: RELEASE_ID=$(./scripts/create_draft_release.sh ${{ github.event.inputs.name }}) echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT - - name: Create lightweight tag + - name: Trigger 'release-nats-manager-build' prow job run: | git tag ${{ github.event.inputs.name }} git push origin ${{ github.event.inputs.name }} + - name: Wait for 'release-nats-manager-build' + run: ./scripts/verify-status.sh ${{ github.ref_name }} 600 10 30 + + - name: Create and upload nats-manager.yaml and nats-default-cr.yaml + env: + BASE_REF: ${{ github.event.inputs.name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + IMG: "europe-docker.pkg.dev/kyma-project/prod/nats-manager:${{ github.event.inputs.name }}" + MODULE_REGISTRY: "europe-docker.pkg.dev/kyma-project/prod/unsigned" + KUSTOMIZE_VERSION: "v4.5.6" + run: | + ./scripts/render_and_upload_manifests.sh + outputs: release_id: ${{ steps.create-draft.outputs.release_id }} diff --git a/scripts/release.sh b/scripts/release.sh deleted file mode 100755 index 03ac301c..00000000 --- a/scripts/release.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/env 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 - -# Expected variables: -# PULL_BASE_REF - name of the tag -# BOT_GITHUB_TOKEN - github token used to upload the template yaml - -uploadFile() { - filePath=${1} - ghAsset=${2} - - response=$(curl -s -o output.txt -w "%{http_code}" \ - --request POST --data-binary @"$filePath" \ - -H "Authorization: token $BOT_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 -} - -echo "PULL_BASE_REF ${PULL_BASE_REF}" - -MODULE_VERSION=${PULL_BASE_REF} make render-manifest - -echo "Generated nats-manager.yaml:" -cat nats-manager.yaml - -MODULE_VERSION=${PULL_BASE_REF} make module-build - -echo "Generated moduletemplate.yaml:" -cat module-template.yaml - -echo "Updating github release with nats-manager.yaml" - -echo "Finding release id for: ${PULL_BASE_REF}" -CURL_RESPONSE=$(curl -w "%{http_code}" -sL \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer $BOT_GITHUB_TOKEN"\ - https://api.github.com/repos/kyma-project/nats-manager/releases) -JSON_RESPONSE=$(sed '$ d' <<< "${CURL_RESPONSE}") -HTTP_CODE=$(tail -n1 <<< "${CURL_RESPONSE}") -if [[ "${HTTP_CODE}" != "200" ]]; then - echo "${JSON_RESPONSE}" && exit 1 -fi - -RELEASE_ID=$(jq <<< ${JSON_RESPONSE} --arg tag "${PULL_BASE_REF}" '.[] | select(.tag_name == $ARGS.named.tag) | .id') - -if [ -z "${RELEASE_ID}" ] -then - echo "No release with tag = ${PULL_BASE_REF}" - exit 1 -fi - -UPLOAD_URL="https://uploads.github.com/repos/kyma-project/nats-manager/releases/${RELEASE_ID}/assets" - -uploadFile "nats-manager.yaml" "${UPLOAD_URL}?name=nats-manager.yaml" -uploadFile "module-template.yaml" "${UPLOAD_URL}?name=module-template.yaml" -uploadFile "config/samples/default.yaml" "${UPLOAD_URL}?name=nats_default_cr.yaml" diff --git a/scripts/render_and_upload_manifests.sh b/scripts/render_and_upload_manifests.sh new file mode 100755 index 00000000..a5654309 --- /dev/null +++ b/scripts/render_and_upload_manifests.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env 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 + +# Expected variables: +# BASE_REF - name of the tag +# GITHUB_TOKEN - github token used to upload the template yaml + +uploadFile() { + filePath=${1} + ghAsset=${2} + + 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 +} + +echo "BASE_REF ${BASE_REF}" + +MODULE_VERSION=${BASE_REF} make render-manifest + +echo "Generated nats-manager.yaml:" +cat nats-manager.yaml + +echo "Updating github release with nats-manager.yaml" + +echo "Finding release id for: ${BASE_REF}" +CURL_RESPONSE=$(curl -w "%{http_code}" -sL \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer $GITHUB_TOKEN" \ + https://api.github.com/repos/kyma-project/nats-manager/releases) +JSON_RESPONSE=$(sed '$ d' <<<"${CURL_RESPONSE}") +HTTP_CODE=$(tail -n1 <<<"${CURL_RESPONSE}") +if [[ "${HTTP_CODE}" != "200" ]]; then + echo "${JSON_RESPONSE}" && exit 1 +fi + +RELEASE_ID=$(jq <<<${JSON_RESPONSE} --arg tag "${BASE_REF}" '.[] | select(.tag_name == $ARGS.named.tag) | .id') + +if [ -z "${RELEASE_ID}" ]; then + echo "No release with tag = ${BASE_REF}" + exit 1 +fi + +UPLOAD_URL="https://uploads.github.com/repos/kyma-project/nats-manager/releases/${RELEASE_ID}/assets" + +uploadFile "nats-manager.yaml" "${UPLOAD_URL}?name=nats-manager.yaml" +uploadFile "config/samples/default.yaml" "${UPLOAD_URL}?name=nats_default_cr.yaml"