Skip to content

Commit

Permalink
Fix release of manifests (#340)
Browse files Browse the repository at this point in the history
* clean up create-release.yml

Clean up the create-release.yml by removing a number of unused and outcommented lines.

* rename release.sh to render_and_upload_manifests.sh

Rename the scripts/release.sh to render_and_upload_manifests.sh to point clearly out, what the script is about.

* call manifest release from create-release.yml

Call the render_and_upload_manifests.sh because it no longer created by a prow job.

* deactivate module-template upload

Deactivate the upload of the module-template. All functionality for the module-template will be removed eventually, in a follow up PR.

* fix reference of env var
  • Loading branch information
friedrichwilken authored Dec 15, 2023
1 parent 29e19fa commit a5d84e4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ jobs:
- name: Check image Tag
run: ./scripts/check_tag_info.sh ${{ github.event.inputs.name }}

# run-unit-tests:
# name: Unit tests
# needs: verify-head-status
# uses: "./.github/workflows/run-unit-tests.yaml"

create-draft:
name: Create draft release
needs: verify-head-status
Expand Down Expand Up @@ -69,14 +64,16 @@ jobs:
- name: Verify job status
run: ./scripts/verify-status.sh ${{ github.ref_name }} 600 10 30

- name: Create and upload eventing-manager.yaml and eventing-default-cr.yaml
env:
PULL_BASE_REF: ${{ PULL_BASE_REF }}
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
run: |
./scripts/render_and_upload_manifests.sh ${{ PULL_BASE_REF }} ${{ BOT_GITHUB_TOKEN }}
outputs:
release_id: ${{ steps.create-draft.outputs.release_id }}

# devOps-Insights:
# name: DevOps Insights
# needs: [verify-head-status, create-draft, run-unit-tests]
# uses: "./.github/workflows/metrics.yaml"

publish-release:
name: Publish release
needs: [verify-head-status, create-draft]
Expand Down
59 changes: 30 additions & 29 deletions scripts/release.sh → scripts/render_and_upload_manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ set -o pipefail # prevents errors in a pipeline from being masked
# BOT_GITHUB_TOKEN - github token used to upload the template yaml

uploadFile() {
filePath=${1}
ghAsset=${2}
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 $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 "Uploading ${filePath} as ${ghAsset}"
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}"
Expand All @@ -39,33 +39,34 @@ cat eventing-manager.yaml

MODULE_VERSION=${PULL_BASE_REF} make module-build

echo "Generated moduletemplate.yaml:"
cat module-template.yaml
# TODO completly remove the rendering of the module-template from the repository.
# echo "Generated moduletemplate.yaml:"
# cat module-template.yaml

echo "Updating github release with eventing-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/eventing-manager/releases)
JSON_RESPONSE=$(sed '$ d' <<< "${CURL_RESPONSE}")
HTTP_CODE=$(tail -n1 <<< "${CURL_RESPONSE}")
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $BOT_GITHUB_TOKEN" \
https://api.github.com/repos/kyma-project/eventing-manager/releases)
JSON_RESPONSE=$(sed '$ d' <<<"${CURL_RESPONSE}")
HTTP_CODE=$(tail -n1 <<<"${CURL_RESPONSE}")
if [[ "${HTTP_CODE}" != "200" ]]; then
echo "${JSON_RESPONSE}" && exit 1
echo "${JSON_RESPONSE}" && exit 1
fi

echo "Finding release id for: ${PULL_BASE_REF}"
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
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/eventing-manager/releases/${RELEASE_ID}/assets"

uploadFile "eventing-manager.yaml" "${UPLOAD_URL}?name=eventing-manager.yaml"
uploadFile "module-template.yaml" "${UPLOAD_URL}?name=module-template.yaml"
# TODO completly remove the rendering of the module-template from the repository.
# uploadFile "module-template.yaml" "${UPLOAD_URL}?name=module-template.yaml"
uploadFile "config/samples/default.yaml" "${UPLOAD_URL}?name=eventing_default_cr.yaml"

0 comments on commit a5d84e4

Please sign in to comment.