Skip to content

Commit

Permalink
remove hello-tile submodule from acceptance tests
Browse files Browse the repository at this point in the history
fix shellcheck issue
  • Loading branch information
crhntr committed Jan 12, 2024
1 parent af31755 commit f6bdb43
Show file tree
Hide file tree
Showing 52 changed files with 1,202 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export CGO_ENABLED=0

export GITHUB_TOKEN
GITHUB_TOKEN="$(gh auth token)"
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "internal/acceptance/workflows/hello-tile"]
path = internal/acceptance/workflows/hello-tile
url = git@github.com:crhntr/hello-tile
[submodule "internal/commands/testdata/test_tile/hello-tile"]
path = internal/commands/testdata/test_tile/hello-tile
url = git@github.com:crhntr/hello-tile.git
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
run:
timeout: 10m
timeout: 10m
build-tags:
- acceptance
7 changes: 3 additions & 4 deletions internal/acceptance/workflows/baking_a_tile.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Feature: As a developer, I want to bake a tile
Scenario: it fetches components and bakes a tile
Given I have a "hello-tile" repository checked out at v0.1.7
Given I have a tile source directory "testdata/tiles/v2"
And the repository has no fetched releases
When I invoke kiln
| bake |
| --version=0.1.7 |
| --variable=github_token="${GITHUB_TOKEN}" |
Then a Tile is created
And the Tile contains
| metadata/metadata.yml |
| migrations/v1 |
| releases/bpm-1.1.18.tgz |
| releases/hello-release-0.1.5.tgz |
| releases/bpm-1.2.12.tgz |
| releases/hello-release-0.2.3.tgz |
46 changes: 32 additions & 14 deletions internal/acceptance/workflows/generating_release_notes.feature
Original file line number Diff line number Diff line change
@@ -1,37 +1,55 @@
Feature: As a robot, I want to generate release notes
Scenario: Update exising release notes document
Given I have a "hello-tile" repository checked out at v0.1.4
Given I have a tile source directory "testdata/tiles/v1"

And I execute git tag v0.1.3

And GitHub repository "crhntr/hello-release" has release with tag "v0.1.5"
And the environment variable "GITHUB_TOKEN" is set
And I invoke kiln
| update-release |
| --name=hello-release |
| --version=v0.1.5 |
| --without-download |
| --variable=github_token="${GITHUB_TOKEN}" |
And I write file "version"
| 0.1.4 |
And I execute git add Kilnfile.lock version
And I execute git commit -m bump-hello
And I execute git show
And I execute git tag v0.1.4

And I execute git remote add origin git@github.com:crhntr/hello-tile

# it does not contain 0.1.4 release header only 0.1.3
And "./scenario/fixtures/release_notes.md.erb" has regex matches: id='(?P<version>[\d\.]+)'
And "notes/release_notes.md.erb" has regex matches: id='(?P<version>[\d\.]+)'
| version |
| 0.1.3 |

And the environment variable "GITHUB_TOKEN" is set

When I invoke kiln
| release-notes |
| --release-date=2022-07-27 |
| --github-issue-milestone=Release-2022-001 |
| --update-docs=../scenario/fixtures/release_notes.md.erb |
| --kilnfile=Kilnfile |
| v0.1.3 |
| v0.1.4 |
| release-notes |
| --release-date=2022-07-27 |
| --github-issue-milestone=Release-2022-001 |
| --update-docs=notes/release_notes.md.erb |
| --kilnfile=Kilnfile |
| v0.1.3 |
| v0.1.4 |

# it contains the release header IDs
Then "./scenario/fixtures/release_notes.md.erb" has regex matches: id='(?P<version>[\d\.]+)'
Then "notes/release_notes.md.erb" has regex matches: id='(?P<version>[\d\.]+)'
| version |
| 0.1.4 |
| 0.1.3 |

# it contains the issue title
And "./scenario/fixtures/release_notes.md.erb" contains substring: **[Bug Fix]** Index page has inconsistent whitespace
And "notes/release_notes.md.erb" contains substring: **[Bug Fix]** Index page has inconsistent whitespace

# it contains the component release note
And "./scenario/fixtures/release_notes.md.erb" contains substring: "**[Fix]**\n The HTML had inconsistent spacing"
And "notes/release_notes.md.erb" contains substring: "**[Fix]**\n The HTML had inconsistent spacing"

# the table contains the name/versions
And "./scenario/fixtures/release_notes.md.erb" has regex matches: (?mU)<tr><td>(?P<release_name>.*)</td><td>(?P<release_version>.*)</td>
And "notes/release_notes.md.erb" has regex matches: (?mU)<tr><td>(?P<release_name>.*)</td><td>(?P<release_version>.*)</td>
| release_name | release_version |
| ubuntu-xenial stemcell | 621.0 |
| bpm | 1.1.18 |
Expand Down
10 changes: 6 additions & 4 deletions internal/acceptance/workflows/glaze.feature
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Feature: As a maintainer, I want to pin all BOSH Releases
Scenario: Kilnfile releases are floating
Given I have a "hello-tile" repository checked out at v0.1.1
Given I have a tile source directory "testdata/tiles/v2"
When I invoke kiln
| glaze |
Then the Kilnfile version for release "hello-release" is "v0.1.3"
And the Kilnfile version for release "bpm" is "1.1.18"
And the Kilnfile version for the stemcell is "621.0"
Then the Kilnfile version for release "hello-release" is "0.2.3"
And the Kilnfile version for release "bpm" is "1.2.12"
And the Kilnfile version for the stemcell is "1.329"


