Skip to content

Commit

Permalink
feat(RHTAPREL-849): add e2e test for release_to_github (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinqi7 authored Mar 24, 2024
1 parent 75179af commit c0ef0b7
Show file tree
Hide file tree
Showing 5 changed files with 309 additions and 37 deletions.
30 changes: 30 additions & 0 deletions pkg/clients/github/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,41 @@ package github
import (
"context"
"fmt"
"strings"

"github.com/google/go-github/v44/github"
. "github.com/onsi/ginkgo/v2"
)

func (g *Github) CheckIfReleaseExist(owner, repositoryName, releaseURL string) bool {
urlParts := strings.Split(releaseURL, "/")
tagName := urlParts[len(urlParts)-1]
_, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), owner, repositoryName, tagName)
if err != nil {
GinkgoWriter.Printf("GetReleaseByTag %s returned error in repo %s : %v\n", tagName, repositoryName, err)
return false
}
GinkgoWriter.Printf("Release tag %s is found in repository %s \n", tagName, repositoryName)
return true
}

func (g *Github) DeleteRelease(owner, repositoryName, releaseURL string) bool {
urlParts := strings.Split(releaseURL, "/")
tagName := urlParts[len(urlParts)-1]
release, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), owner, repositoryName, tagName)
if err != nil {
GinkgoWriter.Printf("GetReleaseByTag returned error in repo %s : %v\n", repositoryName, err)
return false
}

_, err = g.client.Repositories.DeleteRelease(context.Background(), owner, repositoryName, *release.ID)
if err != nil {
GinkgoWriter.Printf("DeleteRelease returned error: %v", err)
}
GinkgoWriter.Printf("Release tag %s is deleted in repository %s \n", tagName, repositoryName)
return true
}

func (g *Github) CheckIfRepositoryExist(repository string) bool {
_, resp, err := g.client.Repositories.Get(context.Background(), g.organization, repository)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions tests/release/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
ReleaseCreationTimeout = 5 * time.Minute
ReleasePipelineRunCreationTimeout = 10 * time.Minute
ReleasePipelineRunCompletionTimeout = 60 * time.Minute
BuildPipelineRunCompletionTimeout = 60 * time.Minute
BuildPipelineRunCreationTimeout = 10 * time.Minute
ReleasePlanStatusUpdateTimeout = 1 * time.Minute
DefaultInterval = 100 * time.Millisecond

Expand All @@ -37,6 +39,12 @@ const (
AdditionalReleasedImagePushRepo string = "quay.io/redhat-appstudio-qe/simplepython"
PyxisStageImagesApiEndpoint string = "https://pyxis.preprod.api.redhat.com/v1/images/id/"

// EC constants
EcPolicyLibPath = "github.com/enterprise-contract/ec-policies//policy/lib"
EcPolicyReleasePath = "github.com/enterprise-contract/ec-policies//policy/release"
EcPolicyDataBundle = "oci::quay.io/redhat-appstudio-tekton-catalog/data-acceptable-bundles:latest"
EcPolicyDataPath = "github.com/release-engineering/rhtap-ec-policy//data"

// Service constants
ApplicationName string = "application"
)
Expand Down
53 changes: 16 additions & 37 deletions tests/release/pipelines/fbc_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pipelines
import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/devfile/library/v2/pkg/util"
Expand All @@ -28,10 +27,6 @@ const (
fbcSourceGitURL = "https://github.com/redhat-appstudio-qe/fbc-sample-repo"
targetPort = 50051
relSvcCatalogPathInRepo = "pipelines/fbc-release/fbc-release.yaml"
ecPolicyLibPath = "github.com/enterprise-contract/ec-policies//policy/lib"
ecPolicyReleasePath = "github.com/enterprise-contract/ec-policies//policy/release"
ecPolicyDataBundle = "oci::quay.io/redhat-appstudio-tekton-catalog/data-acceptable-bundles:latest"
ecPolicyDataPath = "github.com/release-engineering/rhtap-ec-policy//data"
)

var snapshot *appservice.Snapshot
Expand Down Expand Up @@ -75,8 +70,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
Describe("with FBC happy path", Label("fbcHappyPath"), func() {
var component *appservice.Component
BeforeAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)

managedNamespace = managedFw.UserNamespace

Expand All @@ -98,8 +93,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcApplicationName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred())
Expand All @@ -124,8 +119,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
var component *appservice.Component

BeforeAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcHotfixAppName, devNamespace)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -140,8 +135,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcHotfixAppName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcHotfixECPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcHotfixRPAName, managedNamespace, false)).NotTo(HaveOccurred())
Expand All @@ -166,8 +161,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
var component *appservice.Component

BeforeAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)

_, err = devFw.AsKubeDeveloper.HasController.CreateApplication(fbcPreGAAppName, devNamespace)
Expect(err).NotTo(HaveOccurred())
Expand All @@ -182,8 +177,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release-
})

AfterAll(func() {
devFw = newFramework(devWorkspace)
managedFw = newFramework(managedWorkspace)
devFw = releasecommon.NewFramework(devWorkspace)
managedFw = releasecommon.NewFramework(managedWorkspace)
if !CurrentSpecReport().Failed() {
Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcPreGAAppName, devNamespace, false)).NotTo(HaveOccurred())
Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcPreGAECPolicyName, managedNamespace, false)).NotTo(HaveOccurred())
Expand Down Expand Up @@ -228,7 +223,7 @@ func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, dev
return nil
}, 5 * time.Minute, releasecommon.DefaultInterval).Should(Succeed(), "timed out when waiting for Snapshot and Release being created")

mFw := newFramework(managedWorkspace)
mFw := releasecommon.NewFramework(managedWorkspace)
Eventually(func() error {
releasePr, err = mFw.AsKubeAdmin.ReleaseController.GetPipelineRunInNamespace(mFw.UserNamespace, releaseCR.GetName(), releaseCR.GetNamespace())
if err != nil {
Expand All @@ -247,7 +242,7 @@ func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, dev
}

func assertReleaseCRSucceeded(devFw framework.Framework, devNamespace, managedNamespace, fbcAppName string, component *appservice.Component) {
dFw := newFramework(devWorkspace)
dFw := releasecommon.NewFramework(devWorkspace)
Eventually(func() error {
releaseCR, err = dFw.AsKubeDeveloper.ReleaseController.GetRelease("", snapshot.Name, devNamespace)
if err != nil {
Expand Down Expand Up @@ -275,8 +270,8 @@ func createFBCEnterpriseContractPolicy(fbcECPName string, managedFw framework.Fr
PublicKey: "k8s://openshift-pipelines/public-key",
Sources: []ecp.Source{{
Name: "Default",
Policy: []string{ecPolicyLibPath, ecPolicyReleasePath},
Data: []string{ecPolicyDataBundle, ecPolicyDataPath},
Policy: []string{releasecommon.EcPolicyLibPath, releasecommon.EcPolicyReleasePath},
Data: []string{releasecommon.EcPolicyDataBundle, releasecommon.EcPolicyDataPath},
}},
Configuration: &ecp.EnterpriseContractPolicyConfiguration{
Exclude: []string{"cve", "step_image_registries", "tasks.required_tasks_found:prefetch-dependencies"},
Expand Down Expand Up @@ -326,19 +321,3 @@ func createFBCReleasePlanAdmission(fbcRPAName string, managedFw framework.Framew
})
Expect(err).NotTo(HaveOccurred())
}

func newFramework(workspace string) *framework.Framework {

stageOptions := utils.Options{
ToolchainApiUrl: os.Getenv(constants.TOOLCHAIN_API_URL_ENV),
KeycloakUrl: os.Getenv(constants.KEYLOAK_URL_ENV),
OfflineToken: os.Getenv(constants.OFFLINE_TOKEN_ENV),
}
fw, err := framework.NewFrameworkWithTimeout(
workspace,
time.Minute*60,
stageOptions,
)
Expect(err).NotTo(HaveOccurred())
return fw
}
Loading

0 comments on commit c0ef0b7

Please sign in to comment.