Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-release new bramble version #62

Merged
merged 11 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/workflows/goreleaser.yml

This file was deleted.

22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,25 @@ jobs:
- name: Run all tests
run: |
make ci_test
- name: Publish release
if: github.ref == 'refs/heads/main'
run: |
set -x
version="v$(bramble config version)"
git fetch --tags
git fetch --prune --unshallow || true
latest_tag="$(git describe --abbrev=0 --tags)"

# Exit if version is not different from the latest tag
# TODO: ensure there is actually a release for the tag, so if this job fails, we can re-run
if [ $version = $latest_tag ]; then exit 0; fi

git tag $version
git push origin $version

docker build -t goreleaser -f .github/workflows/goreleaser.Dockerfile .github/workflows/
docker run \
-e GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} \
-v $(pwd):/opt \
--workdir=/opt \
goreleaser release --rm-dist
2 changes: 1 addition & 1 deletion bramble.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "github.com/maxmcd/bramble"
version = "0.0.2"
version = "0.0.3"

[dependencies]
"github.com/maxmcd/busybox" = "0.0.2"
20 changes: 20 additions & 0 deletions internal/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ subdirectories.
return b.project.CalculateDependencies()
},
},
{
Name: "config",
UsageText: "bramble config",
Action: cli.ShowAppHelp,
Subcommands: []*cli.Command{
{
Name: "version",
UsageText: "bramble config version",
Action: func(c *cli.Context) error {
project, err := project.NewProject(".")
if err != nil {
return err
}
fmt.Println(project.Version())
return nil
},
Subcommands: []*cli.Command{},
},
},
},
{
Name: "shell",
Usage: "Open a shell within a derivation build context",
Expand Down
16 changes: 14 additions & 2 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,23 @@ func calculatePaddedDirectoryName(bramblePath string, paddingLength int) (storeD
paddingSize := len(PathPaddingCharacters)
repetitions := paddingLen / (paddingSize + 1)
extra := paddingLen % (paddingSize + 1)

for i := 0; i < repetitions; i++ {
storeDirectoryName += ("/" + PathPaddingCharacters)
}
storeDirectoryName += ("/" + PathPaddingCharacters[:extra])
if extra == 0 {
// Of we have 0 extra characters the path ends up being too short.
// If we have this path and we add one character to the bramble path
// /bb/bramble_store_padding/bramble_store_padding/b/
// We get this, which is one too short:
// /bbb/bramble_store_padding/bramble_store_padding/
// So we pad this path like so:
// /bbb/bramble_store_padding/bramble_store_paddingb/
// TODO: find a more elegant way to handle this
storeDirectoryName += PathPaddingCharacters[0:1]
} else {
storeDirectoryName += ("/" + PathPaddingCharacters[:extra])
}

return storeDirectoryName, nil
}

Expand Down
29 changes: 29 additions & 0 deletions internal/store/store_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"os"
"path/filepath"
"strings"
"testing"
Expand All @@ -15,6 +16,28 @@ func Test_ensureBramblePath(t *testing.T) {
}
// -1 because the output path is "/foo/bar" plus the trailing slash
assert.Equal(t, len(s.StorePath), PathPaddingLength-1)

_ = os.MkdirAll("/tmp/bramble-test-34079652", 0755)

}

func Test_calculatePaddedDirectoryNameAll(t *testing.T) {
start := "/"
for i := 0; i < PathPaddingLength-4; i++ {
start += "b"
t.Run(start, func(t *testing.T) {
out, err := calculatePaddedDirectoryName(start, PathPaddingLength)
if err != nil {
t.Fatal(err)
}
// fullpath includes a trailing slash because it would always have
// one when replacing a store reference in a build output
fullPath := filepath.Join(start, out) + "/"
if len(fullPath) != PathPaddingLength {
t.Errorf("len of %s is not %d it's %d", fullPath, PathPaddingLength, len(fullPath))
}
})
}
}

func Test_calculatePaddedDirectoryName(t *testing.T) {
Expand All @@ -38,6 +61,12 @@ func Test_calculatePaddedDirectoryName(t *testing.T) {
bramblePath: "/bramble",
paddingLength: 40,
},
}, {
name: "basic",
args: args{
bramblePath: "/tmp/bramble-test-34079652",
paddingLength: PathPaddingLength,
},
}, {
name: "basic",
args: args{
Expand Down