1 change: 0 additions & 1 deletion internal/acceptance/workflows/hello-tile
Submodule hello-tile deleted from 11847a
9 changes: 3 additions & 6 deletions internal/acceptance/workflows/scenario/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scenario

import (
"context"
"os/exec"
"regexp"

"github.com/cucumber/godog"
Expand Down Expand Up @@ -37,8 +36,10 @@ func initializeExec(ctx scenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
return configureStandardFileDescriptors(ctx), nil
})
ctx.Step(regexp.MustCompile("^I execute (.*)$"), iExecute)
ctx.Step(regexp.MustCompile(`^(stdout|stderr|"[^"]*") contains substring: (.*)`), outputContainsSubstring)
ctx.Step(regexp.MustCompile(`^the exit code is (\d+)$`), theExitCodeIs)
ctx.Step(regexp.MustCompile(`^I write file ("[^"]*")$`), iWriteFileWith)
}

func InitializeGitHub(ctx *godog.ScenarioContext) { initializeGitHub(ctx) }
Expand Down Expand Up @@ -78,15 +79,11 @@ func initializeTile(ctx scenarioContext) {

func InitializeTileSourceCode(ctx *godog.ScenarioContext) { initializeTileSourceCode(ctx) }
func initializeTileSourceCode(ctx scenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
err := exec.CommandContext(ctx, "git", "submodule", "update", "--init", "--recursive").Run()
return setTileRepoPath(ctx, "hello-tile"), err
})
ctx.After(resetTileRepository)

ctx.Step(regexp.MustCompile(`^kiln validate succeeds$`), kilnValidateSucceeds)

ctx.Step(regexp.MustCompile(`^I have a "([^"]*)" repository checked out at (.*)$`), iHaveARepositoryCheckedOutAtRevision)
ctx.Step(regexp.MustCompile(`^I have a tile source directory "([^"]*)"$`), iHaveATileDirectory)

ctx.Step(regexp.MustCompile(`^the repository has no fetched releases$`), theRepositoryHasNoFetchedReleases)

Expand Down
2 changes: 0 additions & 2 deletions internal/acceptance/workflows/scenario/initialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
"github.com/cucumber/godog"
)

const testTilePath = "../hello-tile"

