diff --git a/.github/workflows/ghcr.yaml b/.github/workflows/ghcr.yaml deleted file mode 100644 index 4e3d72d..0000000 --- a/.github/workflows/ghcr.yaml +++ /dev/null @@ -1,38 +0,0 @@ -name: Build and publish a Docker image to ghcr.io -on: - push: - tags: [ "v*.*.*" ] - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }} - -jobs: - build-and-push: - runs-on: "ubuntu-latest" - - permissions: - contents: read - packages: write - - steps: - - uses: actions/checkout@v3 - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - - name: Build and push Docker image - uses: docker/build-push-action@v3 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..ce90691 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,11 @@ +name-template: '$NEXT_MINOR_VERSION' +tag-template: '$NEXT_MINOR_VERSION' +version-template: '$COMPLETE' +change-template: '- $TITLE (#$NUMBER)' +change-title-escapes: '\<*_&#@`' +template: | + # Release $NEXT_MINOR_VERSION + + $CHANGES +exclude-labels: + - 'kind/skip-release-notes' \ No newline at end of file diff --git a/.github/workflows/workflows/check-manifest-generation-diff.yaml b/.github/workflows/workflows/check-manifest-generation-diff.yaml new file mode 100644 index 0000000..5077413 --- /dev/null +++ b/.github/workflows/workflows/check-manifest-generation-diff.yaml @@ -0,0 +1,34 @@ +name: Check for diff after manifest and generated targets + +on: + pull_request: {} + +jobs: + check: + name: Check for diff + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Make manifests && generate + run: | + make manifests && make generate + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version-file: '${{ github.workspace }}/go.mod' + - name: Restore Go cache + uses: actions/cache@v3 + with: + path: /home/runner/work/_temp/_github_home/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: go mod tidy + run: | + go mod tidy + - name: Check for diff + run: | + git diff --exit-code --shortstat diff --git a/.github/workflows/workflows/e2e.yaml b/.github/workflows/workflows/e2e.yaml new file mode 100644 index 0000000..2f42d63 --- /dev/null +++ b/.github/workflows/workflows/e2e.yaml @@ -0,0 +1,44 @@ +name: e2e + +on: + pull_request: + paths-ignore: + - 'CODE_OF_CONDUCT.md' + - 'README.md' + - 'Contributing.md' + + push: + branches: + - main + +permissions: + contents: read # for actions/checkout to fetch code + +jobs: + kind-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version-file: '${{ github.workspace }}/go.mod' + - name: Restore Go cache + uses: actions/cache@v3 + with: + path: /home/runner/work/_temp/_github_home/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Setup Kubernetes + uses: helm/kind-action@v1.5.0 + with: + version: v0.17.0 + cluster_name: ocm-e2e + - name: Setup Kustomize + uses: fluxcd/pkg/actions/kustomize@main + - name: Run E2E tests + run: make e2e + env: + KIND_CLUSTER_NAME: ocm-e2e diff --git a/.github/workflows/workflows/release-drafter.yaml b/.github/workflows/workflows/release-drafter.yaml new file mode 100644 index 0000000..0f70ea4 --- /dev/null +++ b/.github/workflows/workflows/release-drafter.yaml @@ -0,0 +1,20 @@ +name: Release Drafter + +on: + push: + branches: + - main + +permissions: + contents: read + # The release-drafter action adds PR titles to the release notes once these are merged to main. + # A draft release is kept up-to-date listing the changes for the next minor release version. +jobs: + update_release_draft: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/workflows/release.yaml b/.github/workflows/workflows/release.yaml new file mode 100644 index 0000000..10ccdf0 --- /dev/null +++ b/.github/workflows/workflows/release.yaml @@ -0,0 +1,105 @@ +name: Release + +on: + workflow_dispatch: + inputs: + release_candidate: + type: boolean + description: "Release Candidate" + required: false + default: false + +env: + REGISTRY: ghcr.io + DOCKERFILE: ${{ github.workspace }}/goreleaser.dockerfile + +jobs: + tests: + uses: ./.github/workflows/tests.yaml + permissions: + contents: read + pull-requests: 'read' + release: + needs: tests + name: Trigger release build + runs-on: ubuntu-latest + permissions: + contents: 'write' + id-token: 'write' + pull-requests: 'read' + repository-projects: 'write' + packages: 'write' + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version-file: '${{ github.workspace }}/go.mod' + - name: Cache go-build and mod + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build/ + ~/go/pkg/mod/ + key: go-${{ hashFiles('go.sum') }} + restore-keys: | + go- + - name: Set release version + run: | + if ${{ inputs.release_candidate }}; then + echo "RELEASE_VERSION=$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-rc-version)" >> $GITHUB_ENV + else + echo "RELEASE_VERSION=$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-version)" >> $GITHUB_ENV + fi + - name: Set release notes file + run: | + echo "RELEASE_NOTES_FILE=docs/release_notes/$(go run $GITHUB_WORKSPACE/pkg/version/generate/release_generate.go print-version).md" >> $GITHUB_ENV + - name: Validate release notes + run: | + if [[ ! -f ${{ env.RELEASE_NOTES_FILE }} ]]; then + >&2 echo "Must have release notes ${{ env.RELEASE_NOTES_FILE }}" + exit 6 + fi + - name: Create and push branch + env: + RELEASE_BRANCH: release-${{ env.RELEASE_VERSION }} + run: | + if ! git checkout ${RELEASE_BRANCH} >/dev/null; then + echo "Creating ${RELEASE_BRANCH} from $(git branch --show-current)" + git checkout -b ${RELEASE_BRANCH} + git push origin "$(git branch --show-current)" + else + git checkout ${RELEASE_BRANCH} + git pull --ff-only origin ${RELEASE_BRANCH} + fi + - name: Setup git config + run: | + git config user.name "GitHub Actions Bot" + git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>" + - name: Create and push tag + run: | + msg="Release ${{ env.RELEASE_VERSION }}" + git tag --annotate --message "${msg}" ${{ env.RELEASE_VERSION }} + git push origin ${{ env.RELEASE_VERSION }} + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Generate manifests + run: | + mkdir -p output + kustomize build ./config/default > ./output/install.yaml + - name: Run goreleaser + uses: goreleaser/goreleaser-action@v4 + with: + distribution: goreleaser + version: latest + args: release --clean --timeout 60m --skip-validate --config=./.goreleaser.yaml --release-notes=${{ env.RELEASE_NOTES_FILE }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GORELEASER_CURRENT_TAG: ${{ env.RELEASE_VERSION }} diff --git a/.github/workflows/workflows/tests.yaml b/.github/workflows/workflows/tests.yaml new file mode 100644 index 0000000..f5c030b --- /dev/null +++ b/.github/workflows/workflows/tests.yaml @@ -0,0 +1,36 @@ +name: tests + +on: + pull_request: + paths-ignore: + - 'CODE_OF_CONDUCT.md' + - 'README.md' + - 'Contributing.md' + workflow_call: + + push: + branches: + - main + +permissions: + contents: read # for actions/checkout to fetch code + +jobs: + test-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version-file: '${{ github.workspace }}/go.mod' + - name: Restore Go cache + uses: actions/cache@v3 + with: + path: /home/runner/work/_temp/_github_home/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Run tests + run: make test diff --git a/controllers/gitsync_controller_test.go b/controllers/gitsync_controller_test.go new file mode 100644 index 0000000..b013ebc --- /dev/null +++ b/controllers/gitsync_controller_test.go @@ -0,0 +1,97 @@ +package controllers + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" + + ocmv1 "github.com/open-component-model/ocm-controller/api/v1alpha1" + + "github.com/open-component-model/git-sync-controller/api/v1alpha1" + "github.com/open-component-model/git-sync-controller/pkg" +) + +func TestGitSyncReconciler(t *testing.T) { + cv := DefaultComponent.DeepCopy() + snapshot := DefaultSnapshot.DeepCopy() + secret := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "auth-secret", + Namespace: "default", + }, + Data: map[string][]byte{ + "username": []byte("username"), + "password": []byte("password"), + }, + } + gitSync := &v1alpha1.GitSync{ + ObjectMeta: metav1.ObjectMeta{ + Name: "git-sync-test", + Namespace: "default", + }, + Spec: v1alpha1.GitSyncSpec{ + ComponentRef: v1alpha1.Ref{ + Name: cv.Name, + Namespace: cv.Namespace, + }, + SnapshotRef: v1alpha1.Ref{ + Name: snapshot.Name, + Namespace: snapshot.Namespace, + }, + AuthRef: v1alpha1.Ref{ + Name: secret.Name, + Namespace: secret.Namespace, + }, + URL: "https://github.com/Skarlso/test", + Branch: "main", + CommitTemplate: &v1alpha1.CommitTemplate{ + Name: "Skarlso", + Email: "email@mail.com", + Message: "This is my message", + }, + SubPath: "./subpath", + Prune: true, + }, + } + + client := env.FakeKubeClient(WithObjets(gitSync, snapshot, cv, secret), WithAddToScheme(ocmv1.AddToScheme)) + m := &mockGit{ + digest: "test-digest", + } + gsr := GitSyncReconciler{ + Client: client, + Scheme: env.scheme, + Git: m, + } + + _, err := gsr.Reconcile(context.Background(), ctrl.Request{ + NamespacedName: types.NamespacedName{ + Namespace: gitSync.Namespace, + Name: gitSync.Name, + }, + }) + require.NoError(t, err) + + err = client.Get(context.Background(), types.NamespacedName{ + Name: gitSync.Name, + Namespace: gitSync.Namespace, + }, gitSync) + require.NoError(t, err) + + assert.Equal(t, "test-digest", gitSync.Status.Digest) +} + +type mockGit struct { + digest string + err error +} + +func (g *mockGit) Push(ctx context.Context, opts *pkg.PushOptions) (string, error) { + return g.digest, g.err +} diff --git a/controllers/suite_test.go b/controllers/suite_test.go index dc21978..c109fdd 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -6,64 +6,102 @@ package controllers import ( - "path/filepath" "testing" + "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "k8s.io/client-go/kubernetes/scheme" - "k8s.io/client-go/rest" + ocmv1alpha1 "github.com/open-component-model/ocm-controller/api/v1alpha1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest" - logf "sigs.k8s.io/controller-runtime/pkg/log" - "sigs.k8s.io/controller-runtime/pkg/log/zap" + "sigs.k8s.io/controller-runtime/pkg/client/fake" - deliveryv1alpha1 "github.com/open-component-model/git-sync-controller/api/v1alpha1" - //+kubebuilder:scaffold:imports + "github.com/open-component-model/git-sync-controller/api/v1alpha1" ) -// These tests use Ginkgo (BDD-style Go testing framework). Refer to -// http://onsi.github.io/ginkgo/ to learn more about Ginkgo. - -var cfg *rest.Config -var k8sClient client.Client -var testEnv *envtest.Environment - -func TestAPIs(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecs(t, "Controller Suite") +type testEnv struct { + scheme *runtime.Scheme + obj []client.Object } -var _ = BeforeSuite(func() { - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - By("bootstrapping test environment") - testEnv = &envtest.Environment{ - CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, - ErrorIfCRDPathMissing: true, +// FakeKubeClientOption defines options to construct a fake kube client. There are some defaults involved. +// Scheme gets corev1 and v1alpha1 schemes by default. Anything that is passed in will override current +// defaults. +type FakeKubeClientOption func(testEnv *testEnv) + +// WithAddToScheme adds the scheme +func WithAddToScheme(addToScheme func(s *runtime.Scheme) error) FakeKubeClientOption { + return func(testEnv *testEnv) { + if err := addToScheme(testEnv.scheme); err != nil { + panic(err) + } } +} - var err error - // cfg is defined in this file globally. - cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) +// WithObjects provides an option to set objects for the fake client. +func WithObjets(obj ...client.Object) FakeKubeClientOption { + return func(testEnv *testEnv) { + testEnv.obj = obj + } +} - err = deliveryv1alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) +// FakeKubeClient creates a fake kube client with some defaults and optional arguments. +func (t *testEnv) FakeKubeClient(opts ...FakeKubeClientOption) client.Client { + for _, o := range opts { + o(t) + } + return fake.NewClientBuilder().WithScheme(t.scheme).WithObjects(t.obj...).Build() +} - //+kubebuilder:scaffold:scheme +var ( + DefaultComponent = &ocmv1alpha1.ComponentVersion{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-component", + Namespace: "default", + }, + Spec: ocmv1alpha1.ComponentVersionSpec{ + Interval: metav1.Duration{Duration: 10 * time.Minute}, + Component: "github.com/open-component-model/test-component", + Version: ocmv1alpha1.Version{ + Semver: "v0.0.1", + }, + Repository: ocmv1alpha1.Repository{ + URL: "github.com/open-component-model/test", + }, + Verify: []ocmv1alpha1.Signature{}, + References: ocmv1alpha1.ReferencesConfig{ + Expand: true, + }, + }, + } + DefaultSnapshot = &ocmv1alpha1.Snapshot{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-snapshot", + Namespace: "default", + }, + Spec: ocmv1alpha1.SnapshotSpec{ + Identity: ocmv1alpha1.Identity{ + ocmv1alpha1.ComponentNameKey: DefaultComponent.Name, + ocmv1alpha1.ComponentVersionKey: "v0.0.1", + ocmv1alpha1.ResourceNameKey: "test-resource", + ocmv1alpha1.ResourceVersionKey: "v0.0.1", + }, + Digest: "test-digest", + Tag: "v0.0.1", + }, + Status: ocmv1alpha1.SnapshotStatus{}, + } +) - k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) +var env *testEnv -}) +func TestMain(m *testing.M) { + scheme := runtime.NewScheme() + _ = v1alpha1.AddToScheme(scheme) + _ = corev1.AddToScheme(scheme) -var _ = AfterSuite(func() { - By("tearing down the test environment") - err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) -}) + env = &testEnv{ + scheme: scheme, + } + m.Run() +} diff --git a/docs/release_notes/v0.0.1.md b/docs/release_notes/v0.0.1.md new file mode 100644 index 0000000..8fa6967 --- /dev/null +++ b/docs/release_notes/v0.0.1.md @@ -0,0 +1 @@ +# Initial Release diff --git a/go.mod b/go.mod index a54430d..f30c02c 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/open-component-model/git-sync-controller go 1.20 require ( + github.com/Masterminds/semver/v3 v3.2.0 github.com/fluxcd/pkg/runtime v0.27.0 github.com/fluxcd/pkg/tar v0.2.0 github.com/go-git/go-git/v5 v5.6.0 github.com/go-logr/logr v1.2.3 - github.com/onsi/ginkgo/v2 v2.8.4 - github.com/onsi/gomega v1.27.2 github.com/open-component-model/ocm-controller v0.4.0 + github.com/stretchr/testify v1.8.1 k8s.io/api v0.26.2 k8s.io/apimachinery v0.26.2 k8s.io/client-go v0.26.2 @@ -19,7 +19,6 @@ require ( require ( github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect github.com/Masterminds/semver v1.5.0 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Microsoft/go-winio v0.6.0 // indirect github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect github.com/acomagu/bufpipe v1.0.4 // indirect @@ -64,6 +63,7 @@ require ( github.com/docker/go-units v0.5.0 // indirect github.com/emicklei/go-restful/v3 v3.10.1 // indirect github.com/emirpasic/gods v1.18.1 // indirect + github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.6.0 // indirect github.com/fluxcd/pkg/apis/meta v0.19.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect @@ -75,7 +75,6 @@ require ( github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect - github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect @@ -85,7 +84,6 @@ require ( github.com/google/go-github/v45 v45.2.0 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/imdario/mergo v0.3.13 // indirect @@ -115,6 +113,7 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/morikuni/aec v1.0.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect + github.com/onsi/gomega v1.27.2 // indirect github.com/open-component-model/ocm v0.2.0-rc.1 // indirect github.com/open-component-model/ocm-controllers-sdk v0.0.6 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect @@ -122,6 +121,7 @@ require ( github.com/pelletier/go-toml v1.9.5 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect github.com/prometheus/common v0.40.0 // indirect diff --git a/go.sum b/go.sum index 2fdefd3..a8333d9 100644 --- a/go.sum +++ b/go.sum @@ -464,6 +464,7 @@ github.com/evanphx/json-patch v0.5.2/go.mod h1:ZWS5hhDbVDyob71nXKNL0+PWn6ToqBHMi github.com/evanphx/json-patch v4.9.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= +github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww= github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= @@ -652,7 +653,6 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 h1:K6RDEckDVWvDI9JAJYCmNdQXq6neHJOYx3V6jnqNEec= -github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -909,7 +909,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.8.4 h1:gf5mIQ8cLFieruNLAdgijHF1PYfLphKm2dxxcUtcqK0= -github.com/onsi/ginkgo/v2 v2.8.4/go.mod h1:427dEDQZkDKsBvCjc2A/ZPefhKxsTTrsQegMlayL730= github.com/onsi/gomega v0.0.0-20151007035656-2152b45fa28a/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= diff --git a/pkg/providers/gogit/git.go b/pkg/providers/gogit/git.go index b61efc3..b693114 100644 --- a/pkg/providers/gogit/git.go +++ b/pkg/providers/gogit/git.go @@ -19,9 +19,9 @@ import ( "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/ssh" "github.com/go-logr/logr" - "github.com/open-component-model/ocm-controller/pkg/ocm" "github.com/open-component-model/ocm-controller/pkg/cache" + "github.com/open-component-model/ocm-controller/pkg/ocm" "github.com/open-component-model/git-sync-controller/pkg" ) diff --git a/pkg/version/generate/release_generate.go b/pkg/version/generate/release_generate.go new file mode 100644 index 0000000..6a0ce17 --- /dev/null +++ b/pkg/version/generate/release_generate.go @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "fmt" + "log" + "os" + + "github.com/Masterminds/semver/v3" + "github.com/open-component-model/ocm-controller/pkg/version" +) + +func main() { + if len(os.Args) <= 1 { + log.Fatal("missing argument") + } + + _ = semver.MustParse(version.ReleaseVersion) + + cmd := os.Args[1] + + switch cmd { + case "print-version": + fmt.Print(version.ReleaseVersion) + case "print-rc-version": + fmt.Printf("%s-%s", version.ReleaseVersion, version.ReleaseCandidate) + } +} diff --git a/pkg/version/release.go b/pkg/version/release.go new file mode 100644 index 0000000..450ae71 --- /dev/null +++ b/pkg/version/release.go @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors. +// +// SPDX-License-Identifier: Apache-2.0 + +package version + +// ReleaseVersion is the version number in semver format "vX.Y.Z", prefixed with "v". +var ReleaseVersion = "v0.0.1" + +// ReleaseCandidate is the release candidate ID in format "rc.X", which will be appended to the release version. +var ReleaseCandidate = "rc.1"