From a4a42ded0bd2978b1d3a17e133241248db913a1d Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Tue, 14 May 2024 22:19:19 -0400 Subject: [PATCH 1/2] Always set TTL_SH_PUBLISH This fixes an error where it tries to access this env and it's not set, which is an error cause our strict script settings Signed-off-by: Daniel Mikusa --- octo/test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/octo/test.go b/octo/test.go index a3affd7c..3b21a610 100644 --- a/octo/test.go +++ b/octo/test.go @@ -227,9 +227,10 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) { Name: "Package Buildpack", Run: StatikString("/package-buildpack.sh"), Env: map[string]string{ - "FORMAT": format, - "PACKAGES": "test", - "VERSION": "${{ steps.version.outputs.version }}", + "FORMAT": format, + "PACKAGES": "test", + "VERSION": "${{ steps.version.outputs.version }}", + "TTL_SH_PUBLISH": "false", }, }) } From 3d7c848817228f9e6a263832d3f1e435a75b6166 Mon Sep 17 00:00:00 2001 From: Daniel Mikusa Date: Tue, 14 May 2024 22:40:28 -0400 Subject: [PATCH 2/2] Add back missing integration tests Signed-off-by: Daniel Mikusa --- .github/workflows/pb-tests.yml | 7 +++++++ octo/test.go | 23 +++++++++++++++++------ octo/test_test.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pb-tests.yml b/.github/workflows/pb-tests.yml index f1521664..24ab465b 100644 --- a/.github/workflows/pb-tests.yml +++ b/.github/workflows/pb-tests.yml @@ -52,3 +52,10 @@ jobs: richgo test ./... -run Unit env: RICHGO_FORCE_COLOR: "1" + - name: Run Integration Tests + run: | + #!/usr/bin/env bash + + set -euo pipefail + + go test ./integration/... -run Integration diff --git a/octo/test.go b/octo/test.go index 3b21a610..eb468e72 100644 --- a/octo/test.go +++ b/octo/test.go @@ -94,17 +94,28 @@ func ContributeTest(descriptor Descriptor) (*Contribution, error) { if len(integrationTestFiles) == 0 { j.Steps = append(j.Steps, descriptor.Test.Steps...) - } else { - j.Steps = append(j.Steps, actions.Step{ - Name: "Install richgo", - Run: StatikString("/install-richgo.sh"), - Env: map[string]string{"RICHGO_VERSION": RichGoVersion}, - }, + } + + if len(integrationTestFiles) > 0 { + j.Steps = append(j.Steps, + actions.Step{ + Name: "Install richgo", + Run: StatikString("/install-richgo.sh"), + Env: map[string]string{"RICHGO_VERSION": RichGoVersion}, + }, actions.Step{ Name: "Run Tests", Run: StatikString("/run-unit-tests.sh"), Env: map[string]string{"RICHGO_FORCE_COLOR": "1"}, }) + + if !descriptor.Package.Enabled { + j.Steps = append(j.Steps, + actions.Step{ + Name: "Run Integration Tests", + Run: StatikString("/run-integration-tests.sh"), + }) + } } w.Jobs["unit"] = j diff --git a/octo/test_test.go b/octo/test_test.go index d6e842bf..fbf147ce 100644 --- a/octo/test_test.go +++ b/octo/test_test.go @@ -82,6 +82,40 @@ package: }) context("there are integration tests", func() { + it.Before(func() { + var err error + + Expect(os.WriteFile(filepath.Join(dir, ".github", "pipeline-descriptor.yaml"), []byte(`--- +github: + username: ${{ secrets.JAVA_GITHUB_USERNAME }} + token: ${{ secrets.JAVA_GITHUB_TOKEN }} +`), 0644)).To(Succeed()) + descriptor, err = octo.NewDescriptor(filepath.Join(dir, ".github", "pipeline-descriptor.yaml")) + Expect(err).To(Not(HaveOccurred())) + + Expect(os.Mkdir(filepath.Join(dir, "integration"), 0755)).To(Succeed()) + Expect(os.WriteFile(filepath.Join(dir, "integration", "main.go"), []byte{}, 0644)).To(Succeed()) + }) + + it("will contribute a unit test and an integration test pipeline", func() { + contribution, err := octo.ContributeTest(descriptor) + Expect(err).To(Not(HaveOccurred())) + + Expect(contribution.Path).To(Equal(".github/workflows/pb-tests.yml")) + + var workflow jobs + Expect(yaml.Unmarshal(contribution.Content, &workflow)).To(Succeed()) + + Expect(len(workflow.Jobs)).To(Equal(1)) + Expect(workflow.Jobs["unit"]).To(Not(BeNil())) + + unitSteps := workflow.Jobs["unit"].Steps + Expect(unitSteps[len(unitSteps)-2].Run).Should(ContainSubstring("richgo test ./... -run Unit")) + Expect(unitSteps[len(unitSteps)-1].Run).Should(ContainSubstring("go test ./integration/... -run Integration")) + }) + }) + + context("there are integration tests when packaged", func() { it.Before(func() { Expect(os.Mkdir(filepath.Join(dir, "integration"), 0755)).To(Succeed()) Expect(os.WriteFile(filepath.Join(dir, "integration", "main.go"), []byte{}, 0644)).To(Succeed())