func TestInitialize(t *testing.T) {
t.Run("AWS", func(t *testing.T) {
initializeAWS(newFakeScenarioContext(t))
Expand Down
6 changes: 5 additions & 1 deletion internal/acceptance/workflows/scenario/shared_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ func output(ctx context.Context, name string) (*bytes.Buffer, error) {
case "stderr":
return v[stderrFD], nil
default:
tileDir, err := tileRepoPath(ctx)
if err != nil {
return nil, err
}
name, err = strconv.Unquote(name)
if err != nil {
return nil, err
}
buf, err := os.ReadFile(name)
buf, err := os.ReadFile(filepath.Join(tileDir, name))
if err != nil {
return nil, err
}
Expand Down
40 changes: 40 additions & 0 deletions internal/acceptance/workflows/scenario/step_funcs_exec.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package scenario

import (
"bytes"
"context"
"fmt"
"github.com/cucumber/godog"
"os"
"path/filepath"
"strconv"
"strings"
)
Expand Down Expand Up @@ -38,3 +42,39 @@ func theExitCodeIs(ctx context.Context, expectedCode int) error {
}
return nil
}

func iExecute(ctx context.Context, command string) error {
args := strings.Fields(command)
if len(args) < 1 {
return nil
}
dir, err := tileRepoPath(ctx)
if err != nil {
return err
}
return executeAndWrapError(dir, args[0], args[1:]...)
}

func iWriteFileWith(ctx context.Context, fileName string, lines *godog.Table) error {
tileDir, err := tileRepoPath(ctx)
if err != nil {
return err
}
fileName, err = strconv.Unquote(fileName)
if err != nil {
return err
}

out := bytes.NewBuffer(nil)
for i, line := range lines.Rows {
for _, cell := range line.Cells {
out.WriteString(cell.Value)
}
if i < len(lines.Rows)-1 {
out.WriteByte('\n')
}
}

fileName = filepath.Join(tileDir, fileName)
return os.WriteFile(fileName, out.Bytes(), 0644)
}
14 changes: 9 additions & 5 deletions internal/acceptance/workflows/scenario/step_funcs_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scenario

import (
"context"
"path/filepath"
"testing"

. "github.com/onsi/gomega"
Expand All @@ -13,16 +14,19 @@ func Test_githubRepoHasReleaseWithTag(t *testing.T) {
t.Skip("skip this step in CI. GitHub action credentials do not have access to crhntr/hello-release")
}
setup := func(t *testing.T) (context.Context, Gomega) {
please := NewWithT(t)
ctx := context.Background()
err := checkoutMain(testTilePath)
please.Expect(err).NotTo(HaveOccurred())
ctx = setTileRepoPath(ctx, testTilePath)

dir, err := copyTileDirectory(t.TempDir(), filepath.Join("..", "testdata", "tiles", "v1"))
if err != nil {
t.Fatal(err)
}

ctx = setTileRepoPath(ctx, dir)
ctx, err = loadGithubToken(ctx)
if err != nil {
t.Fatal(err)
}
return ctx, please
return ctx, NewWithT(t)
}

t.Run("release exists", func(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package scenario

import (
"context"
"errors"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"

"github.com/cucumber/godog"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"

"github.com/pivotal-cf/kiln/pkg/cargo"
)
Expand Down Expand Up @@ -81,35 +83,80 @@ func iSetAVersionConstraintForRelease(ctx context.Context, versionConstraint, re

// iHaveARepositoryCheckedOutAtRevision checks out a repository at the filepath to a given revision
// Importantly, it also sets tilePath and tileVersion on kilnBakeScenario.
func iHaveARepositoryCheckedOutAtRevision(ctx context.Context, filePath, revision string) (context.Context, error) {
repo, err := git.PlainOpen(filePath)
if err != nil {
return ctx, fmt.Errorf("opening the repository failed: %w", err)
func iHaveATileDirectory(ctx context.Context, tileDirectory string) (context.Context, error) {
if err := os.RemoveAll(filepath.Join(tileDirectory, ".git")); err != nil && !errors.Is(err, os.ErrNotExist) {
return ctx, fmt.Errorf("failed to remove .git directory: %w", err)
}

wt, err := repo.Worktree()
tmpDir, err := os.MkdirTemp("", "")
if err != nil {
return ctx, fmt.Errorf("loading the worktree failed: %w", err)
return ctx, fmt.Errorf("failed to create new copy of tile directory: %w", err)
}

revisionHash, err := repo.ResolveRevision(plumbing.Revision(revision))
dir, err := copyTileDirectory(tmpDir, tileDirectory)
if err != nil {
return ctx, fmt.Errorf("resolving the given revision %q failed: %w", revision, err)
return ctx, err
}

err = wt.Checkout(&git.CheckoutOptions{
Hash: *revisionHash,
Force: true,
})
version, err := os.ReadFile(filepath.Join(dir, "version"))
if err != nil {
return ctx, fmt.Errorf("checking out the revision %q at %q failed: %w", revision, revisionHash, err)
version = []byte("0.1.0")
}

ctx = setTileVersion(ctx, strings.TrimPrefix(revision, "v"))
ctx = setTileVersion(ctx, strings.TrimSpace(string(version)))
ctx = setTileRepoPath(ctx, dir)

return ctx, nil
}

func copyTileDirectory(dir, tileDirectory string) (string, error) {
tileDirCopy := filepath.Join(dir, filepath.Base(tileDirectory))
if err := filepath.Walk(tileDirectory, copyDir(tileDirCopy, tileDirectory)); err != nil {
return "", fmt.Errorf("failed to copy tile directory: %w", err)
}
if err := executeAndWrapError(tileDirCopy, "git", "init"); err != nil {
return "", fmt.Errorf("tile path is not a repository: initalizing failed: %w", err)
}
if err := executeAndWrapError(tileDirCopy, "git", "add", "."); err != nil {
return "", fmt.Errorf("tile path is not a repository: adding initial files failed: %w", err)
}
if err := executeAndWrapError(tileDirCopy, "git", "commit", "-m", "initial commit"); err != nil {
return "", fmt.Errorf("tile path is not a repository: adding initial files failed: %w", err)
}
return tileDirCopy, nil
}

func copyDir(dstDir, srcDir string) filepath.WalkFunc {
return func(srcPath string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
rp, err := filepath.Rel(srcDir, srcPath)
if err != nil {
return err
}
createPath := filepath.Join(dstDir, rp)
if info.IsDir() {
_, err := os.Stat(createPath)
if err != nil {
return os.Mkdir(createPath, info.Mode().Perm())
}
return nil
}
dst, err := os.Create(createPath)
if err != nil {
return err
}
defer closeAndIgnoreErr(dst)
src, err := os.Open(srcPath)
if err != nil {
return err
}
defer closeAndIgnoreErr(src)
_, err = io.Copy(dst, src)
return err
}
}

// theRepositoryHasNoFetchedReleases deletes fetched releases, if any.
func theRepositoryHasNoFetchedReleases(ctx context.Context) error {
repoPath, err := tileRepoPath(ctx)
Expand Down
Loading

0 comments on commit f6bdb43

Please sign in to comment.