generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: Bump go version and setup action * add dependabot actions scan * remove windows builds * rename workflow files to yml * add workflows * add version cmd * add release workflow * fix * fix * fix * gend ocs
- Loading branch information
Showing
18 changed files
with
393 additions
and
13 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,36 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
CURRENT_RELEASE_TAG=$1 | ||
DOCKER_IMAGE_URL=$2 | ||
LAST_RELEASE_TAG=$3 | ||
|
||
if [ "${LAST_RELEASE_TAG}" == "" ] | ||
then | ||
LAST_RELEASE_TAG=$(git describe --tags --abbrev=0) | ||
fi | ||
|
||
GITHUB_URL=https://api.github.com/repos/$CODE_REPOSITORY | ||
GITHUB_AUTH_HEADER="Authorization: Bearer $GITHUB_TOKEN" | ||
CHANGELOG_FILE="CHANGELOG.md" | ||
|
||
git log "$LAST_RELEASE_TAG"..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 | ||
|
||
{ | ||
echo -e "\n**Full changelog**: $GITHUB_URL/compare/$LAST_RELEASE_TAG...$CURRENT_RELEASE_TAG" | ||
echo -e "\n" | ||
echo "## Docker image URL" | ||
echo "$DOCKER_IMAGE_URL" | ||
} >> $CHANGELOG_FILE | ||
|
||
cat $CHANGELOG_FILE |
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,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
RELEASE_TAG=$1 | ||
|
||
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" \ | ||
--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,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
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" | ||
|
||
curl -L \ | ||
-s \ | ||
--fail-with-body \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "$GITHUB_AUTH_HEADER" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"$GITHUB_URL"/releases/tags/"$RELEASE_TAG" | ||
|
||
CURL_EXIT_CODE=$? | ||
|
||
if [[ $CURL_EXIT_CODE == 0 ]]; then | ||
echo "Release with tag $RELEASE_TAG already exists!" | ||
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,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
RELEASE_ID=$1 | ||
|
||
GITHUB_URL=https://api.github.com/repos/${CODE_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_ID}" \ | ||
-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,58 @@ | ||
#!/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 $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}" | ||
|
||
echo "Fetching releases" | ||
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/modulectl/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/modulectl/releases/${RELEASE_ID}/assets" | ||
|
||
echo "$UPLOAD_URL" | ||
pwd | ||
ls -la | ||
uploadFile "modulectl-linux" "${UPLOAD_URL}?name=modulectl-linux" |
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,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -o nounset | ||
set -o errexit | ||
set -E | ||
set -o pipefail | ||
|
||
CURRENT_RELEASE_TAG=$1 | ||
|
||
semver_pattern="^([0-9]|[1-9][0-9]*)[.]([0-9]|[1-9][0-9]*)[.]([0-9]|[1-9][0-9]*)(-[a-z][a-z0-9]*)?$" | ||
|
||
if ! [[ $CURRENT_RELEASE_TAG =~ $semver_pattern ]]; then | ||
echo "Given tag \"$CURRENT_RELEASE_TAG\" does not match semantic version pattern: \"$semver_pattern\"." | ||
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 |
---|---|---|
|
@@ -3,7 +3,6 @@ on: | |
pull_request: | ||
branches: | ||
- main | ||
- 'release-**' | ||
workflow_dispatch: | ||
jobs: | ||
build-modulectl: | ||
|
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,81 @@ | ||
name: "Create release" | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
description: "Release version" | ||
default: "" | ||
required: true | ||
since: | ||
description: "Changelog since" | ||
default: "" | ||
required: false | ||
|
||
jobs: | ||
validate-release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Validate the release tag | ||
run: ./.github/scripts/validate_release_tag.sh ${{ github.event.inputs.version }} | ||
- name: Check if release exists | ||
run: ./.github/scripts/get_release_by_tag.sh ${{ github.event.inputs.version }} ${{ secrets.GITHUB_TOKEN }} | ||
draft-release: | ||
runs-on: ubuntu-latest | ||
needs: validate-release | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Create changelog | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./.github/scripts/create_changelog.sh ${{ github.event.inputs.version }} ${{ env.IMAGE_REPO }}:${{ github.event.inputs.version }} ${{ github.event.inputs.since }} | ||
- name: Draft release | ||
id: draft-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
RELEASE_ID=$(./.github/scripts/draft_release.sh ${{ github.event.inputs.version }}) | ||
echo "release_id=$RELEASE_ID" >> $GITHUB_OUTPUT | ||
- name: Create tag | ||
run: | | ||
git tag ${{ github.event.inputs.version }} | ||
git push origin ${{ github.event.inputs.version }} --tags | ||
outputs: | ||
release_id: ${{ steps.draft-release.outputs.release_id }} | ||
artifacts: | ||
runs-on: ubuntu-latest | ||
needs: validate-release | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Go setup | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: 'go.mod' | ||
cache-dependency-path: 'go.sum' | ||
- name: "Run 'make build' with version" | ||
run: make build VERSION=${{ inputs.version }} | ||
- name: Add binaries to draft | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PULL_BASE_REF: ${{ github.event.inputs.version }} | ||
run: ./.github/scripts/upload_assets.sh | ||
publish-release: | ||
runs-on: ubuntu-latest | ||
needs: [ validate-release, draft-release, artifacts ] | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Publish release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} |
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package version | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
use = "version" | ||
short = "Prints the current modulectl version." | ||
long = "This command prints the current semantic version of the modulectl binary set at build time." | ||
) | ||
|
||
// Version will contain the binary version injected by make build target | ||
var Version string //nolint:gochecknoglobals // This is a variable meant to be set at build time | ||
|
||
func NewCmd() (*cobra.Command, error) { | ||
cmd := &cobra.Command{ | ||
Use: use, | ||
Short: short, | ||
Long: long, | ||
Args: cobra.NoArgs, | ||
Aliases: []string{"v"}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Println(Version) | ||
}, | ||
} | ||
|
||
return cmd, nil | ||
} |
Oops, something went wrong.