generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #117 from lindnerby/add-release-pipeline
feat: Add release workflow dispatch
- Loading branch information
Showing
15 changed files
with
310 additions
and
7 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,72 @@ | ||
name: "Create release" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
name: | ||
description: "Release name" | ||
default: "" | ||
required: true | ||
since: | ||
description: "Changelog since" | ||
default: "" | ||
required: false | ||
|
||
jobs: | ||
validate-head-status: | ||
name: Validate HEAD | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
shell: bash | ||
working-directory: ./scripts/release/ | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Validate set versions | ||
run: ./validate_versions.sh ${{ github.event.inputs.name }} | ||
- name: Validate pipeline status | ||
run: ./validate_pipeline_status.sh ${{ github.ref_name }} | ||
|
||
draft-release: | ||
name: Draft release | ||
needs: validate-head-status | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Create changelog | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./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 }} | ||
run: | | ||
RELEASE_ID=$(./scripts/release/draft_release.sh ${{ github.event.inputs.name }}) | ||
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT | ||
- name: Create lightweight tag | ||
run: | | ||
git tag ${{ github.event.inputs.name }} | ||
git push origin ${{ github.event.inputs.name }} | ||
outputs: | ||
release_id: ${{ steps.draft-release.outputs.release_id }} | ||
|
||
publish-release: | ||
name: Publish release | ||
needs: [validate-head-status, draft-release] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Publish release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./scripts/release/publish_release.sh ${{ needs.draft-release.outputs.release_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 @@ | ||
MODULE_VERSION=0.1.0 |
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
File renamed without changes.
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
File renamed without changes.
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,53 @@ | ||
#!/usr/bin/env bash | ||
|
||
PREVIOUS_RELEASE=$2 | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
RELEASE_VERSION=$1 | ||
|
||
if [ "${PREVIOUS_RELEASE}" == "" ] | ||
then | ||
PREVIOUS_RELEASE=$(git describe --tags --abbrev=0) | ||
fi | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/template-operator} | ||
GITHUB_URL=https://api.github.com/repos/${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" |
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,35 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
RELEASE_TAG=$1 | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/template-operator} | ||
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") | ||
|
||
# return the id of the release draft | ||
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,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
RELEASE_VERSION=$1 | ||
|
||
REPOSITORY=${REPOSITORY:-kyma-project/template-operator} | ||
GITHUB_URL=https://api.github.com/repos/${REPOSITORY} | ||
GITHUB_AUTH_HEADER="Authorization: Bearer ${GITHUB_TOKEN}" | ||
|
||
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/"${RELEASE_VERSION}" \ | ||
-d '{"draft":false}') | ||
echo "$CURL_RESPONSE" |
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,68 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
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 $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 template-operator.yaml:" | ||
cat template-operator.yaml | ||
|
||
MODULE_VERSION=${PULL_BASE_REF} make module-build | ||
|
||
echo "Generated moduletemplate.yaml:" | ||
cat moduletemplate.yaml | ||
|
||
echo "Fetching releases" | ||
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/template-operator/releases) | ||
JSON_RESPONSE=$(sed '$ d' <<< "${CURL_RESPONSE}") | ||
HTTP_CODE=$(tail -n1 <<< "${CURL_RESPONSE}") | ||
if [[ "${HTTP_CODE}" != "200" ]]; then | ||
echo "${CURL_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') | ||
|
||
echo "Got '${RELEASE_ID}' release id" | ||
if [ -z "${RELEASE_ID}" ] | ||
then | ||
echo "No release with tag = ${PULL_BASE_REF}" | ||
exit 1 | ||
fi | ||
|
||
echo "Adding assets to Github release" | ||
UPLOAD_URL="https://uploads.github.com/repos/kyma-project/template-operator/releases/${RELEASE_ID}/assets" | ||
|
||
uploadFile "template-operator.yaml" "${UPLOAD_URL}?name=template-operator.yaml" | ||
uploadFile "moduletemplate.yaml" "${UPLOAD_URL}?name=moduletemplate.yaml" | ||
uploadFile "config/samples/default-sample-cr.yaml" "${UPLOAD_URL}?name=default-sample-cr.yaml" | ||
uploadFile "module-config.yaml" "${UPLOAD_URL}?name=module-config.yaml" |
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,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Checking status of 'post-*' pipelines for template-operator" | ||
REF_NAME="${1:-"main"}" | ||
STATUS_URL="https://api.github.com/repos/kyma-project/template-operator/commits/${REF_NAME}/status" | ||
STATUS=$(curl -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "${STATUS_URL}" | head -n 2 ) | ||
if [[ "$STATUS" == *"success"* ]]; then | ||
echo "All recent jobs succeeded, post-pipelines are green." | ||
else | ||
echo "Latest post-pipelines are failing or pending! Reason:" | ||
echo "$STATUS" | ||
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,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ue | ||
source ./../../.version | ||
|
||
DESIRED_VERSION=$1 | ||
if [[ "$DESIRED_VERSION" != "$MODULE_VERSION" ]]; then | ||
echo "Versions don't match! Expected ${MODULE_VERSION} but got $DESIRED_VERSION." | ||
echo "Please update .version file or change desired version!" | ||
exit 1 | ||
fi | ||
echo "Versions match." | ||
|
||
IMAGE_TO_CHECK="${2:-europe-docker.pkg.dev/kyma-project/prod/template-operator}" | ||
BUMPED_IMAGE_TAG=$(grep "${IMAGE_TO_CHECK}" ../../sec-scanners-config.yaml | cut -d : -f 2) | ||
if [[ "$BUMPED_IMAGE_TAG" != "$DESIRED_VERSION" ]]; then | ||
echo "Version tag in sec-scanners-config.yaml file is incorrect!" | ||
echo "Could not find $DESIRED_VERSION." | ||
exit 1 | ||
fi | ||
echo "Image version tag in sec-scanners-config.yaml does match with release tag." | ||
exit 0 |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
module-name: template-operator | ||
rc-tag: 0.5.0 | ||
dev-branch: main | ||
protecode: | ||
- europe-docker.pkg.dev/kyma-project/prod/template-operator:0.1.0 | ||
whitesource: | ||
language: golang-mod | ||
subprojects: false | ||
exclude: | ||
- "**/test/**" | ||
- "**/*_test.go" | ||
- "**/*_test.go" |