From a5512c96dde1922e9868cea70afc529c55c36ba3 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Wed, 2 Oct 2024 15:49:29 +0200 Subject: [PATCH 01/13] chore: Bump go version and setup action --- .github/workflows/build.yaml | 2 +- .github/workflows/lint-golangci.yml | 2 +- .github/workflows/test-e2e-create.yml | 2 +- .github/workflows/test-e2e-scaffold.yml | 2 +- .github/workflows/test-unit.yaml | 2 +- go.mod | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e82b1bf7..f07ff0f2 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -12,7 +12,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Go setup - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' diff --git a/.github/workflows/lint-golangci.yml b/.github/workflows/lint-golangci.yml index b4f019b2..d18fcf33 100644 --- a/.github/workflows/lint-golangci.yml +++ b/.github/workflows/lint-golangci.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: actions/setup-go@v4 + - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache: false diff --git a/.github/workflows/test-e2e-create.yml b/.github/workflows/test-e2e-create.yml index 58701af8..620da1d4 100644 --- a/.github/workflows/test-e2e-create.yml +++ b/.github/workflows/test-e2e-create.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Go setup - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' diff --git a/.github/workflows/test-e2e-scaffold.yml b/.github/workflows/test-e2e-scaffold.yml index cb80b104..4a8ad950 100644 --- a/.github/workflows/test-e2e-scaffold.yml +++ b/.github/workflows/test-e2e-scaffold.yml @@ -11,7 +11,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 - name: Go setup - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 205a0f94..fda2cc0b 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -13,7 +13,7 @@ jobs: - name: Checkout modulectl uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' diff --git a/go.mod b/go.mod index 89a34448..21e61ce7 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/kyma-project/modulectl -go 1.22.7 +go 1.23.2 require ( github.com/Masterminds/semver/v3 v3.3.0 From ea7f60775f627f5da36995d78cecc7cabe8a4276 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Wed, 2 Oct 2024 16:06:58 +0200 Subject: [PATCH 02/13] add dependabot actions scan --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 71f2ad92..4f50120c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -2,6 +2,12 @@ version: 2 updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: "chore(dependabot)" - package-ecosystem: "gomod" directory: "/" labels: From 4a3ac8babcfbd6a2b7c4789992ae999e8842d174 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 08:27:18 +0200 Subject: [PATCH 03/13] remove windows builds --- Makefile | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 17d9d9ad..2daf466e 100644 --- a/Makefile +++ b/Makefile @@ -23,10 +23,7 @@ FLAGS = -ldflags '-s -w -X github.com/kyma-project/modulectl/cmd/modulectl/versi validate-docs: ./hack/verify-generated-docs.sh -build: build-windows build-linux build-darwin build-windows-arm build-linux-arm build-darwin-arm - -build-windows: - CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./bin/modulectl.exe $(FLAGS) ./cmd +build: build-linux build-darwin build-linux-arm build-darwin-arm build-darwin: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./bin/modulectl-darwin $(FLAGS) ./cmd @@ -34,10 +31,6 @@ build-darwin: build-linux: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./bin/modulectl-linux $(FLAGS) ./cmd -# ARM based chipsets -build-windows-arm: - CGO_ENABLED=0 GOOS=windows GOARCH=arm64 go build -o ./bin/modulectl-arm.exe $(FLAGS) ./cmd - build-darwin-arm: CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o ./bin/modulectl-darwin-arm $(FLAGS) ./cmd From 4638a4635254bfea6d80e6d6c0d18480f5c75124 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 08:29:34 +0200 Subject: [PATCH 04/13] rename workflow files to yml --- .github/workflows/{build.yaml => build.yml} | 0 .github/workflows/{test-unit.yaml => test-unit.yml} | 0 .github/workflows/{validate-docs.yaml => validate-docs.yml} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{build.yaml => build.yml} (100%) rename .github/workflows/{test-unit.yaml => test-unit.yml} (100%) rename .github/workflows/{validate-docs.yaml => validate-docs.yml} (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yml similarity index 100% rename from .github/workflows/build.yaml rename to .github/workflows/build.yml diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yml similarity index 100% rename from .github/workflows/test-unit.yaml rename to .github/workflows/test-unit.yml diff --git a/.github/workflows/validate-docs.yaml b/.github/workflows/validate-docs.yml similarity index 100% rename from .github/workflows/validate-docs.yaml rename to .github/workflows/validate-docs.yml From 7c43ddf06438ad3b44263ed1aa3de105d6b5bbe4 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 09:13:12 +0200 Subject: [PATCH 05/13] add workflows --- .github/scripts/create_changelog.sh | 36 +++++++++++ .github/scripts/draft_release.sh | 34 +++++++++++ .github/scripts/get_release_by_tag.sh | 25 ++++++++ .github/scripts/validate_release_tag.sh | 15 +++++ .github/workflows/create-release.yml | 80 +++++++++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 .github/scripts/create_changelog.sh create mode 100644 .github/scripts/draft_release.sh create mode 100644 .github/scripts/get_release_by_tag.sh create mode 100644 .github/scripts/validate_release_tag.sh create mode 100644 .github/workflows/create-release.yml diff --git a/.github/scripts/create_changelog.sh b/.github/scripts/create_changelog.sh new file mode 100644 index 00000000..19b9c067 --- /dev/null +++ b/.github/scripts/create_changelog.sh @@ -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 diff --git a/.github/scripts/draft_release.sh b/.github/scripts/draft_release.sh new file mode 100644 index 00000000..81b638b7 --- /dev/null +++ b/.github/scripts/draft_release.sh @@ -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" diff --git a/.github/scripts/get_release_by_tag.sh b/.github/scripts/get_release_by_tag.sh new file mode 100644 index 00000000..00f680dc --- /dev/null +++ b/.github/scripts/get_release_by_tag.sh @@ -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 diff --git a/.github/scripts/validate_release_tag.sh b/.github/scripts/validate_release_tag.sh new file mode 100644 index 00000000..5c0c7a73 --- /dev/null +++ b/.github/scripts/validate_release_tag.sh @@ -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 diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml new file mode 100644 index 00000000..cca61d2d --- /dev/null +++ b/.github/workflows/create-release.yml @@ -0,0 +1,80 @@ +name: "Create release" + +#env: +# IMAGE_REPO: europe-docker.pkg.dev/kyma-project/prod/lifecycle-manager +# CODE_REPOSITORY: kyma-project/lifecycle-manager +on: + workflow_dispatch: + inputs: + version: + description: "Release version" + default: "" + required: true + since: + description: "Changelog since" + default: "" + required: false + +jobs: + validate-release: + name: 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: + name: 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 }} + build: + needs: draft-release + uses: ./.github/workflows/build.yml + with: + tag: "${{ github.event.inputs.version }}" + publish-release: + name: Publish release + needs: [ validate-release, draft-release, build ] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 +# - name: Wait for the Docker image +# timeout-minutes: 20 +# env: +# ITERATIONS: 40 +# SLEEP_SECONDS: 30 +# run: ./.github/scripts/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.version }} $ITERATIONS $SLEEP_SECONDS + - name: Publish release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} \ No newline at end of file From ef3760f26f2fa4f3e003561df88576fbbf7b574e Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 10:11:02 +0200 Subject: [PATCH 06/13] add version cmd --- cmd/main.go | 2 +- cmd/modulectl/cmd.go | 7 ++++ cmd/modulectl/version/cmd.go | 29 ++++++++++++++++ cmd/modulectl/version/cmd_test.go | 57 +++++++++++++++++++++++++++++++ tests/e2e/create/create_test.go | 5 +-- 5 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 cmd/modulectl/version/cmd.go create mode 100644 cmd/modulectl/version/cmd_test.go diff --git a/cmd/main.go b/cmd/main.go index d71b10b7..566f3c07 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -14,7 +14,7 @@ func main() { os.Exit(-1) } - if err := cmd.Execute(); err != nil { + if err = cmd.Execute(); err != nil { fmt.Println(fmt.Errorf("failed to execute modulectl command: %w", err)) os.Exit(-1) } diff --git a/cmd/modulectl/cmd.go b/cmd/modulectl/cmd.go index 02905127..75cce5cd 100644 --- a/cmd/modulectl/cmd.go +++ b/cmd/modulectl/cmd.go @@ -9,6 +9,7 @@ import ( createcmd "github.com/kyma-project/modulectl/cmd/modulectl/create" scaffoldcmd "github.com/kyma-project/modulectl/cmd/modulectl/scaffold" + "github.com/kyma-project/modulectl/cmd/modulectl/version" "github.com/kyma-project/modulectl/internal/service/componentarchive" "github.com/kyma-project/modulectl/internal/service/componentdescriptor" "github.com/kyma-project/modulectl/internal/service/contentprovider" @@ -72,8 +73,14 @@ func NewCmd() (*cobra.Command, error) { return nil, fmt.Errorf("failed to build create command: %w", err) } + versionCmd, err := version.NewCmd() + if err != nil { + return nil, fmt.Errorf("failed to build version command: %w", err) + } + rootCmd.AddCommand(scaffoldCmd) rootCmd.AddCommand(createCmd) + rootCmd.AddCommand(versionCmd) return rootCmd, nil } diff --git a/cmd/modulectl/version/cmd.go b/cmd/modulectl/version/cmd.go new file mode 100644 index 00000000..bdfa2be2 --- /dev/null +++ b/cmd/modulectl/version/cmd.go @@ -0,0 +1,29 @@ +package version + +import ( + "github.com/spf13/cobra" +) + +const ( + use = "version" + short = "Print current modulectl version" + long = "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 +} diff --git a/cmd/modulectl/version/cmd_test.go b/cmd/modulectl/version/cmd_test.go new file mode 100644 index 00000000..8db7cec7 --- /dev/null +++ b/cmd/modulectl/version/cmd_test.go @@ -0,0 +1,57 @@ +package version_test + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/kyma-project/modulectl/cmd/modulectl/version" +) + +func TestNewCmd_WhenCalled_ReturnsNoErr(t *testing.T) { + _, err := version.NewCmd() + + require.NoError(t, err) +} + +func TestNewCmd_WhenCalled_CmdContainsUseDescription(t *testing.T) { + cmd, _ := version.NewCmd() + + assert.Equal(t, "version", cmd.Use) +} + +func TestNewCmd_WhenCalled_CmdContainsShortDescription(t *testing.T) { + cmd, _ := version.NewCmd() + + assert.Equal(t, "Print current modulectl version", cmd.Short) +} + +func TestNewCmd_WhenCalled_CmdContainsLongDescription(t *testing.T) { + cmd, _ := version.NewCmd() + + assert.Equal(t, "Prints the current semantic version of the modulectl binary set at build time", cmd.Long) +} + +func TestNewCmd_WhenCalled_CmdRunNotNil(t *testing.T) { + cmd, _ := version.NewCmd() + + require.NotNil(t, cmd.Run) +} + +func TestNewCmd_WhenCalled_CmdHasAlias(t *testing.T) { + cmd, _ := version.NewCmd() + + require.Len(t, cmd.Aliases, 1) + require.Contains(t, cmd.Aliases, "v") +} + +func TestNewCmd_WhenCalled_CmdExecuteCanBeCalledWithNoVersionGlobalSet(t *testing.T) { + cmd, _ := version.NewCmd() + os.Args = []string{"version"} + + err := cmd.Execute() + + require.NoError(t, err) +} diff --git a/tests/e2e/create/create_test.go b/tests/e2e/create/create_test.go index 9423c189..ee6016e3 100644 --- a/tests/e2e/create/create_test.go +++ b/tests/e2e/create/create_test.go @@ -3,11 +3,12 @@ package create_test import ( - "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/github" - "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" "io/fs" "os" + "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/github" + "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/ociartifact" + "github.com/open-component-model/ocm/pkg/contexts/oci/repositories/ocireg" "github.com/open-component-model/ocm/pkg/contexts/ocm" "github.com/open-component-model/ocm/pkg/contexts/ocm/accessmethods/localblob" From 6f60c127a1b8588a2ca273b6bf0df3fd766f4028 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 10:34:39 +0200 Subject: [PATCH 07/13] add release workflow --- .github/scripts/publish_release.sh | 20 ++++++++++ .github/scripts/upload_assets.sh | 58 ++++++++++++++++++++++++++++ .github/workflows/build.yml | 15 ++++++- .github/workflows/create-release.yml | 26 +++++-------- 4 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 .github/scripts/publish_release.sh create mode 100644 .github/scripts/upload_assets.sh diff --git a/.github/scripts/publish_release.sh b/.github/scripts/publish_release.sh new file mode 100644 index 00000000..d4c0d38b --- /dev/null +++ b/.github/scripts/publish_release.sh @@ -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" diff --git a/.github/scripts/upload_assets.sh b/.github/scripts/upload_assets.sh new file mode 100644 index 00000000..a26f6a7c --- /dev/null +++ b/.github/scripts/upload_assets.sh @@ -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" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f07ff0f2..65319b04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,13 @@ on: pull_request: branches: - main - - 'release-**' + workflow_call: + inputs: + version: + description: 'Version used for release builds' + required: false + type: string + default: "" workflow_dispatch: jobs: build-modulectl: @@ -17,4 +23,9 @@ jobs: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' - name: "Run 'make build'" - run: make build + run: | + if [[ "${{ inputs.version }}" != "" ]]; then + make build VERSION=${{ inputs.version }} + else + make build + fi diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index cca61d2d..40f9f44f 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -59,22 +59,16 @@ jobs: uses: ./.github/workflows/build.yml with: tag: "${{ github.event.inputs.version }}" + upload-assets: + needs: build + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PULL_BASE_REF: ${{ github.event.inputs.version }} + run: ./.github/scripts/upload_assets.sh publish-release: - name: Publish release needs: [ validate-release, draft-release, build ] runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 -# - name: Wait for the Docker image -# timeout-minutes: 20 -# env: -# ITERATIONS: 40 -# SLEEP_SECONDS: 30 -# run: ./.github/scripts/wait_for_image.sh ${{ env.IMAGE_REPO }}:${{ github.event.inputs.version }} $ITERATIONS $SLEEP_SECONDS - - name: Publish release - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} \ No newline at end of file + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} From 29a47a7701d299e82da5dd8dc3da96abcf496d34 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 10:55:15 +0200 Subject: [PATCH 08/13] fix --- .github/workflows/create-release.yml | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index 40f9f44f..d90610f2 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -1,8 +1,5 @@ name: "Create release" -#env: -# IMAGE_REPO: europe-docker.pkg.dev/kyma-project/prod/lifecycle-manager -# CODE_REPOSITORY: kyma-project/lifecycle-manager on: workflow_dispatch: inputs: @@ -17,7 +14,6 @@ on: jobs: validate-release: - name: Validate release runs-on: ubuntu-latest steps: - name: Checkout code @@ -29,7 +25,6 @@ jobs: - name: Check if release exists run: ./.github/scripts/get_release_by_tag.sh ${{ github.event.inputs.version }} ${{ secrets.GITHUB_TOKEN }} draft-release: - name: Draft release runs-on: ubuntu-latest needs: validate-release steps: @@ -54,21 +49,27 @@ jobs: git push origin ${{ github.event.inputs.version }} --tags outputs: release_id: ${{ steps.draft-release.outputs.release_id }} - build: - needs: draft-release - uses: ./.github/workflows/build.yml - with: - tag: "${{ github.event.inputs.version }}" - upload-assets: - needs: build + artifacts: runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - PULL_BASE_REF: ${{ github.event.inputs.version }} - run: ./.github/scripts/upload_assets.sh + 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: - needs: [ validate-release, draft-release, build ] + needs: [ validate-release, draft-release, artifacts ] runs-on: ubuntu-latest env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} + uses: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} From 424ba809a557c1e88ba7c2e0157d2af7af9558da Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Thu, 10 Oct 2024 10:56:12 +0200 Subject: [PATCH 09/13] fix --- .github/workflows/build.yml | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 65319b04..fbaed0b9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,13 +3,13 @@ on: pull_request: branches: - main - workflow_call: - inputs: - version: - description: 'Version used for release builds' - required: false - type: string - default: "" +# workflow_call: +# inputs: +# version: +# description: 'Version used for release builds' +# required: false +# type: string +# default: "" workflow_dispatch: jobs: build-modulectl: @@ -23,9 +23,10 @@ jobs: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' - name: "Run 'make build'" - run: | - if [[ "${{ inputs.version }}" != "" ]]; then - make build VERSION=${{ inputs.version }} - else - make build - fi + run: make build +# run: | +# if [[ "${{ inputs.version }}" != "" ]]; then +# make build VERSION=${{ inputs.version }} +# else +# make build +# fi From dee87d2f1cb879cf452f08043ae51423618bcb41 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Fri, 11 Oct 2024 14:04:20 +0200 Subject: [PATCH 10/13] fix --- .github/workflows/create-release.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/create-release.yml b/.github/workflows/create-release.yml index d90610f2..1a9633fa 100644 --- a/.github/workflows/create-release.yml +++ b/.github/workflows/create-release.yml @@ -68,8 +68,14 @@ jobs: PULL_BASE_REF: ${{ github.event.inputs.version }} run: ./.github/scripts/upload_assets.sh publish-release: - needs: [ validate-release, draft-release, artifacts ] runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: ./.github/scripts/publish_release.sh ${{ needs.draft-release.outputs.release_id }} + 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 }} From a945f43ba6f062ee7fab3f1b529868b330ba7172 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Mon, 14 Oct 2024 14:01:55 +0200 Subject: [PATCH 11/13] gend ocs --- docs/gen-docs/modulectl.md | 1 + docs/gen-docs/modulectl_version.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 docs/gen-docs/modulectl_version.md diff --git a/docs/gen-docs/modulectl.md b/docs/gen-docs/modulectl.md index e81348ba..7eb29fe9 100644 --- a/docs/gen-docs/modulectl.md +++ b/docs/gen-docs/modulectl.md @@ -21,4 +21,5 @@ A CLI from the Kyma Module Controller. Wonderful to use. * [modulectl create](modulectl_create.md) - Creates a module bundled as an OCI artifact. * [modulectl scaffold](modulectl_scaffold.md) - Generates necessary files required for module creation. +* [modulectl version](modulectl_version.md) - Print current modulectl version diff --git a/docs/gen-docs/modulectl_version.md b/docs/gen-docs/modulectl_version.md new file mode 100644 index 00000000..bafaaac3 --- /dev/null +++ b/docs/gen-docs/modulectl_version.md @@ -0,0 +1,25 @@ +--- +title: modulectl version +--- + +Print current modulectl version + +## Synopsis + +Prints the current semantic version of the modulectl binary set at build time + +```bash +modulectl version [flags] +``` + +## Flags + +```bash +-h, --help Provides help for the version command. +``` + +## See also + +* [modulectl](modulectl.md) - This is the Kyma Module Controller CLI. + + From ec10a2f539094063694a33b4edfefc2f79c85e45 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Tue, 15 Oct 2024 09:22:35 +0200 Subject: [PATCH 12/13] change docs --- cmd/modulectl/version/cmd.go | 4 ++-- cmd/modulectl/version/cmd_test.go | 4 ++-- docs/gen-docs/modulectl.md | 2 +- docs/gen-docs/modulectl_version.md | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/modulectl/version/cmd.go b/cmd/modulectl/version/cmd.go index bdfa2be2..71927576 100644 --- a/cmd/modulectl/version/cmd.go +++ b/cmd/modulectl/version/cmd.go @@ -6,8 +6,8 @@ import ( const ( use = "version" - short = "Print current modulectl version" - long = "Prints the current semantic version of the modulectl binary set at build time" + 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 diff --git a/cmd/modulectl/version/cmd_test.go b/cmd/modulectl/version/cmd_test.go index 8db7cec7..64d2ea5a 100644 --- a/cmd/modulectl/version/cmd_test.go +++ b/cmd/modulectl/version/cmd_test.go @@ -25,13 +25,13 @@ func TestNewCmd_WhenCalled_CmdContainsUseDescription(t *testing.T) { func TestNewCmd_WhenCalled_CmdContainsShortDescription(t *testing.T) { cmd, _ := version.NewCmd() - assert.Equal(t, "Print current modulectl version", cmd.Short) + assert.Equal(t, "Prints the current modulectl version.", cmd.Short) } func TestNewCmd_WhenCalled_CmdContainsLongDescription(t *testing.T) { cmd, _ := version.NewCmd() - assert.Equal(t, "Prints the current semantic version of the modulectl binary set at build time", cmd.Long) + assert.Equal(t, "This command prints the current semantic version of the modulectl binary set at build time.", cmd.Long) } func TestNewCmd_WhenCalled_CmdRunNotNil(t *testing.T) { diff --git a/docs/gen-docs/modulectl.md b/docs/gen-docs/modulectl.md index 7eb29fe9..6edc1e32 100644 --- a/docs/gen-docs/modulectl.md +++ b/docs/gen-docs/modulectl.md @@ -21,5 +21,5 @@ A CLI from the Kyma Module Controller. Wonderful to use. * [modulectl create](modulectl_create.md) - Creates a module bundled as an OCI artifact. * [modulectl scaffold](modulectl_scaffold.md) - Generates necessary files required for module creation. -* [modulectl version](modulectl_version.md) - Print current modulectl version +* [modulectl version](modulectl_version.md) - Prints the current modulectl version. diff --git a/docs/gen-docs/modulectl_version.md b/docs/gen-docs/modulectl_version.md index bafaaac3..50cd02a0 100644 --- a/docs/gen-docs/modulectl_version.md +++ b/docs/gen-docs/modulectl_version.md @@ -2,11 +2,11 @@ title: modulectl version --- -Print current modulectl version +Prints the current modulectl version. ## Synopsis -Prints the current semantic version of the modulectl binary set at build time +This command prints the current semantic version of the modulectl binary set at build time. ```bash modulectl version [flags] From c891a29d52020b5445e3c9bc799c3829448fe2a4 Mon Sep 17 00:00:00 2001 From: Benjamin Lindner Date: Tue, 15 Oct 2024 14:15:25 +0200 Subject: [PATCH 13/13] adapt to latest template-operator release --- .github/workflows/build.yml | 13 ------------- tests/e2e/create/create_test.go | 6 +++--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbaed0b9..8012ff3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,13 +3,6 @@ on: pull_request: branches: - main -# workflow_call: -# inputs: -# version: -# description: 'Version used for release builds' -# required: false -# type: string -# default: "" workflow_dispatch: jobs: build-modulectl: @@ -24,9 +17,3 @@ jobs: cache-dependency-path: 'go.sum' - name: "Run 'make build'" run: make build -# run: | -# if [[ "${{ inputs.version }}" != "" ]]; then -# make build VERSION=${{ inputs.version }} -# else -# make build -# fi diff --git a/tests/e2e/create/create_test.go b/tests/e2e/create/create_test.go index 459f2617..d1d3c580 100644 --- a/tests/e2e/create/create_test.go +++ b/tests/e2e/create/create_test.go @@ -309,7 +309,7 @@ var _ = Describe("Test 'create' command", Ordered, func() { Expect(resource.Name).To(Equal("template-operator")) Expect(resource.Relation).To(Equal(ocmv1.ExternalRelation)) Expect(resource.Type).To(Equal("ociArtifact")) - Expect(resource.Version).To(Equal("1.0.0")) + Expect(resource.Version).To(Equal("1.0.1")) resource = descriptor.Resources[1] Expect(resource.Name).To(Equal("raw-manifest")) Expect(resource.Version).To(Equal("1.0.3")) @@ -320,7 +320,7 @@ var _ = Describe("Test 'create' command", Ordered, func() { ociArtifactAccessSpec, ok := resourceAccessSpec0.(*ociartifact.AccessSpec) Expect(ok).To(BeTrue()) Expect(ociArtifactAccessSpec.GetType()).To(Equal(ociartifact.Type)) - Expect(ociArtifactAccessSpec.ImageReference).To(Equal("europe-docker.pkg.dev/kyma-project/prod/template-operator:1.0.0")) + Expect(ociArtifactAccessSpec.ImageReference).To(Equal("europe-docker.pkg.dev/kyma-project/prod/template-operator:1.0.1")) By("And descriptor.component.resources[1].access should be correct") resourceAccessSpec1, err := ocm.DefaultContext().AccessSpecForSpec(descriptor.Resources[1].Access) @@ -347,7 +347,7 @@ var _ = Describe("Test 'create' command", Ordered, func() { By("And security scan labels should be correct") secScanLabels := flatten(descriptor.Sources[0].Labels) Expect(secScanLabels).To(HaveKeyWithValue("git.kyma-project.io/ref", "HEAD")) - Expect(secScanLabels).To(HaveKeyWithValue("scan.security.kyma-project.io/rc-tag", "1.0.0")) + Expect(secScanLabels).To(HaveKeyWithValue("scan.security.kyma-project.io/rc-tag", "1.0.1")) Expect(secScanLabels).To(HaveKeyWithValue("scan.security.kyma-project.io/language", "golang-mod")) Expect(secScanLabels).To(HaveKeyWithValue("scan.security.kyma-project.io/dev-branch", "main")) Expect(secScanLabels).To(HaveKeyWithValue("scan.security.kyma-project.io/subprojects", "false"))